From 8ca12c16855d38d7f693687458636f98a9172b99 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Fri, 28 May 2021 15:00:43 +0100 Subject: [PATCH] Fixes #3567 - Invalid auto assignment conditions may break ticket view for unassigned tickets. --- .../_manage/ticket_auto_assignment.coffee | 2 +- .../_ui_element/ticket_selector.coffee | 3 +++ ...20210528092410_issue_3567_auto_assignment.rb | 17 +++++++++++++++++ .../migrate/issue_3567_auto_assignment_spec.rb | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210528092410_issue_3567_auto_assignment.rb create mode 100644 spec/db/migrate/issue_3567_auto_assignment_spec.rb diff --git a/app/assets/javascripts/app/controllers/_manage/ticket_auto_assignment.coffee b/app/assets/javascripts/app/controllers/_manage/ticket_auto_assignment.coffee index 2abef3251..6a3447b2a 100644 --- a/app/assets/javascripts/app/controllers/_manage/ticket_auto_assignment.coffee +++ b/app/assets/javascripts/app/controllers/_manage/ticket_auto_assignment.coffee @@ -22,7 +22,7 @@ class App.SettingTicketAutoAssignment extends App.ControllerSubContent @html(App.view('settings/ticket_auto_assignment')()) configure_attributes = [ - { name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: false, hasChanged: false }, + { name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: false, hasChanged: false, article: false }, ] ticket_auto_assignment_selector = App.Setting.get('ticket_auto_assignment_selector') 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 d8fb5cad9..8ea489efd 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee @@ -62,6 +62,9 @@ class App.UiElement.ticket_selector # merge config elements = {} + if attribute.article is false + delete groups.article + if attribute.action elements['ticket.action'] = name: 'action' diff --git a/db/migrate/20210528092410_issue_3567_auto_assignment.rb b/db/migrate/20210528092410_issue_3567_auto_assignment.rb new file mode 100644 index 000000000..da777aa73 --- /dev/null +++ b/db/migrate/20210528092410_issue_3567_auto_assignment.rb @@ -0,0 +1,17 @@ +class Issue3567AutoAssignment < ActiveRecord::Migration[5.2] + def change + return if !Setting.exists?(name: 'system_init_done') + + setting = Setting.get('ticket_auto_assignment_selector') + return if setting.blank? + return if setting['condition'].blank? + + setting['condition'].each_key do |key| + next if !key.start_with?('article.') + + setting['condition'].delete(key) + end + + Setting.set('ticket_auto_assignment_selector', setting) + end +end diff --git a/spec/db/migrate/issue_3567_auto_assignment_spec.rb b/spec/db/migrate/issue_3567_auto_assignment_spec.rb new file mode 100644 index 000000000..c353e701e --- /dev/null +++ b/spec/db/migrate/issue_3567_auto_assignment_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe Issue3567AutoAssignment, type: :db_migration, db_strategy: :reset do + context 'when setting contains article keys' do + before do + Setting.set('ticket_auto_assignment_selector', { 'condition'=>{ 'article.subject'=>{ 'operator' => 'contains', 'value' => 'test' } } }) + migrate + end + + it 'config gets removed' do + config = Setting.get('ticket_auto_assignment_selector') + expect(config['condition']['article.subject']).to be nil + end + end +end