From 2fcc24a51bb66be67b5d02f22e43f9965021251a Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Tue, 31 Mar 2015 22:29:40 +0000 Subject: [PATCH] Unassign on transfer Unassign tickets on transfer when the target department has assignment restriction and the assigned staff is not a member. Disable claim (quick self-assignment) when above restriction is in effect. --- include/class.dept.php | 10 ++++++++++ include/class.ticket.php | 28 +++++++++++++++++++++++++++- include/staff/ticket-view.inc.php | 9 +++++++-- scp/tickets.php | 19 ++++++++++++++----- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/include/class.dept.php b/include/class.dept.php index d9d4c6309..cea549872 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -246,6 +246,16 @@ class Dept { return ($this->getManagerId() && $this->getManagerId()==$staff); } + function isMember($staff) { + + if (is_object($staff)) + $staff = $staff->getId(); + + // Members are indexed by ID + $members = $this->getMembers(); + + return ($members && isset($members[$staff])); + } function isPublic() { return ($this->ht['ispublic']); diff --git a/include/class.ticket.php b/include/class.ticket.php index 148f4f7d9..1740b10b0 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1559,11 +1559,21 @@ class Ticket { if($this->isClosed()) $this->reopen(); $this->reload(); + $dept = $this->getDept(); // Set SLA of the new department if(!$this->getSLAId() || $this->getSLA()->isTransient()) $this->selectSLAId(); + // Make sure the new department allows assignment to the + // currently assigned agent (if any) + if ($this->isAssigned() + && ($staff=$this->getStaff()) + && $dept->assignMembersOnly() + && !$dept->isMember($staff)) { + $this->setStaffId(0); + } + /*** log the transfer comments as internal note - with alerts disabled - ***/ $title=sprintf(_S('Ticket transferred from %1$s to %2$s'), $currentDept, $this->getDeptName()); @@ -1573,7 +1583,7 @@ class Ticket { $this->logEvent('transferred'); //Send out alerts if enabled AND requested - if(!$alert || !$cfg->alertONTransfer() || !($dept=$this->getDept())) + if (!$alert || !$cfg->alertONTransfer()) return true; //no alerts!! if (($email = $dept->getAlertEmail()) @@ -1616,6 +1626,21 @@ class Ticket { return true; } + function claim() { + global $thisstaff; + + if (!$thisstaff || !$this->isOpen() || $this->isAssigned()) + return false; + + $dept = $this->getDept(); + if ($dept->assignMembersOnly() && !$dept->isMember($thisstaff)) + return false; + + $comments = sprintf(_S('Ticket claimed by %s'), $thisstaff->getName()); + + return $this->assignToStaff($thisstaff->getId(), $comments, false); + } + function assignToStaff($staff, $note, $alert=true) { if(!is_object($staff) && !($staff=Staff::lookup($staff))) @@ -1933,6 +1958,7 @@ class Ticket { && $vars['reply_status_id'] != $this->getStatusId()) $this->setStatus($vars['reply_status_id']); + // Claim on response bypasses the department assignment restrictions if($thisstaff && $this->isOpen() && !$this->getStaffId() && $cfg->autoClaimTickets()) $this->setStaffId($thisstaff->getId()); //direct assignment; diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index e3e93f736..c2608d4b7 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -76,7 +76,10 @@ if($ticket->isOverdue()) echo __('Edit'); ?></a> <?php } - if ($ticket->isOpen() && !$ticket->isAssigned() && $thisstaff->canAssignTickets()) {?> + if ($ticket->isOpen() + && !$ticket->isAssigned() + && $thisstaff->canAssignTickets() + && $ticket->getDept()->isMember($thisstaff)) {?> <a id="ticket-claim" class="action-button pull-right confirm-action" href="#claim"><i class="icon-user"></i> <?php echo __('Claim'); ?></a> @@ -803,7 +806,9 @@ print $note_form->getField('attachments')->render(); <select id="assignId" name="assignId"> <option value="0" selected="selected">— <?php echo __('Select an Agent OR a Team');?> —</option> <?php - if($ticket->isOpen() && !$ticket->isAssigned()) + if ($ticket->isOpen() + && !$ticket->isAssigned() + && $ticket->getDept()->isMember($thisstaff)) echo sprintf('<option value="%d">'.__('Claim Ticket (comments optional)').'</option>', $thisstaff->getId()); $sid=$tid=0; diff --git a/scp/tickets.php b/scp/tickets.php index 33300cb44..ce6418048 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -147,12 +147,21 @@ if($_POST && !$errors): $id = preg_replace("/[^0-9]/", "",$_POST['assignId']); $claim = (is_numeric($_POST['assignId']) && $_POST['assignId']==$thisstaff->getId()); + $dept = $ticket->getDept(); - if(!$_POST['assignId'] || !$id) + if (!$_POST['assignId'] || !$id) $errors['assignId'] = __('Select assignee'); - elseif($_POST['assignId'][0]!='s' && $_POST['assignId'][0]!='t' && !$claim) - $errors['assignId']=__('Invalid assignee ID - get technical support'); - elseif($ticket->isAssigned()) { + elseif ($_POST['assignId'][0]!='s' && $_POST['assignId'][0]!='t' && !$claim) + $errors['assignId']= sprintf('%s - %s', + __('Invalid assignee '), + __('get technical support')); + elseif ($_POST['assignId'][0]!='s' + && $dept->assignMembersOnly() + && !$dept->isMember($id)) { + $errors['assignId'] = sprintf('%s. %s', + __('Invalid assignee'), + __('Must be department member')); + } elseif($ticket->isAssigned()) { if($_POST['assignId'][0]=='s' && $id==$ticket->getStaffId()) $errors['assignId']=__('Ticket already assigned to the agent.'); elseif($_POST['assignId'][0]=='t' && $id==$ticket->getTeamId()) @@ -246,7 +255,7 @@ if($_POST && !$errors): $errors['err'] = __('Only open tickets can be assigned'); } elseif($ticket->isAssigned()) { $errors['err'] = sprintf(__('Ticket is already assigned to %s'),$ticket->getAssigned()); - } elseif($ticket->assignToStaff($thisstaff->getId(), (sprintf(__('Ticket claimed by %s'),$thisstaff->getName())), false)) { + } elseif ($ticket->claim()) { $msg = __('Ticket is now assigned to you!'); } else { $errors['err'] = __('Problems assigning the ticket. Try again'); -- GitLab