diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index fbe1fff1f..a825b8a8b 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -634,6 +634,14 @@ class App.GenericHistory extends App.ControllerModal content = '' if item.type is 'notification' || item.type is 'email' content = "#{ @T( item.type ) } #{ @T( 'sent to' ) } '#{ item.value_to }'" + else if item.type is 'received_merge' + ticket = App.Ticket.find( item.id_from ) + ticket_link = "##{ ticket.number }" + content = "#{ @T( 'Ticket' ) } #{ ticket_link } #{ @T( 'was merged into this ticket' ) }" + else if item.type is 'merged_into' + ticket = App.Ticket.find( item.id_to ) + ticket_link = "##{ ticket.number }" + content = "#{ @T( 'This ticket was merged into' ) } #{ @T( 'ticket' ) } #{ ticket_link }" else content = "#{ @T( item.type ) } #{ @T(item.object) } " if item.attribute diff --git a/app/models/ticket.rb b/app/models/ticket.rb index a5a81c1df..6d1b38baf 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -310,7 +310,19 @@ returns # quiet update of reassign of articles Ticket::Article.where(ticket_id: id).update_all(['ticket_id = ?', data[:ticket_id]]) # rubocop:disable Rails/SkipsModelValidations - # update history + # add merge event to both ticket's history (Issue #2469 - Add information "Ticket merged" to History) + target_ticket.history_log( + 'received_merge', + data[:user_id], + id_to: target_ticket.id, + id_from: id, + ) + history_log( + 'merged_into', + data[:user_id], + id_to: target_ticket.id, + id_from: id, + ) # create new merge article Ticket::Article.create( @@ -323,8 +335,6 @@ returns updated_by_id: data[:user_id], ) - # add history to both - # reassign links to the new ticket # rubocop:disable Rails/SkipsModelValidations Link.where( diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index b4f88156c..17f3ec62f 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -74,6 +74,35 @@ RSpec.describe Ticket, type: :model do .to raise_error("Can't merge ticket with it self!") end end + + # Issue #2469 - Add information "Ticket merged" to History + context 'when merging' do + let(:merge_user) { create(:user) } + + it 'creates history entries in both the origin ticket and the target ticket' do + ticket.merge_to(ticket_id: target_ticket.id, user_id: merge_user.id) + + expect(target_ticket.history_get.size).to eq 2 + + target_history = target_ticket.history_get.last + expect(target_history['object']).to eq 'Ticket' + expect(target_history['type']).to eq 'received_merge' + expect(target_history['created_by_id']).to eq merge_user.id + expect(target_history['o_id']).to eq target_ticket.id + expect(target_history['id_to']).to eq target_ticket.id + expect(target_history['id_from']).to eq ticket.id + + expect(ticket.history_get.size).to eq 4 + + origin_history = ticket.reload.history_get[1] + expect(origin_history['object']).to eq 'Ticket' + expect(origin_history['type']).to eq 'merged_into' + expect(origin_history['created_by_id']).to eq merge_user.id + expect(origin_history['o_id']).to eq ticket.id + expect(origin_history['id_to']).to eq target_ticket.id + expect(origin_history['id_from']).to eq ticket.id + end + end end describe '#perform_changes' do diff --git a/spec/system/ticket/update_spec.rb b/spec/system/ticket/update_spec.rb index 0395548c9..bb64b92fb 100644 --- a/spec/system/ticket/update_spec.rb +++ b/spec/system/ticket/update_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Ticket Create', type: :system do +RSpec.describe 'Ticket Update', type: :system do let(:group) { Group.find_by(name: 'Users') } @@ -22,4 +22,30 @@ RSpec.describe 'Ticket Create', type: :system do expect(ticket.reload.state.name).to eq('new') end end + + # Issue #2469 - Add information "Ticket merged" to History + context 'when merging tickets' do + scenario 'tickets history of both tickets should show the merge event' do + user = create :user + origin_ticket = create :ticket, group: group + target_ticket = create :ticket, group: group + origin_ticket.merge_to(ticket_id: target_ticket.id, user_id: user.id) + + visit "#ticket/zoom/#{origin_ticket.id}" + click '.content.active .js-actions .dropdown-toggle' + click '.content.active .js-actions .dropdown-menu [data-type="ticket-history"]' + + modal = find('.content.active .modal') + expect(modal).to have_content "This ticket was merged into ticket ##{target_ticket.number}" + expect(modal).to have_link "##{target_ticket.number}", href: "#ticket/zoom/#{target_ticket.id}" + + visit "#ticket/zoom/#{target_ticket.id}" + click '.content.active .js-actions .dropdown-toggle' + click '.content.active .js-actions .dropdown-menu [data-type="ticket-history"]' + + modal = find('.content.active .modal') + expect(modal).to have_content("Ticket ##{origin_ticket.number} was merged into this ticket") + expect(modal).to have_link "##{origin_ticket.number}", href: "#ticket/zoom/#{origin_ticket.id}" + end + end end