Browse Source

Fixes #3567 - Invalid auto assignment conditions may break ticket view for unassigned tickets.

Rolf Schmidt 3 years ago
parent
commit
8ca12c1685

+ 1 - 1
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')

+ 3 - 0
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'

+ 17 - 0
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

+ 15 - 0
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