From 2ba9231e6708dc92bc1a48f7fd0998b91bd5d1b9 Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Tue, 19 Feb 2019 09:47:24 -0600
Subject: [PATCH] Assignment Restriction Issue

This commit fixes an issue where we were not checking the restrictions on Ticket assignment correctly. isAccessLimited returns true if showAssignedOnly is true, so we wouldn't want to negate the isAccessLimited check (that would return true if access is not limited).

Also, if an Agent's access is limited to assigned tickets only, we can return the assigned tickets once we have them without needing to go through any further processing.

Finally, we should still allow an agent to view an assigned ticket even if the ticket is closed.

Note: queue counts update themselves a little after you toggle the 'Limit ticket access to ONLY assigned tickets' check box. The 'See all tickets in search results, regardless of access' still works correctly as well.
---
 include/class.staff.php  | 4 ++++
 include/class.ticket.php | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/class.staff.php b/include/class.staff.php
index 0deedfefc..2618730bc 100644
--- a/include/class.staff.php
+++ b/include/class.staff.php
@@ -597,6 +597,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable, Searchable {
 
         $visibility = Q::any(new Q(array('status__state'=>'open', $assigned)));
 
+        // -- If access is limited to assigned only, return assigned
+        if ($this->isAccessLimited())
+            return $visibility;
+
         // -- Routed to a department of mine
         if (($depts=$this->getDepts()) && count($depts)) {
             $visibility->add(array('dept_id__in' => $depts));
diff --git a/include/class.ticket.php b/include/class.ticket.php
index d50bba7f1..895aa16d5 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -261,7 +261,6 @@ implements RestrictedAccess, Threadable, Searchable {
     }
 
     function isAssigned($to=null) {
-
         if (!$this->isOpen())
             return false;
 
@@ -308,8 +307,6 @@ implements RestrictedAccess, Threadable, Searchable {
 
         // check department access first
         if (!$staff->canAccessDept($this->getDept())
-                // no restrictions
-                && !$staff->isAccessLimited()
                 // check assignment
                 && !$this->isAssigned($staff)
                 // check referral
-- 
GitLab