Browse Source

Added history support for checklists and items (#4886).

Co-authored-by: Florian Liebe <fl@zammad.com>
Rolf Schmidt 7 months ago
parent
commit
5f23da0d24

+ 3 - 1
app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee

@@ -56,6 +56,8 @@ class App.GenericHistory extends App.ControllerModal
           item.value_to   = App.Utils.html2text(item.value_to)
       if item.object is 'Ticket::SharedDraftZoom'
         item.object = 'Draft'
+      if item.object is 'Checklist::Item'
+        item.object = __('Checklist Item')
 
       currentItemTime = new Date( item.created_at )
       lastItemTime    = new Date( new Date( lastTime ).getTime() + (15 * 1000) )
@@ -140,7 +142,7 @@ class App.GenericHistory extends App.ControllerModal
           if item.value_from || item.object is 'Mention'
             content += ' &rarr;'
           content += " '#{ @translateItemValue(item, item.value_to) }'"
-        else if item.value_from
+        else if item.value_from && item.type isnt 'removed'
           content += " &rarr; '-'"
 
       recordsUser.records.push content

+ 18 - 0
app/models/checklist.rb

@@ -3,6 +3,7 @@
 class Checklist < ApplicationModel
   include HasDefaultModelUserRelations
   include ChecksClientNotification
+  include HasHistory
   include Checklist::TriggersSubscriptions
   include Checklist::Assets
   include CanChecklistSortedItems
@@ -17,6 +18,23 @@ class Checklist < ApplicationModel
   validates :name,      presence: { allow_blank: true }
   validates :ticket_id, presence: true, uniqueness: { allow_nil: true }
 
+  history_attributes_ignored :sorted_item_ids
+
+  def history_log_attributes
+    {
+      related_o_id:           ticket_id,
+      related_history_object: 'Ticket',
+    }
+  end
+
+  def history_create
+    history_log('created', created_by_id, { value_to: name })
+  end
+
+  def history_destroy
+    history_log('removed', updated_by_id, { value_to: name })
+  end
+
   def notify_clients_data_attributes
     {
       id:         id,

+ 16 - 0
app/models/checklist/item.rb

@@ -2,6 +2,7 @@
 
 class Checklist::Item < ApplicationModel
   include ChecksClientNotification
+  include HasHistory
   include HasDefaultModelUserRelations
   include Checklist::TriggersSubscriptions
   include Checklist::Item::Assets
@@ -15,6 +16,21 @@ class Checklist::Item < ApplicationModel
 
   validates :text, presence: { allow_blank: true }
 
+  def history_log_attributes
+    {
+      related_o_id:           checklist.ticket_id,
+      related_history_object: 'Ticket',
+    }
+  end
+
+  def history_create
+    history_log('created', created_by_id, { value_to: text })
+  end
+
+  def history_destroy
+    history_log('removed', updated_by_id, { value_to: text })
+  end
+
   def notify_clients_data_attributes
     {
       id:            id,

+ 1 - 1
app/models/ticket.rb

@@ -84,7 +84,7 @@ class Ticket < ApplicationModel
                              :article_count,
                              :preferences
 
-  history_relation_object 'Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom'
+  history_relation_object 'Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom', 'Checklist', 'Checklist::Item'
 
   validates :note, length: { maximum: 250 }
   sanitized_html :note

+ 12 - 8
i18n/zammad.pot

@@ -2613,6 +2613,10 @@ msgstr ""
 msgid "Checklist"
 msgstr ""
 
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:60
+msgid "Checklist Item"
+msgstr ""
+
 #: app/assets/javascripts/app/views/generic/checklist_item.jst.eco:10
 msgid "Checklist Item Label"
 msgstr ""
@@ -17828,7 +17832,7 @@ msgstr ""
 msgid "email"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:97
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:99
 msgid "email sent to '%s'"
 msgstr ""
 
@@ -17910,7 +17914,7 @@ msgstr ""
 msgid "forward"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:136
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:138
 msgid "from"
 msgstr ""
 
@@ -18392,7 +18396,7 @@ msgstr ""
 msgid "note"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:95
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:97
 msgid "notification sent to '%s'"
 msgstr ""
 
@@ -18690,7 +18694,7 @@ msgstr ""
 msgid "theme,color,style,dark mode,night mode,light mode"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:121
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:123
 msgid "this ticket was merged into ticket %s"
 msgstr ""
 
@@ -18699,7 +18703,7 @@ msgstr ""
 msgid "ticket"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:114
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:116
 msgid "ticket %s was merged into this ticket"
 msgstr ""
 
@@ -18743,15 +18747,15 @@ msgstr ""
 msgid "translation,locale,localization"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:101
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:103
 msgid "trigger '%s' was performed because pending reminder was reached"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:103
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:105
 msgid "trigger '%s' was performed because ticket was escalated"
 msgstr ""
 
-#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:105
+#: app/assets/javascripts/app/controllers/_application_controller/_modal_generic_history.coffee:107
 msgid "trigger '%s' was performed because ticket will escalate soon"
 msgstr ""
 

+ 1 - 1
spec/models/ticket_spec.rb

@@ -26,7 +26,7 @@ RSpec.describe Ticket, type: :model do
   it_behaves_like 'CanCsvImport'
   include_examples 'CanCsvImport - Ticket specific tests'
   it_behaves_like 'ChecksCoreWorkflow'
-  it_behaves_like 'HasHistory', history_relation_object: ['Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom']
+  it_behaves_like 'HasHistory', history_relation_object: ['Ticket::Article', 'Mention', 'Ticket::SharedDraftZoom', 'Checklist', 'Checklist::Item']
   it_behaves_like 'HasTags'
   it_behaves_like 'TagWritesToTicketHistory'
   it_behaves_like 'HasTaskbars'