diff --git a/client/src/app-components/activity-row.js b/client/src/app-components/activity-row.js index cb5dec18..ebde5f44 100644 --- a/client/src/app-components/activity-row.js +++ b/client/src/app-components/activity-row.js @@ -65,9 +65,7 @@ class ActivityRow extends React.Component {
- - {this.props.author.name} - + {this.renderAuthorName()} {i18n('ACTIVITY_' + this.props.type)} {_.includes(ticketRelatedTypes, this.props.type) ? this.renderTicketNumber() : this.props.to} @@ -76,6 +74,18 @@ class ActivityRow extends React.Component { ); } + renderAuthorName() { + let name = this.props.author.name; + + if (this.props.author.id) { + name = + {this.props.author.name} + ; + } + + return name; + } + renderTicketNumber() { let ticketNumber = (this.props.mode === 'staff') ? this.props.ticketNumber : this.props.to; diff --git a/server/controllers/ticket/comment.php b/server/controllers/ticket/comment.php index de6e2c85..f72a9e5c 100755 --- a/server/controllers/ticket/comment.php +++ b/server/controllers/ticket/comment.php @@ -37,9 +37,10 @@ class CommentController extends Controller { private $ticket; private $content; + private $session; public function validations() { - $session = Session::getInstance(); + $this->session = Session::getInstance(); if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) { return [ @@ -64,11 +65,11 @@ class CommentController extends Controller { 'error' => ERRORS::INVALID_CONTENT ], 'ticketNumber' => [ - 'validation' => DataValidator::equals($session->getTicketNumber()), + 'validation' => DataValidator::equals($this->session->getTicketNumber()), 'error' => ERRORS::INVALID_TICKET ], 'csrf_token' => [ - 'validation' => DataValidator::equals($session->getToken()), + 'validation' => DataValidator::equals($this->session->getToken()), 'error' => ERRORS::INVALID_TOKEN ] ] @@ -78,16 +79,16 @@ class CommentController extends Controller { public function handler() { $this->requestData(); + $this->user = Controller::getLoggedUser(); $ticketAuthor = $this->ticket->authorToArray(); - $isAuthor = $this->ticket->isAuthor(Controller::getLoggedUser()) || Session::getInstance()->isTicketSession(); - $isOwner = $this->ticket->isOwner(Controller::getLoggedUser()); - $user = Controller::getLoggedUser(); + $isAuthor = $this->ticket->isAuthor($this->user) || $this->session->isTicketSession(); + $isOwner = $this->ticket->isOwner($this->user); if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){ throw new RequestException(ERRORS::NO_PERMISSION); } - if(!$user->canManageTicket($this->ticket)) { + if(!$this->session->isTicketSession() && !$this->user->canManageTicket($this->ticket)) { throw new RequestException(ERRORS::NO_PERMISSION); } @@ -100,7 +101,7 @@ class CommentController extends Controller { 'staff' => true ]); } else if($isOwner) { - !Controller::request('private') ? $this->sendMail($ticketAuthor) : null; + !Controller::request('private') ? $this->sendMail($ticketAuthor) : null; } Log::createLog('COMMENT', $this->ticket->ticketNumber); @@ -129,12 +130,12 @@ class CommentController extends Controller { )); if(Controller::isStaffLogged()) { - $this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser()); - $this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser()); - $comment->authorStaff = Controller::getLoggedUser(); + $this->ticket->unread = !$this->ticket->isAuthor($this->user); + $this->ticket->unreadStaff = !$this->ticket->isOwner($this->user); + $comment->authorStaff = $this->user; } else if(Controller::isUserSystemEnabled()) { $this->ticket->unreadStaff = true; - $comment->authorUser = Controller::getLoggedUser(); + $comment->authorUser = $this->user; } $this->ticket->addEvent($comment); diff --git a/server/models/Ticketevent.php b/server/models/Ticketevent.php index d22b961d..9daf2560 100755 --- a/server/models/Ticketevent.php +++ b/server/models/Ticketevent.php @@ -83,15 +83,16 @@ class Ticketevent extends DataStore { public function toArray() { $user = ($this->authorStaff) ? $this->authorStaff : $this->authorUser; + $author = $this->ticket->authorToArray(); return [ 'type' => $this->type, 'ticketNumber' => $this->ticket->ticketNumber, 'author' => [ - 'name' => $user ? $user->name : null, + 'name' => $user ? $user->name : $author['name'], 'staff' => $user instanceOf Staff, 'id' => $user ? $user->id : null, - 'customfields' => $user->xownCustomfieldvalueList ? $user->xownCustomfieldvalueList->toArray() : [], + 'customfields' => $user && $user->xownCustomfieldvalueList ? $user->xownCustomfieldvalueList->toArray() : [], ], 'edited' => $this->editedContent ];