mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-29 16:54:53 +02:00
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">
|
<div className="activity-row">
|
||||||
<Icon {...this.getIconProps()} className="activity-row__icon"/>
|
<Icon {...this.getIconProps()} className="activity-row__icon"/>
|
||||||
<span>
|
<span>
|
||||||
<Link className="activity-row__name-link" to={this.getNameLinkDestination()}>
|
{this.renderAuthorName()}
|
||||||
{this.props.author.name}
|
|
||||||
</Link>
|
|
||||||
</span>
|
</span>
|
||||||
<span className="activity-row__message"> {i18n('ACTIVITY_' + this.props.type)} </span>
|
<span className="activity-row__message"> {i18n('ACTIVITY_' + this.props.type)} </span>
|
||||||
{_.includes(ticketRelatedTypes, this.props.type) ? this.renderTicketNumber() : this.props.to}
|
{_.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() {
|
renderTicketNumber() {
|
||||||
let ticketNumber = (this.props.mode === 'staff') ? this.props.ticketNumber : this.props.to;
|
let ticketNumber = (this.props.mode === 'staff') ? this.props.ticketNumber : this.props.to;
|
||||||
|
|
||||||
|
@ -37,9 +37,10 @@ class CommentController extends Controller {
|
|||||||
|
|
||||||
private $ticket;
|
private $ticket;
|
||||||
private $content;
|
private $content;
|
||||||
|
private $session;
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
$session = Session::getInstance();
|
$this->session = Session::getInstance();
|
||||||
|
|
||||||
if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
|
if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
|
||||||
return [
|
return [
|
||||||
@ -64,11 +65,11 @@ class CommentController extends Controller {
|
|||||||
'error' => ERRORS::INVALID_CONTENT
|
'error' => ERRORS::INVALID_CONTENT
|
||||||
],
|
],
|
||||||
'ticketNumber' => [
|
'ticketNumber' => [
|
||||||
'validation' => DataValidator::equals($session->getTicketNumber()),
|
'validation' => DataValidator::equals($this->session->getTicketNumber()),
|
||||||
'error' => ERRORS::INVALID_TICKET
|
'error' => ERRORS::INVALID_TICKET
|
||||||
],
|
],
|
||||||
'csrf_token' => [
|
'csrf_token' => [
|
||||||
'validation' => DataValidator::equals($session->getToken()),
|
'validation' => DataValidator::equals($this->session->getToken()),
|
||||||
'error' => ERRORS::INVALID_TOKEN
|
'error' => ERRORS::INVALID_TOKEN
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -78,16 +79,16 @@ 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(Controller::getLoggedUser()) || Session::getInstance()->isTicketSession();
|
$isAuthor = $this->ticket->isAuthor($this->user) || $this->session->isTicketSession();
|
||||||
$isOwner = $this->ticket->isOwner(Controller::getLoggedUser());
|
$isOwner = $this->ticket->isOwner($this->user);
|
||||||
$user = Controller::getLoggedUser();
|
|
||||||
|
|
||||||
if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){
|
if(!Controller::isStaffLogged() && Controller::isUserSystemEnabled() && !$isAuthor){
|
||||||
throw new RequestException(ERRORS::NO_PERMISSION);
|
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);
|
throw new RequestException(ERRORS::NO_PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ class CommentController extends Controller {
|
|||||||
'staff' => true
|
'staff' => true
|
||||||
]);
|
]);
|
||||||
} else if($isOwner) {
|
} else if($isOwner) {
|
||||||
!Controller::request('private') ? $this->sendMail($ticketAuthor) : null;
|
!Controller::request('private') ? $this->sendMail($ticketAuthor) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
Log::createLog('COMMENT', $this->ticket->ticketNumber);
|
||||||
@ -129,12 +130,12 @@ class CommentController extends Controller {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if(Controller::isStaffLogged()) {
|
if(Controller::isStaffLogged()) {
|
||||||
$this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser());
|
$this->ticket->unread = !$this->ticket->isAuthor($this->user);
|
||||||
$this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser());
|
$this->ticket->unreadStaff = !$this->ticket->isOwner($this->user);
|
||||||
$comment->authorStaff = Controller::getLoggedUser();
|
$comment->authorStaff = $this->user;
|
||||||
} else if(Controller::isUserSystemEnabled()) {
|
} else if(Controller::isUserSystemEnabled()) {
|
||||||
$this->ticket->unreadStaff = true;
|
$this->ticket->unreadStaff = true;
|
||||||
$comment->authorUser = Controller::getLoggedUser();
|
$comment->authorUser = $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ticket->addEvent($comment);
|
$this->ticket->addEvent($comment);
|
||||||
|
@ -83,15 +83,16 @@ class Ticketevent extends DataStore {
|
|||||||
|
|
||||||
public function toArray() {
|
public function toArray() {
|
||||||
$user = ($this->authorStaff) ? $this->authorStaff : $this->authorUser;
|
$user = ($this->authorStaff) ? $this->authorStaff : $this->authorUser;
|
||||||
|
$author = $this->ticket->authorToArray();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'ticketNumber' => $this->ticket->ticketNumber,
|
'ticketNumber' => $this->ticket->ticketNumber,
|
||||||
'author' => [
|
'author' => [
|
||||||
'name' => $user ? $user->name : null,
|
'name' => $user ? $user->name : $author['name'],
|
||||||
'staff' => $user instanceOf Staff,
|
'staff' => $user instanceOf Staff,
|
||||||
'id' => $user ? $user->id : null,
|
'id' => $user ? $user->id : null,
|
||||||
'customfields' => $user->xownCustomfieldvalueList ? $user->xownCustomfieldvalueList->toArray() : [],
|
'customfields' => $user && $user->xownCustomfieldvalueList ? $user->xownCustomfieldvalueList->toArray() : [],
|
||||||
],
|
],
|
||||||
'edited' => $this->editedContent
|
'edited' => $this->editedContent
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user