Fixed issue #3136 - Attribute changes remove Owner of closed Ticket.

This commit is contained in:
Thorsten Eckel 2020-07-31 14:25:02 +02:00
parent 9a65f79d89
commit b81d31a42f
2 changed files with 44 additions and 0 deletions

View file

@ -1346,6 +1346,9 @@ result
def check_owner_active
return true if Setting.get('import_mode')
# only change the owner for non closed Tickets for historical/reporting reasons
return true if state.present? && Ticket::StateType.lookup(id: state.state_type_id)&.name == 'closed'
# return when ticket is unassigned
return true if owner_id.blank?
return true if owner_id == 1

View file

@ -537,6 +537,47 @@ RSpec.describe Ticket, type: :model do
.to change { ticket.reload.owner }.to(User.first)
end
end
context 'when the Ticket is closed' do
before do
ticket.update!(state: Ticket::State.lookup(name: 'closed'))
end
context 'if original owner is still an active agent belonging to ticket.group' do
it 'does not change' do
expect { create(:ticket_article, ticket: ticket) }
.not_to change { ticket.reload.owner }
end
end
context 'if original owner has left ticket.group' do
before { original_owner.groups = [] }
it 'does not change' do
expect { create(:ticket_article, ticket: ticket) }
.not_to change { ticket.reload.owner }
end
end
context 'if original owner has become inactive' do
before { original_owner.update(active: false) }
it 'does not change' do
expect { create(:ticket_article, ticket: ticket) }
.not_to change { ticket.reload.owner }
end
end
context 'if original owner has lost agent status' do
before { original_owner.roles = [create(:role)] }
it 'does not change' do
expect { create(:ticket_article, ticket: ticket) }
.not_to change { ticket.reload.owner }
end
end
end
end
end