Browse Source

Fixed issue #1920 - Sometimes notifications are note marked as seen if somebody else already closed the ticketed.

Martin Edenhofer 7 years ago
parent
commit
050f5527e6

+ 25 - 0
app/models/observer/ticket/escalation_update.rb

@@ -0,0 +1,25 @@
+# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
+
+class Observer::Ticket::EscalationUpdate < ActiveRecord::Observer
+  observe 'ticket'
+
+  def after_create(record)
+    _check(record)
+  end
+
+  def after_update(record)
+    _check(record)
+  end
+
+  private
+
+  def _check(record)
+
+    # return if we run import mode
+    return false if Setting.get('import_mode')
+
+    return false if !record.saved_changes?
+
+    record.escalation_calculation
+  end
+end

+ 0 - 7
app/models/ticket.rb

@@ -23,9 +23,7 @@ class Ticket < ApplicationModel
 
   store          :preferences
   before_create  :check_generate, :check_defaults, :check_title, :set_default_state, :set_default_priority
-  after_create   :check_escalation_update
   before_update  :check_defaults, :check_title, :reset_pending_time, :check_owner_active
-  after_update   :check_escalation_update
 
   validates :group_id, presence: true
 
@@ -1188,11 +1186,6 @@ result
     true
   end
 
-  def check_escalation_update
-    escalation_calculation
-    true
-  end
-
   def set_default_state
     return true if state_id
     default_ticket_state = Ticket::State.find_by(default_create: true)

+ 1 - 0
config/application.rb

@@ -35,6 +35,7 @@ module Zammad
       'observer::_ticket::_ref_object_touch',
       'observer::_ticket::_online_notification_seen',
       'observer::_ticket::_stats_reopen',
+      'observer::_ticket::_escalation_update',
       'observer::_tag::_ticket_history',
       'observer::_user::_ref_object_touch',
       'observer::_user::_ticket_organization',

+ 51 - 0
test/unit/online_notifiaction_test.rb

@@ -35,6 +35,57 @@ class OnlineNotificationTest < ActiveSupport::TestCase
       created_by_id: 1
     )
     @customer_user = User.lookup(email: 'nicole.braun@zammad.org')
+
+    calendar1 = Calendar.create_or_update(
+      name: 'EU 1 - test',
+      timezone: 'Europe/Berlin',
+      business_hours: {
+        mon: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        tue: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        wed: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        thu: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        fri: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        sat: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+        sun: {
+          active: true,
+          timeframes: [ ['00:00', '23:59'] ]
+        },
+      },
+      default: true,
+      ical_url: nil,
+      updated_by_id: 1,
+      created_by_id: 1,
+    )
+
+    sla1 = Sla.create_or_update(
+      name: 'test sla 1',
+      condition: {},
+      first_response_time: 20,
+      update_time: 60,
+      solution_time: 120,
+      calendar_id: calendar1.id,
+      updated_by_id: 1,
+      created_by_id: 1,
+    )
+
   end
 
   test 'ticket notification' do

+ 12 - 0
test/unit/ticket_escalation_test.rb

@@ -114,12 +114,24 @@ class TicketEscalationTest < ActiveSupport::TestCase
 
     ticket.save!
     assert_not(ticket.has_changes_to_save?)
+    assert(ticket.escalation_at)
+    assert_equal(ticket_escalation_at.to_s, ticket.escalation_at.to_s)
+
+    ticket.title = 'some value 123-1'
+    ticket.save!
+    assert_not(ticket.has_changes_to_save?)
+
     assert(ticket.escalation_at)
     assert_not_equal(ticket_escalation_at.to_s, ticket.escalation_at.to_s)
 
     sla.destroy!
     calendar.destroy!
 
+    ticket.save!
+    assert_not(ticket.has_changes_to_save?)
+    assert(ticket.escalation_at)
+
+    ticket.title = 'some value 123-2'
     ticket.save!
     assert_not(ticket.has_changes_to_save?)
     assert_not(ticket.escalation_at)