From 4f94b01d56f7c9d926c0c4dcf87c2361dda2e69b Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 21 Oct 2021 13:22:06 +0200 Subject: [PATCH] Fixes #3818 - Owner should get cleared if not listed in changed group. --- app/models/core_workflow/attributes.rb | 7 ++---- spec/system/ticket/update_spec.rb | 4 ++-- spec/system/ticket/zoom_spec.rb | 32 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/models/core_workflow/attributes.rb b/app/models/core_workflow/attributes.rb index 7005155af..5640cf851 100644 --- a/app/models/core_workflow/attributes.rb +++ b/app/models/core_workflow/attributes.rb @@ -238,13 +238,10 @@ class CoreWorkflow::Attributes end def saved_attribute_value(attribute) - saved_attribute_value = saved_only&.try(attribute[:name]) # special case for owner_id - if saved_only&.class == Ticket && attribute[:name] == 'owner_id' && saved_attribute_value == 1 - saved_attribute_value = nil - end + return if saved_only&.class == Ticket && attribute[:name] == 'owner_id' - saved_attribute_value + saved_only&.try(attribute[:name]) end end diff --git a/spec/system/ticket/update_spec.rb b/spec/system/ticket/update_spec.rb index 09cb8cfe1..3f56e6420 100644 --- a/spec/system/ticket/update_spec.rb +++ b/spec/system/ticket/update_spec.rb @@ -322,10 +322,10 @@ RSpec.describe 'Ticket Update', type: :system do end context 'when group will be changed' do - let(:user) { create(:user) } + let(:user) { User.find_by(email: 'agent1@example.com') } let(:ticket) { create(:ticket, group: group, owner: user) } - it 'check that owner is resetet after group change' do + it 'check that owner resets after group change' do visit "#ticket/zoom/#{ticket.id}" expect(page).to have_field('owner_id', with: user.id) diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 7f48eb9db..53199f58d 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -2235,4 +2235,36 @@ RSpec.describe 'Ticket zoom', type: :system do expect(page).to have_selector('form.article-add.is-open') end end + + context 'Owner should get cleared if not listed in changed group #3818', authenticated_as: :authenticate do + let(:group1) { create(:group) } + let(:group2) { create(:group) } + let(:agent1) { create(:agent) } + let(:agent2) { create(:agent) } + let(:ticket) { create(:ticket, group: group1, owner: agent1) } + + def authenticate + agent1.group_names_access_map = { + group1.name => 'full', + group2.name => %w[read change overview] + } + agent2.group_names_access_map = { + group1.name => 'full', + group2.name => 'full', + } + agent1 + end + + before do + visit "#ticket/zoom/#{ticket.id}" + end + + it 'does clear agent1 on select of group 2' do + select group2.name, from: 'Group' + wait(5).until { page.find('select[name=owner_id]').value != agent1.id.to_s } + expect(page.find('select[name=owner_id]').value).to eq('') + expect(page.all('select[name=owner_id] option').map(&:value)).not_to include(agent1.id.to_s) + expect(page.all('select[name=owner_id] option').map(&:value)).to include(agent2.id.to_s) + end + end end