From 33af34ab12b5b244309865129d9f72311a5f0cff Mon Sep 17 00:00:00 2001 From: Maxi Redigonda Date: Wed, 20 Nov 2019 14:24:02 -0300 Subject: [PATCH] Corrects email notifications and unread status on ticket/comment. --- server/controllers/ticket/comment.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php index fd904375..6cd513a2 100755 --- a/server/controllers/ticket/comment.php +++ b/server/controllers/ticket/comment.php @@ -79,10 +79,10 @@ class CommentController extends Controller { public function handler() { $this->requestData(); - $this->user = Controller::getLoggedUser(); $ticketAuthor = $this->ticket->authorToArray(); - $isAuthor = $this->ticket->isAuthor($this->user) || $this->session->isTicketSession(); + $isAuthor = $this->session->isTicketSession() || $this->ticket->isAuthor($this->user); $isOwner = $this->ticket->isOwner($this->user); + $private = Controller::request('private'); if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){ throw new RequestException(ERRORS::NO_PERMISSION); @@ -94,14 +94,15 @@ class CommentController extends Controller { $this->storeComment(); - if($isAuthor && $this->ticket->owner) { + if(!$isAuthor && !$private) { + $this->sendMail($ticketAuthor); + } + if($this->ticket->owner && !$isOwner) { $this->sendMail([ 'email' => $this->ticket->owner->email, 'name' => $this->ticket->owner->name, 'staff' => true ]); - } else if($isOwner && !Controller::request('private')) { - $this->sendMail($ticketAuthor); } Log::createLog('COMMENT', $this->ticket->ticketNumber); @@ -113,6 +114,7 @@ class CommentController extends Controller { $ticketNumber = Controller::request('ticketNumber'); $this->ticket = Ticket::getByTicketNumber($ticketNumber); $this->content = Controller::request('content', true); + $this->user = Controller::getLoggedUser(); } private function storeComment() { @@ -136,6 +138,8 @@ class CommentController extends Controller { } else if(Controller::isUserSystemEnabled()) { $this->ticket->unreadStaff = true; $comment->authorUser = $this->user; + } else { + $this->ticket->unreadStaff = true; } $this->ticket->addEvent($comment);