Fixes #3818 - Owner should get cleared if not listed in changed group.

This commit is contained in:
Rolf Schmidt 2021-10-21 13:22:06 +02:00
parent 678b5ada31
commit 4f94b01d56
3 changed files with 36 additions and 7 deletions

View file

@ -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

View file

@ -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)

View file

@ -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