From f80ac0e7070967f1b9ee63eb2955107b2de48fef Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Tue, 17 Aug 2021 14:06:31 +0200 Subject: [PATCH] Fixes #3428 - Trigger ignores changes on some Ticket attributes. --- .../_ui_element/ticket_selector.coffee | 5 +- lib/transaction_dispatcher.rb | 5 -- spec/models/ticket_spec.rb | 54 ++++++++++++++++++- spec/system/manage/trigger_spec.rb | 39 +++++++++++--- 4 files changed, 88 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee index 8ea489efd..0ba4484fa 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee @@ -91,7 +91,6 @@ class App.UiElement.ticket_selector else for row in App[groupMeta.model].configure_attributes - # ignore passwords and relations if row.type isnt 'password' && row.name.substr(row.name.length-4,4) isnt '_ids' && row.searchable isnt false config = _.clone(row) @@ -121,6 +120,10 @@ class App.UiElement.ticket_selector translate: true operator: ['is', 'is not'] + # Remove 'has changed' operator from attributes which don't support the operator. + ['ticket.created_at', 'ticket.updated_at'].forEach (element_name) -> + elements[element_name]['operator'] = elements[element_name]['operator'].filter (item) -> item != 'has changed' + elements['ticket.mention_user_ids'] = name: 'mention_user_ids' display: 'Subscribe' diff --git a/lib/transaction_dispatcher.rb b/lib/transaction_dispatcher.rb index d762858ed..ef34c5497 100644 --- a/lib/transaction_dispatcher.rb +++ b/lib/transaction_dispatcher.rb @@ -203,11 +203,6 @@ class TransactionDispatcher real_changes = {} record.changes_to_save.each do |key, value| next if key == 'updated_at' - next if key == 'first_response_at' - next if key == 'close_at' - next if key == 'last_contact_agent_at' - next if key == 'last_contact_customer_at' - next if key == 'last_contact_at' next if key == 'article_count' next if key == 'create_article_type_id' next if key == 'create_article_sender_id' diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index e7223b9e5..b26764a22 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -1704,6 +1704,59 @@ RSpec.describe Ticket, type: :model do .to change { NotificationFactory::Mailer.already_sent?(ticket, agent, 'email') }.to(1) end end + + describe 'Ticket has changed attributes:' do + subject!(:ticket) { create(:ticket) } + + let(:group) { create(:group) } + let(:condition_field) { nil } + + shared_examples 'updated ticket group with trigger condition' do + it 'updated ticket group with has changed trigger condition' do + expect { TransactionDispatcher.commit }.to change { ticket.reload.group }.to(group) + end + end + + before do + create( + :trigger, + condition: { "ticket.#{condition_field}" => { 'operator' => 'has changed', 'value' => 'create' } }, + perform: { 'ticket.group_id' => { 'value' => group.id } } + ) + + ticket.update!(condition_field => Time.zone.now) + end + + context "when changing 'first_response_at' attribute" do + let(:condition_field) { 'first_response_at' } + + include_examples 'updated ticket group with trigger condition' + end + + context "when changing 'close_at' attribute" do + let(:condition_field) { 'close_at' } + + include_examples 'updated ticket group with trigger condition' + end + + context "when changing 'last_contact_agent_at' attribute" do + let(:condition_field) { 'last_contact_agent_at' } + + include_examples 'updated ticket group with trigger condition' + end + + context "when changing 'last_contact_customer_at' attribute" do + let(:condition_field) { 'last_contact_customer_at' } + + include_examples 'updated ticket group with trigger condition' + end + + context "when changing 'last_contact_at' attribute" do + let(:condition_field) { 'last_contact_at' } + + include_examples 'updated ticket group with trigger condition' + end + end end describe 'Mentions:', sends_notification_emails: true do @@ -2127,5 +2180,4 @@ RSpec.describe Ticket, type: :model do end end - end diff --git a/spec/system/manage/trigger_spec.rb b/spec/system/manage/trigger_spec.rb index 4991cd297..535c359e8 100644 --- a/spec/system/manage/trigger_spec.rb +++ b/spec/system/manage/trigger_spec.rb @@ -5,6 +5,13 @@ require 'system/examples/pagination_examples' RSpec.describe 'Manage > Trigger', type: :system do + def open_new_trigger_dialog + visit '/#manage/trigger' + click_on 'New Trigger' + + modal_ready + end + context 'Selector' do context 'custom attribute', db_strategy: :reset do @@ -23,10 +30,7 @@ RSpec.describe 'Manage > Trigger', type: :system do nulloption: true, } - visit '/#manage/trigger' - click '.page-header-meta .btn--success' - - modal_ready + open_new_trigger_dialog within '.modal .ticket_selector' do find('.js-attributeSelector select').select(attribute.display) @@ -57,10 +61,7 @@ RSpec.describe 'Manage > Trigger', type: :system do it 'shows tag selection list in foreground' do tag_item = create :tag_item - visit '/#manage/trigger' - click_on 'New Trigger' - - modal_ready + open_new_trigger_dialog within '.modal .ticket_perform_action' do find('.js-attributeSelector select').select('Tags') @@ -77,4 +78,26 @@ RSpec.describe 'Manage > Trigger', type: :system do context 'ajax pagination' do include_examples 'pagination', model: :trigger, klass: Trigger, path: 'manage/trigger' end + + context "with elements which do not support 'has changed' operator" do + it "check 'created_at' element" do + open_new_trigger_dialog + + within '.modal .ticket_selector' do + find(".js-attributeSelector select option[value='ticket.created_at']").select_option + + expect(page).to have_no_css('select[name="condition::ticket.created_at::operator"] option[value="has changed"]') + end + end + + it "check 'updated_at' element" do + open_new_trigger_dialog + + within '.modal .ticket_selector' do + find(".js-attributeSelector select option[value='ticket.updated_at']").select_option + + expect(page).to have_no_css('select[name="condition::ticket.updated_at::operator"] option[value="has changed"]') + end + end + end end