Small improvement for issue #1216 (moved same ticket check into model, show error message in ui).

This commit is contained in:
Martin Edenhofer 2017-07-25 13:53:01 +02:00
parent ab63ef2e0d
commit 6004e48cbd
4 changed files with 23 additions and 14 deletions

View file

@ -98,9 +98,13 @@ class App.TicketMerge extends App.ControllerModal
type: 'error' type: 'error'
msg: App.i18n.translateContent(data['message']) msg: App.i18n.translateContent(data['message'])
timeout: 6000 timeout: 6000
@formEnable(e) @formEnable(e)
error: => error: (data) =>
details = data.responseJSON || {}
@notify
type: 'error'
msg: App.i18n.translateContent(details.error_human || details.error || 'Unable to merge!')
timeout: 6000
@formEnable(e) @formEnable(e)
) )

View file

@ -332,15 +332,6 @@ class TicketsController < ApplicationController
end end
access!(ticket_slave, 'full') access!(ticket_slave, 'full')
# check different ticket ids
if ticket_slave.id == ticket_master.id
render json: {
result: 'failed',
message: 'Can\'t merge ticket with it self!',
}
return
end
# merge ticket # merge ticket
ticket_slave.merge_to( ticket_slave.merge_to(
ticket_id: ticket_master.id, ticket_id: ticket_master.id,

View file

@ -245,9 +245,12 @@ returns
def merge_to(data) def merge_to(data)
# prevent cross merging tickets # prevent cross merging tickets
target_ticket = Ticket.find(data[:ticket_id]) target_ticket = Ticket.find_by(id: data[:ticket_id])
raise 'no target ticket given' if !target_ticket raise 'no target ticket given' if !target_ticket
raise 'invalid state for target ticket' if target_ticket.state.name == 'merged' raise Exceptions::UnprocessableEntity, 'ticket already merged, no merge into merged ticket possible' if target_ticket.state.state_type.name == 'merged'
# check different ticket ids
raise Exceptions::UnprocessableEntity, 'Can\'t merge ticket with it self!' if id == target_ticket.id
# update articles # update articles
Transaction.execute do Transaction.execute do

View file

@ -47,7 +47,18 @@ RSpec.describe Ticket do
ticket_id: source_ticket.id, ticket_id: source_ticket.id,
user_id: 1, user_id: 1,
) )
}.to raise_error('invalid state for target ticket') }.to raise_error('ticket already merged, no merge into merged ticket possible')
end
it 'prevents merging ticket in it self' do
source_ticket = create(:ticket)
expect {
result = source_ticket.merge_to(
ticket_id: source_ticket.id,
user_id: 1,
)
}.to raise_error('Can\'t merge ticket with it self!')
end end
end end