Fixed issue #2082 - escalation_at are not updated correctly.
This commit is contained in:
parent
a4d000cda5
commit
28a1bbe4c6
5 changed files with 102 additions and 26 deletions
|
@ -3,15 +3,7 @@
|
||||||
class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
|
class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
|
||||||
observe 'sla', 'calendar'
|
observe 'sla', 'calendar'
|
||||||
|
|
||||||
def after_create(record)
|
def after_commit(record)
|
||||||
_rebuild(record)
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_update(record)
|
|
||||||
_check(record)
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_delete(record)
|
|
||||||
_rebuild(record)
|
_rebuild(record)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
|
||||||
record.ticket.touch # rubocop:disable Rails/SkipsModelValidations
|
record.ticket.touch # rubocop:disable Rails/SkipsModelValidations
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
record.ticket.save
|
record.ticket.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_destroy(record)
|
def after_destroy(record)
|
||||||
|
|
|
@ -16,8 +16,6 @@ class Observer::Ticket::EscalationUpdate < ActiveRecord::Observer
|
||||||
|
|
||||||
return true if record.destroyed?
|
return true if record.destroyed?
|
||||||
|
|
||||||
return true if !record.saved_changes?
|
|
||||||
|
|
||||||
record.escalation_calculation
|
record.escalation_calculation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
|
||||||
|
|
||||||
# check if update is needed
|
# check if update is needed
|
||||||
customer = User.lookup(id: @customer_id)
|
customer = User.lookup(id: @customer_id)
|
||||||
|
return true if !customer
|
||||||
need_update = false
|
need_update = false
|
||||||
if customer[:preferences][:tickets_open] != tickets_open
|
if customer[:preferences][:tickets_open] != tickets_open
|
||||||
need_update = true
|
need_update = true
|
||||||
|
@ -36,7 +37,7 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob
|
||||||
customer[:preferences][:tickets_closed] = tickets_closed
|
customer[:preferences][:tickets_closed] = tickets_closed
|
||||||
end
|
end
|
||||||
|
|
||||||
return if !need_update
|
return true if !need_update
|
||||||
customer.updated_by_id = @updated_by_id
|
customer.updated_by_id = @updated_by_id
|
||||||
customer.save
|
customer.save
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,27 +115,112 @@ class TicketEscalationTest < ActiveSupport::TestCase
|
||||||
ticket.save!
|
ticket.save!
|
||||||
assert_not(ticket.has_changes_to_save?)
|
assert_not(ticket.has_changes_to_save?)
|
||||||
assert(ticket.escalation_at)
|
assert(ticket.escalation_at)
|
||||||
assert_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)
|
||||||
|
|
||||||
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!
|
sla.destroy!
|
||||||
calendar.destroy!
|
calendar.destroy!
|
||||||
|
|
||||||
ticket.save!
|
|
||||||
assert_not(ticket.has_changes_to_save?)
|
|
||||||
assert(ticket.escalation_at)
|
|
||||||
|
|
||||||
ticket.title = 'some value 123-2'
|
|
||||||
ticket.save!
|
ticket.save!
|
||||||
assert_not(ticket.has_changes_to_save?)
|
assert_not(ticket.has_changes_to_save?)
|
||||||
assert_not(ticket.escalation_at)
|
assert_not(ticket.escalation_at)
|
||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue