Fixed issue #2082 - escalation_at are not updated correctly.

This commit is contained in:
Martin Edenhofer 2018-06-15 13:54:07 +02:00
parent a4d000cda5
commit 28a1bbe4c6
5 changed files with 102 additions and 26 deletions

View file

@ -3,15 +3,7 @@
class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
observe 'sla', 'calendar'
def after_create(record)
_rebuild(record)
end
def after_update(record)
_check(record)
end
def after_delete(record)
def after_commit(record)
_rebuild(record)
end

View file

@ -27,7 +27,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
record.ticket.touch # rubocop:disable Rails/SkipsModelValidations
return
end
record.ticket.save
record.ticket.save!
end
def after_destroy(record)

View file

@ -16,8 +16,6 @@ class Observer::Ticket::EscalationUpdate < ActiveRecord::Observer
return true if record.destroyed?
return true if !record.saved_changes?
record.escalation_calculation
end
end

View file

@ -26,6 +26,7 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
# check if update is needed
customer = User.lookup(id: @customer_id)
return true if !customer
need_update = false
if customer[:preferences][:tickets_open] != tickets_open
need_update = true
@ -36,7 +37,7 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
customer[:preferences][:tickets_closed] = tickets_closed
end
return if !need_update
return true if !need_update
customer.updated_by_id = @updated_by_id
customer.save
end

View file

@ -115,27 +115,112 @@ 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)
assert_equal((ticket_escalation_at - 30.minutes).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)
end
test 'email process and reply via email' do
calendar = Calendar.create_or_update(
name: 'Escalation 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,
)
sla = Sla.create_or_update(
name: 'test sla 1',
condition: {
'ticket.title' => {
operator: 'contains',
value: 'some value 123',
},
},
first_response_time: 60,
update_time: 180,
solution_time: 240,
calendar_id: calendar.id,
updated_by_id: 1,
created_by_id: 1,
)
email = "From: Bob Smith <customer@example.com>
To: zammad@example.com
Subject: some value 123
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
ticket_p.reload
assert(ticket_p.escalation_at)
assert_equal(ticket_p.first_response_escalation_at.to_s, (ticket_p.created_at + 1.hour).to_s)
assert_equal(ticket_p.update_escalation_at.to_s, (ticket_p.created_at + 3.hours).to_s)
assert_equal(ticket_p.close_escalation_at.to_s, (ticket_p.created_at + 4.hours).to_s)
assert_equal(ticket_p.escalation_at.to_s, (ticket_p.created_at + 1.hour).to_s)
travel 3.hours
article = nil
ticket_p.with_lock do
article = Ticket::Article.create!(
ticket_id: ticket_p.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message',
internal: false,
sender: Ticket::Article::Sender.where(name: 'Agent').first,
type: Ticket::Article::Type.where(name: 'email').first,
updated_by_id: 1,
created_by_id: 1,
)
end
ticket_p.reload
assert_equal(ticket_p.first_response_escalation_at.to_s, (ticket_p.created_at + 1.hour).to_s)
assert_equal(ticket_p.update_escalation_at.to_s, (ticket_p.last_contact_agent_at + 3.hours).to_s)
assert_equal(ticket_p.close_escalation_at.to_s, (ticket_p.created_at + 4.hours).to_s)
assert_equal(ticket_p.escalation_at.to_s, (ticket_p.created_at + 4.hours).to_s)
end
end