diff --git a/app/models/observer/ticket/escalation_update.rb b/app/models/observer/ticket/escalation_update.rb new file mode 100644 index 000000000..0ee7c72e0 --- /dev/null +++ b/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 diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 2d60d0cb4..5844f271f 100644 --- a/app/models/ticket.rb +++ b/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) diff --git a/config/application.rb b/config/application.rb index 9b80328c8..5945668f0 100644 --- a/config/application.rb +++ b/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', diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index 07e669f9d..d7746236b 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/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 diff --git a/test/unit/ticket_escalation_test.rb b/test/unit/ticket_escalation_test.rb index a963874f0..c46bb97f5 100644 --- a/test/unit/ticket_escalation_test.rb +++ b/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)