Browse Source

Fixes #4266 - Customer cant select group in ticket creation when - is configured in the Web channel.

Rolf Schmidt 2 years ago
parent
commit
da42a6bc36

+ 21 - 0
db/migrate/20221108124934_issue4266_fix_field.rb

@@ -0,0 +1,21 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+class Issue4266FixField < ActiveRecord::Migration[6.1]
+  def change
+
+    # return if it's a new setup
+    return if !Setting.exists?(name: 'system_init_done')
+
+    setting                           = Setting.find_by(name: 'customer_ticket_create_group_ids')
+    setting.description               = 'Defines groups for which a customer can create tickets via web interface. No selection means all groups are available.'
+    setting.options['form'][0]['tag'] = 'multiselect'
+    setting.options['form'][0].delete('nulloption')
+    setting.save!
+
+    value = Setting.get('customer_ticket_create_group_ids')
+    if ['', ['']].include?(value)
+      value = nil
+    end
+    Setting.set('customer_ticket_create_group_ids', value)
+  end
+end

+ 8 - 9
db/seeds/settings.rb

@@ -2445,21 +2445,20 @@ Setting.create_if_not_exists(
   title:       __('Group selection for Ticket creation'),
   name:        'customer_ticket_create_group_ids',
   area:        'CustomerWeb::Base',
-  description: __('Defines groups for which a customer can create tickets via web interface. "-" means all groups are available.'),
+  description: __('Defines groups for which a customer can create tickets via web interface. No selection means all groups are available.'),
   options:     {
     form: [
       {
-        display:    '',
-        null:       true,
-        name:       'group_ids',
-        tag:        'select',
-        multiple:   true,
-        nulloption: true,
-        relation:   'Group',
+        display:  '',
+        null:     true,
+        name:     'group_ids',
+        tag:      'multiselect',
+        multiple: true,
+        relation: 'Group',
       },
     ],
   },
-  state:       '',
+  state:       nil,
   preferences: {
     authentication: true,
     permission:     ['admin.channel_web'],

+ 1 - 1
i18n/zammad.pot

@@ -2969,7 +2969,7 @@ msgid "Defines endpoint of Elasticsearch."
 msgstr ""
 
 #: db/seeds/settings.rb
-msgid "Defines groups for which a customer can create tickets via web interface. \"-\" means all groups are available."
+msgid "Defines groups for which a customer can create tickets via web interface. No selection means all groups are available."
 msgstr ""
 
 #: db/seeds/settings.rb

+ 84 - 0
spec/db/migrate/issue_4266_fix_field_spec.rb

@@ -0,0 +1,84 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe Issue4266FixField, type: :db_migration do
+
+  context 'when config is migrated' do
+    before do
+      Setting.find_by(name: 'customer_ticket_create_group_ids').destroy
+      Setting.create_if_not_exists(
+        title:       'Group selection for Ticket creation',
+        name:        'customer_ticket_create_group_ids',
+        area:        'CustomerWeb::Base',
+        description: 'Defines groups for which a customer can create tickets via web interface. "-" means all groups are available.',
+        options:     {
+          form: [
+            {
+              display:    '',
+              null:       true,
+              name:       'group_ids',
+              tag:        'select',
+              multiple:   true,
+              nulloption: true,
+              relation:   'Group',
+            },
+          ],
+        },
+        state:       '',
+        preferences: {
+          authentication: true,
+          permission:     ['admin.channel_web'],
+        },
+        frontend:    true
+      )
+
+      migrate
+    end
+
+    it 'does change the config properly', :aggregate_failures do
+      setting = Setting.find_by(name: 'customer_ticket_create_group_ids')
+      expect(setting.options['form'][0]['tag']).to eq('multiselect')
+      expect(setting.options['form'][0]['nulloption']).to be_nil
+    end
+  end
+
+  context 'when value is correct' do
+    let(:setting_value) { [Group.first.id] }
+
+    before do
+      Setting.set('customer_ticket_create_group_ids', setting_value)
+      migrate
+    end
+
+    it 'does not change the value' do
+      expect(Setting.get('customer_ticket_create_group_ids')).to eq(setting_value)
+    end
+  end
+
+  context 'when value is an empty string' do
+    let(:setting_value) { '' }
+
+    before do
+      Setting.set('customer_ticket_create_group_ids', setting_value)
+      migrate
+    end
+
+    it 'does change to value to nil' do
+      expect(Setting.get('customer_ticket_create_group_ids')).to be_nil
+    end
+  end
+
+  context 'when value is an empty array string' do
+    let(:setting_value) { [''] }
+
+    before do
+      Setting.set('customer_ticket_create_group_ids', setting_value)
+      migrate
+    end
+
+    it 'does change to value to nil' do
+      expect(Setting.get('customer_ticket_create_group_ids')).to be_nil
+    end
+  end
+end