Merge pull request #656 from mredigonda/no-user-system-comment-bug
No user system comment bug - Fix notifications
This commit is contained in:
commit
8aaacc5b2a
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -99,8 +100,8 @@ class CommentController extends Controller {
|
|||
'name' => $this->ticket->owner->name,
|
||||
'staff' => true
|
||||
]);
|
||||
} else if($isOwner) {
|
||||
!Controller::request('private') ? $this->sendMail($ticketAuthor) : null;
|
||||
} else if($isOwner && !Controller::request('private')) {
|
||||
$this->sendMail($ticketAuthor);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -115,10 +115,16 @@ class CreateController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Log::createLog('CREATE_TICKET', $this->ticketNumber);
|
||||
Response::respondSuccess([
|
||||
'ticketNumber' => $this->ticketNumber
|
||||
]);
|
||||
|
||||
if(!Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) {
|
||||
$session = Session::getInstance();
|
||||
$session->createTicketSession($this->ticketNumber);
|
||||
}
|
||||
|
||||
Log::createLog('CREATE_TICKET', $this->ticketNumber);
|
||||
}
|
||||
|
||||
private function storeTicket() {
|
||||
|
|
|
@ -22,21 +22,36 @@ class Log extends DataStore {
|
|||
'authorUser',
|
||||
'authorStaff',
|
||||
'to',
|
||||
'date'
|
||||
'date',
|
||||
'authorName'
|
||||
];
|
||||
}
|
||||
|
||||
public static function createLog($type, $to, $author = null) {
|
||||
$session = Session::getInstance();
|
||||
$authorName = '';
|
||||
|
||||
if($session->isTicketSession()) {
|
||||
$ticketNumber = $session->getTicketNumber();
|
||||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||
$authorName = $ticket->authorToArray()['name'];
|
||||
}
|
||||
|
||||
if($author === null) {
|
||||
$author = Controller::getLoggedUser();
|
||||
}
|
||||
|
||||
if(!$author->isNull()) {
|
||||
$authorName = $author->name;
|
||||
}
|
||||
|
||||
$log = new Log();
|
||||
|
||||
$log->setProperties(array(
|
||||
'type' => $type,
|
||||
'to' => $to,
|
||||
'date' => Date::getCurrentDate()
|
||||
'date' => Date::getCurrentDate(),
|
||||
'authorName' => $authorName
|
||||
));
|
||||
|
||||
if($author instanceof User) {
|
||||
|
@ -55,8 +70,8 @@ class Log extends DataStore {
|
|||
'type' => $this->type,
|
||||
'to' => $this->to,
|
||||
'author' => [
|
||||
'name' => $author->name,
|
||||
'id' => $author->id,
|
||||
'name' => $this->authorName,
|
||||
'id' => ($author && !$author->isNull()) ? $author->id : null,
|
||||
'staff' => $author instanceof Staff
|
||||
],
|
||||
'date' => $this->date
|
||||
|
|
|
@ -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
|
||||
];
|
||||
|
|
|
@ -65,6 +65,35 @@ describe'system/disable-user-system' do
|
|||
(result['status']).should.equal('success')
|
||||
end
|
||||
|
||||
it 'should be able to comment on ticket as a non-logged user' do
|
||||
result = request('/ticket/create', {
|
||||
title: 'Doubt about Russian language',
|
||||
content: 'Stariy means old in Russian?',
|
||||
departmentId: 1,
|
||||
language: 'en',
|
||||
name: 'Abraham Einstein',
|
||||
email: 'abrahameinstein@opensupports.com'
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticketNumber = result['data']['ticketNumber']
|
||||
|
||||
result = request('/ticket/check', {
|
||||
ticketNumber: ticketNumber,
|
||||
email: 'abrahameinstein@opensupports.com',
|
||||
captcha: 'valid'
|
||||
})
|
||||
token = result['data']['token']
|
||||
(result['status']).should.equal('success');
|
||||
|
||||
result = request('/ticket/comment', {
|
||||
content: 'I actually think it is not like that, but anyways, thanks',
|
||||
ticketNumber: ticketNumber,
|
||||
csrf_token: token
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
end
|
||||
|
||||
it 'should be able to assign and respond tickets' do
|
||||
Scripts.login($staff[:email], $staff[:password], true);
|
||||
ticket = $database.getLastRow('ticket');
|
||||
|
@ -84,6 +113,26 @@ describe'system/disable-user-system' do
|
|||
(result['status']).should.equal('success')
|
||||
end
|
||||
|
||||
it 'should be able to get the latest events as admin' do
|
||||
result = request('/staff/last-events', {
|
||||
page: 1,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
(result['data'].size).should.equal(10)
|
||||
end
|
||||
|
||||
it 'should be able to get system logs as admin' do
|
||||
result = request('/system/get-logs', {
|
||||
page: 1,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
(result['data'].size).should.equal(10)
|
||||
end
|
||||
|
||||
it 'should be be able to create a ticket as an admin' do
|
||||
result = request('/ticket/create', {
|
||||
title: 'created by staff with user system disabled',
|
||||
|
@ -127,8 +176,7 @@ describe'system/disable-user-system' do
|
|||
|
||||
numberOftickets= $database.query("SELECT * FROM ticket WHERE author_email IS NULL AND author_name IS NULL AND author_id IS NOT NULL" )
|
||||
|
||||
(numberOftickets.num_rows).should.equal(52)
|
||||
|
||||
(numberOftickets.num_rows).should.equal(53)
|
||||
end
|
||||
|
||||
it 'should not enable the user system' do
|
||||
|
@ -140,6 +188,5 @@ describe'system/disable-user-system' do
|
|||
|
||||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('SYSTEM_USER_IS_ALREADY_ENABLED')
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue