From ea749640f89b3654865a5bc296e67ae7a2bf29f6 Mon Sep 17 00:00:00 2001
From: Jared Hancock <gravydish@gmail.com>
Date: Fri, 22 Jun 2012 23:15:00 -0500
Subject: [PATCH] Handle tickets assigned to teams

Add Team::hasMember utility method to assist in determining if a ticket is
owned by a team that he currently-logged-in-staff is a member of. Then,
check if the ticket is assigned to a staff member other than the current
staff or to a team that the current staff is not a member of. If so (the
ticket is not assigned to the current staff), then display the warning
banner showing who currently owns the ticket.
---
 include/class.team.php            | 7 +++++++
 include/staff/ticket-view.inc.php | 5 ++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/class.team.php b/include/class.team.php
index 48d7b5655..c9f88a231 100644
--- a/include/class.team.php
+++ b/include/class.team.php
@@ -80,6 +80,13 @@ class Team {
         return $this->members;
     }
 
+    function hasMember($staff) {
+        return db_count(
+             'SELECT COUNT(*) FROM '.TEAM_MEMBER_TABLE
+            .' WHERE team_id='.db_input($this->getId())
+            .'   AND staff_id='.db_input($staff->getId())) !== 0;
+    }
+
     function getLeadId(){
         return $this->ht['lead_id'];
     }
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index b8a2e8097..3ba4558a1 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -20,7 +20,10 @@ $lock  = $ticket->getLock();  //Ticket lock obj
 $id    = $ticket->getId();    //Ticket ID.
 
 //Useful warnings and errors the user might want to know!
-if($ticket->isAssigned() && $staff->getId()!=$thisstaff->getId())
+if($ticket->isAssigned() && (
+            ($staff && $staff->getId()!=$thisstaff->getId())
+         || ($team && !$team->hasMember($thisstaff))
+        ))
     $warn.='&nbsp;&nbsp;<span class="Icon assignedTicket">Ticket is assigned to '.implode('/', $ticket->getAssignees()).'</span>';
 if(!$errors['err'] && ($lock && $lock->getStaffId()!=$thisstaff->getId()))
     $errors['err']='This ticket is currently locked by '.$lock->getStaffName();
-- 
GitLab