Makes users able to comment on tickets when there is no user system, and fixes logs
This commit is contained in:
parent
0bfb36afd6
commit
431ef44c8d
|
@ -65,9 +65,7 @@ class ActivityRow extends React.Component {
|
|||
<div className="activity-row">
|
||||
<Icon {...this.getIconProps()} className="activity-row__icon"/>
|
||||
<span>
|
||||
<Link className="activity-row__name-link" to={this.getNameLinkDestination()}>
|
||||
{this.props.author.name}
|
||||
</Link>
|
||||
{this.renderAuthorName()}
|
||||
</span>
|
||||
<span className="activity-row__message"> {i18n('ACTIVITY_' + this.props.type)} </span>
|
||||
{_.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 = <Link className="activity-row__name-link" to={this.getNameLinkDestination()}>
|
||||
{this.props.author.name}
|
||||
</Link>;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
renderTicketNumber() {
|
||||
let ticketNumber = (this.props.mode === 'staff') ? this.props.ticketNumber : this.props.to;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue