Fixed issue #1216 - Race condition if agents merge ticket at same time but in different directions.

This commit is contained in:
Rolf Schmidt 2017-07-19 12:03:17 +02:00
parent efad1f9fb1
commit 51d4162775
2 changed files with 24 additions and 1 deletions

View file

@ -244,6 +244,11 @@ returns
def merge_to(data) def merge_to(data)
# prevent cross merging tickets
target_ticket = Ticket.find(data[:ticket_id])
raise 'no target ticket given' if !target_ticket
raise 'invalid state for target ticket' if target_ticket.state.name == 'merged'
# update articles # update articles
Transaction.execute do Transaction.execute do
@ -296,7 +301,7 @@ returns
save! save!
# touch new ticket (to broadcast change) # touch new ticket (to broadcast change)
Ticket.find(data[:ticket_id]).touch target_ticket.touch
end end
true true
end end

View file

@ -32,6 +32,24 @@ RSpec.describe Ticket do
expect(check_ticket_ids).to match_array(expected_ticket_ids) expect(check_ticket_ids).to match_array(expected_ticket_ids)
end end
it 'prevents cross merging tickets' do
source_ticket = create(:ticket)
target_ticket = create(:ticket)
result = source_ticket.merge_to(
ticket_id: target_ticket.id,
user_id: 1,
)
expect(result).to be(true)
expect {
result = target_ticket.merge_to(
ticket_id: source_ticket.id,
user_id: 1,
)
}.to raise_error('invalid state for target ticket')
end
end end
describe '.destroy' do describe '.destroy' do