Small improvement for issue #1216 (moved same ticket check into model, show error message in ui).
This commit is contained in:
parent
ab63ef2e0d
commit
6004e48cbd
4 changed files with 23 additions and 14 deletions
|
@ -98,9 +98,13 @@ class App.TicketMerge extends App.ControllerModal
|
|||
type: 'error'
|
||||
msg: App.i18n.translateContent(data['message'])
|
||||
timeout: 6000
|
||||
|
||||
@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)
|
||||
)
|
||||
|
|
|
@ -332,15 +332,6 @@ class TicketsController < ApplicationController
|
|||
end
|
||||
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
|
||||
ticket_slave.merge_to(
|
||||
ticket_id: ticket_master.id,
|
||||
|
|
|
@ -245,9 +245,12 @@ returns
|
|||
def merge_to(data)
|
||||
|
||||
# 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 '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
|
||||
Transaction.execute do
|
||||
|
|
|
@ -47,7 +47,18 @@ RSpec.describe Ticket do
|
|||
ticket_id: source_ticket.id,
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue