Skip to content

Commit

Permalink
Small improvement for issue #1216 (moved same ticket check into model…
Browse files Browse the repository at this point in the history
…, show error message in ui).
  • Loading branch information
martini committed Jul 25, 2017
1 parent d636996 commit d8be2e0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Expand Up @@ -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)
)
9 changes: 0 additions & 9 deletions app/controllers/tickets_controller.rb
Expand Up @@ -345,15 +345,6 @@ def ticket_merge
# permission check
ticket_permission(ticket_slave)

# check diffetent 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,
Expand Down
7 changes: 5 additions & 2 deletions app/models/ticket.rb
Expand Up @@ -276,9 +276,12 @@ def self.process_escalation
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
Expand Down
13 changes: 12 additions & 1 deletion spec/models/ticket_spec.rb
Expand Up @@ -19,7 +19,18 @@
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
Expand Down

0 comments on commit d8be2e0

Please sign in to comment.