Enhancement to issue #1816 - also reset owner if agent isn't agent anymore.

This commit is contained in:
Martin Edenhofer 2018-02-16 12:56:51 +01:00
parent 506fe55608
commit 7dc2875a49
2 changed files with 51 additions and 4 deletions

View file

@ -1209,9 +1209,16 @@ result
end end
def check_owner_active def check_owner_active
return true if owner.login == '-' # return when ticket is unassigned
return true if owner.groups.any?(&:active?) && owner.active? # return if user in any groups assigned is active and user account is active # return when ticket is unassigned
self.owner = User.find_by(login: '-') # else set the owner of the ticket to the default user as unassigned return true if owner_id.blank?
return true if owner_id == 1
# return if owner is active, is agent and has access to group of ticket
return true if owner.active? && owner.permissions?('ticket.agent') && owner.group_access?(group_id, 'full')
# else set the owner of the ticket to the default user as unassigned
self.owner_id = 1
true true
end end
end end

View file

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class TicketUpdateTest < ActiveSupport::TestCase class TicketOwnerResetOnFollowUpTest < ActiveSupport::TestCase
setup do setup do
UserInfo.current_user_id = 1 UserInfo.current_user_id = 1
@ -179,6 +179,46 @@ Some Text"
To: customer@example.com To: customer@example.com
Subject: #{ticket.subject_build('some new subject')} Subject: #{ticket.subject_build('some new subject')}
Some Text"
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw)
assert_equal(ticket.id, ticket_p.id)
assert_equal('open', ticket_p.state.name)
assert_equal('-', ticket_p.owner.login)
end
test 'check if ticket is unassigned on follow up via email if current owner is customer now' do
ticket = Ticket.create!(
title: 'follow up check for invalid owner is customer now',
group: Group.lookup(name: 'Users'),
customer: @customer1,
owner: @agent1,
state: Ticket::State.lookup(name: 'closed'),
updated_by_id: 1,
created_by_id: 1,
)
article = Ticket::Article.create!(
ticket_id: ticket.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'follow up check',
body: 'some message article',
internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
type: Ticket::Article::Type.lookup(name: 'email'),
updated_by_id: 1,
created_by_id: 1,
)
@agent1.roles = Role.where(name: 'Customer')
@agent1.save!
email_raw = "From: me@example.com
To: customer@example.com
Subject: #{ticket.subject_build('some new subject')}
Some Text" Some Text"
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw) ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw)