From 080ccc4a667d8661854a27ddb0e548c6bfc84875 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Mon, 30 Aug 2021 15:26:24 +0200 Subject: [PATCH] Fixes #3713 - Core workflows breaks groups selection for customer panel --- .../controllers/customer_ticket_create.coffee | 6 ---- app/models/core_workflow/attributes/group.rb | 30 +++++++++++++++---- spec/models/core_workflow_spec.rb | 22 ++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.coffee index 79958e74d..c09dfdc8e 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.coffee @@ -33,12 +33,6 @@ class CustomerTicketCreate extends App.ControllerAppContent defaults = template['options'] || {} handlers = @Config.get('TicketCreateFormHandler') - groupFilter = App.Config.get('customer_ticket_create_group_ids') - if groupFilter - if !_.isArray(groupFilter) - groupFilter = [groupFilter] - @formMeta.filter.group_id = groupFilter - @html App.view('customer_ticket_create')( head: 'New Ticket' form_id: @form_id diff --git a/app/models/core_workflow/attributes/group.rb b/app/models/core_workflow/attributes/group.rb index 90339a337..8f34c8af6 100644 --- a/app/models/core_workflow/attributes/group.rb +++ b/app/models/core_workflow/attributes/group.rb @@ -13,18 +13,36 @@ class CoreWorkflow::Attributes::Group < CoreWorkflow::Attributes::Base end end + def customer_ticket_create_group_ids + Setting.get('customer_ticket_create_group_ids') + end + def groups @groups ||= if @attributes.user.permissions?('ticket.agent') - if @attributes.payload['screen'] == 'create_middle' - @attributes.user.groups_access(%w[create]) - else - @attributes.user.groups_access(%w[create change]) - end + groups_agent + elsif @attributes.user.permissions?('ticket.customer') && @attributes.payload['screen'] == 'create_middle' && customer_ticket_create_group_ids.present? + groups_customer else - Group.where(active: true) + groups_default end end + def groups_agent + if @attributes.payload['screen'] == 'create_middle' + @attributes.user.groups_access(%w[create]) + else + @attributes.user.groups_access(%w[create change]) + end + end + + def groups_customer + Group.where(id: customer_ticket_create_group_ids, active: true) + end + + def groups_default + Group.where(active: true) + end + def assets(group) return if @attributes.assets[Group.to_app_model] && @attributes.assets[Group.to_app_model][group.id] diff --git a/spec/models/core_workflow_spec.rb b/spec/models/core_workflow_spec.rb index ffd213464..8625579d5 100644 --- a/spec/models/core_workflow_spec.rb +++ b/spec/models/core_workflow_spec.rb @@ -237,6 +237,28 @@ RSpec.describe CoreWorkflow, type: :model do end end + describe '.perform - Default - Customer setting customer_ticket_create_group_ids' do + let(:action_user) { create(:customer) } + + let!(:group1) { create(:group) } + let!(:group2) { create(:group) } + let!(:group3) { create(:group) } + + it 'does show group 1' do + expect(result[:restrict_values]['group_id']).to include(group1.id.to_s) + end + + context 'with customer_ticket_create_group_ids set' do + before do + Setting.set('customer_ticket_create_group_ids', [group2.id.to_s, group3.id.to_s]) + end + + it 'does not show group 1' do + expect(result[:restrict_values]['group_id']).not_to include(group1.id.to_s) + end + end + end + describe '.perform - Custom - Pending Time' do it 'does not show pending time for non pending state' do expect(result[:visibility]['pending_time']).to eq('remove')