Corrects email notifications and unread status on ticket/comment.

This commit is contained in:
Maxi Redigonda 2019-11-20 14:24:02 -03:00
parent ec88e02ad4
commit 33af34ab12
1 changed files with 9 additions and 5 deletions

View File

@ -79,10 +79,10 @@ class CommentController extends Controller {
public function handler() { public function handler() {
$this->requestData(); $this->requestData();
$this->user = Controller::getLoggedUser();
$ticketAuthor = $this->ticket->authorToArray(); $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); $isOwner = $this->ticket->isOwner($this->user);
$private = Controller::request('private');
if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){ if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){
throw new RequestException(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
@ -94,14 +94,15 @@ class CommentController extends Controller {
$this->storeComment(); $this->storeComment();
if($isAuthor && $this->ticket->owner) { if(!$isAuthor && !$private) {
$this->sendMail($ticketAuthor);
}
if($this->ticket->owner && !$isOwner) {
$this->sendMail([ $this->sendMail([
'email' => $this->ticket->owner->email, 'email' => $this->ticket->owner->email,
'name' => $this->ticket->owner->name, 'name' => $this->ticket->owner->name,
'staff' => true 'staff' => true
]); ]);
} else if($isOwner && !Controller::request('private')) {
$this->sendMail($ticketAuthor);
} }
Log::createLog('COMMENT', $this->ticket->ticketNumber); Log::createLog('COMMENT', $this->ticket->ticketNumber);
@ -113,6 +114,7 @@ class CommentController extends Controller {
$ticketNumber = Controller::request('ticketNumber'); $ticketNumber = Controller::request('ticketNumber');
$this->ticket = Ticket::getByTicketNumber($ticketNumber); $this->ticket = Ticket::getByTicketNumber($ticketNumber);
$this->content = Controller::request('content', true); $this->content = Controller::request('content', true);
$this->user = Controller::getLoggedUser();
} }
private function storeComment() { private function storeComment() {
@ -136,6 +138,8 @@ class CommentController extends Controller {
} else if(Controller::isUserSystemEnabled()) { } else if(Controller::isUserSystemEnabled()) {
$this->ticket->unreadStaff = true; $this->ticket->unreadStaff = true;
$comment->authorUser = $this->user; $comment->authorUser = $this->user;
} else {
$this->ticket->unreadStaff = true;
} }
$this->ticket->addEvent($comment); $this->ticket->addEvent($comment);