From 2fcc664e153625c19ddadd1b19f57d36132d23c2 Mon Sep 17 00:00:00 2001
From: Rikki Masters <Rikki.Masters@copart.com>
Date: Tue, 29 Oct 2019 14:44:38 +0000
Subject: [PATCH] Feature: Mark as Answered permission option

Some roles need the ability to mark a ticket as Answered/Unanswered but must not be able to reply directly to the customer. Both are controlled by the Post Reply permission. This seperates the two functions so they can be managed independently.
---
 include/ajax.tickets.php          | 2 +-
 include/class.ticket.php          | 6 ++++++
 include/staff/ticket-view.inc.php | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index c3de4f715..14ac16401 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -1273,7 +1273,7 @@ function refer($tid, $target=null) {
         if (!($ticket=Ticket::lookup($tid)))
             Http::response(404, __('No such ticket'));
 
-        if (!$ticket->checkStaffPerm($thisstaff, Ticket::PERM_REPLY) && !$thisstaff->isManager())
+            if (!$ticket->checkStaffPerm($thisstaff, Ticket::PERM_REPLY) && !$ticket->checkStaffPerm($thisstaff, Ticket::PERM_MARKANSWERED) && !$thisstaff->isManager())
             Http::response(403, __('Permission denied'));
 
         $errors = array();
diff --git a/include/class.ticket.php b/include/class.ticket.php
index f8dbc5bf5..c63fcf546 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -102,6 +102,7 @@ implements RestrictedAccess, Threadable, Searchable {
     const PERM_TRANSFER = 'ticket.transfer';
     const PERM_REFER    = 'ticket.refer';
     const PERM_REPLY    = 'ticket.reply';
+    const PERM_MARKANSWERED = 'ticket.markanswered';
     const PERM_CLOSE    = 'ticket.close';
     const PERM_DELETE   = 'ticket.delete';
 
@@ -141,6 +142,11 @@ implements RestrictedAccess, Threadable, Searchable {
                 /* @trans */ 'Post Reply',
                 'desc'  =>
                 /* @trans */ 'Ability to post a ticket reply'),
+            self::PERM_MARKANSWERED => array(
+                'title' =>
+                /* @trans */ 'Mark as Answered',
+                'desc'  =>
+                /* @trans */ 'Ability to mark a ticket as Answered/Unanswered'),
             self::PERM_CLOSE => array(
                 'title' =>
                 /* @trans */ 'Close',
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index ecc5f45d6..b35421c44 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -22,7 +22,7 @@ $mylock = ($lock && $lock->getStaffId() == $thisstaff->getId()) ? $lock : null;
 $id    = $ticket->getId();    //Ticket ID.
 $isManager = $dept->isManager($thisstaff); //Check if Agent is Manager
 $canRelease = ($isManager || $role->hasPerm(Ticket::PERM_RELEASE)); //Check if Agent can release tickets
-$canAnswer = ($isManager || $role->hasPerm(Ticket::PERM_REPLY)); //Check if Agent can mark as answered/unanswered
+$canMarkAnswered = ($isManager || $role->hasPerm(Ticket::PERM_MARKANSWERED)); //Check if Agent can mark as answered/unanswered
 
 //Useful warnings and errors the user might want to know!
 if ($ticket->isClosed() && !$ticket->isReopenable())
@@ -165,7 +165,7 @@ if($ticket->isOverdue())
                     <?php
                     }
                  }
-                 if($ticket->isOpen() && $canAnswer) {
+                 if($ticket->isOpen() && $canMarkAnswered) {
                     if($ticket->isAnswered()) { ?>
                     <li><a href="#tickets/<?php echo $ticket->getId();
                         ?>/mark/unanswered" class="ticket-action"
-- 
GitLab