From 5257136edfaac5a0cc6e84577c42846f458d3bfd Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Wed, 2 Dec 2015 12:03:43 +0000 Subject: [PATCH] Check agent's access on reopen auto-assignment Auto-assign to closing staff or the last respondent if the agent is available and has access. Otherwise, put the ticket back to unassigned pool. --- include/class.ticket.php | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/include/class.ticket.php b/include/class.ticket.php index 61da381c5..e4764a857 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1525,28 +1525,21 @@ implements RestrictedAccess, Threadable { // confused with autorespond on new message setting if ($autorespond && $this->isClosed() && $this->isReopenable()) { $this->reopen(); + // Auto-assign to closing staff or the last respondent if the + // agent is available and has access. Otherwise, put the ticket back + // to unassigned pool. $dept = $this->getDept(); + $staff = $this->getStaff() ?: $this->getLastRespondent(); $autoclaim = ($cfg->autoClaimTickets() && !$dept->disableAutoClaim()); - // Auto-assign to closing staff or last respondent - // If the ticket is closed and auto-claim is not enabled then put the - // ticket back to unassigned pool. - if (!$autoclaim) { - $this->setStaffId(0); - } - elseif (!($staff = $this->getStaff()) || !$staff->isAvailable()) { - // Ticket has no assigned staff - if auto-claim is enabled then - // try assigning it to the last respondent (if available) - // otherwise leave the ticket unassigned. - if (($lastrep = $this->getLastRespondent()) - && $lastrep->isAvailable() - ) { - $this->setStaffId($lastrep->getId()); //direct assignment; - } - else { - // unassign - last respondent is not available. - $this->setStaffId(0); - } - } + if ($autoclaim + && $staff + // Is agent on vacation ? + && $staff->isAvailable() + // Does the agent have access to dept? + && $staff->canAccessDept($dept->getId())) + $this->setStaffId($staff->getId()); + else + $this->setStaffId(0); // Clear assignment } // Figure out the user -- GitLab