Mark as unread if author is not making the change

This commit is contained in:
Ivan Diaz 2018-07-17 02:04:00 -03:00
parent 050623713c
commit 0a5d444186
11 changed files with 59 additions and 17 deletions

View File

@ -59,7 +59,7 @@ class AssignStaffController extends Controller {
} else { } else {
$this->user->sharedTicketList->add($this->ticket); $this->user->sharedTicketList->add($this->ticket);
$this->ticket->owner = $this->user; $this->ticket->owner = $this->user;
$this->ticket->unread = true; $this->ticket->unread = !$this->ticket->isAuthor($this->user);
$event = Ticketevent::getEvent(Ticketevent::ASSIGN); $event = Ticketevent::getEvent(Ticketevent::ASSIGN);
$event->setProperties(array( $event->setProperties(array(
'authorStaff' => Controller::getLoggedUser(), 'authorStaff' => Controller::getLoggedUser(),

View File

@ -50,7 +50,7 @@ class UnAssignStaffController extends Controller {
$owner->store(); $owner->store();
$ticket->owner = null; $ticket->owner = null;
$ticket->unread = true; $ticket->unread = !$ticket->isAuthor($user);
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN); $event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
$event->setProperties(array( $event->setProperties(array(

View File

@ -64,7 +64,7 @@ class ChangeDepartmentController extends Controller {
)); ));
$ticket->addEvent($event); $ticket->addEvent($event);
$ticket->department = $department; $ticket->department = $department;
$ticket->unread = true; $ticket->unread = !$ticket->isAuthor($user);
$ticket->store(); $ticket->store();
if(!$user->sharedDepartmentList->includesId($department->id)) { if(!$user->sharedDepartmentList->includesId($department->id)) {

View File

@ -18,9 +18,9 @@ use Respect\Validation\Validator as DataValidator;
* *
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET * @apiUse INVALID_TICKET
* @apiUse INVALID_PRIORITY * @apiUse INVALID_PRIORITY
* *
* @apiSuccess {Object} data Empty object * @apiSuccess {Object} data Empty object
* *
*/ */
@ -52,10 +52,10 @@ class ChangePriorityController extends Controller {
if($ticket->owner && $user->id === $ticket->owner->id) { if($ticket->owner && $user->id === $ticket->owner->id) {
$ticket->priority = $priority; $ticket->priority = $priority;
$ticket->unread = true; $ticket->unread = !$ticket->isAuthor($user);
$event = Ticketevent::getEvent(Ticketevent::PRIORITY_CHANGED); $event = Ticketevent::getEvent(Ticketevent::PRIORITY_CHANGED);
$event->setProperties(array( $event->setProperties(array(
'authorStaff' => Controller::getLoggedUser(), 'authorStaff' => Controller::getLoggedUser(),
'content' => $ticket->priority, 'content' => $ticket->priority,
'date' => Date::getCurrentDate() 'date' => Date::getCurrentDate()
)); ));
@ -70,5 +70,3 @@ class ChangePriorityController extends Controller {
} }
} }

View File

@ -83,11 +83,8 @@ class CloseController extends Controller {
} }
private function markAsUnread() { private function markAsUnread() {
if(Controller::isStaffLogged()) { $this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser());
$this->ticket->unread = true; $this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser());
} else {
$this->ticket->unreadStaff = true;
}
} }
private function addCloseEvent() { private function addCloseEvent() {

View File

@ -115,7 +115,8 @@ class CommentController extends Controller {
)); ));
if(Controller::isStaffLogged()) { if(Controller::isStaffLogged()) {
$this->ticket->unread = true; $this->ticket->unread = !$this->ticket->isAuthor(Controller::getLoggedUser());
$this->ticket->unreadStaff = !$this->ticket->isOwner(Controller::getLoggedUser());
$comment->authorStaff = Controller::getLoggedUser(); $comment->authorStaff = Controller::getLoggedUser();
} else if(Controller::isUserSystemEnabled()) { } else if(Controller::isUserSystemEnabled()) {
$this->ticket->unreadStaff = true; $this->ticket->unreadStaff = true;

View File

@ -10,6 +10,6 @@ describe '/staff/get-new-tickets' do
}) })
(result['status']).should.equal('success') (result['status']).should.equal('success')
(result['data'].size).should.equal(9) (result['data'].size).should.equal(10)
end end
end end

View File

@ -92,7 +92,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= $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(39) (numberOftickets.num_rows).should.equal(40)
end end

View File

@ -34,6 +34,7 @@ describe '/ticket/close' do
csrf_token: $csrf_token csrf_token: $csrf_token
}) })
puts result
(result['status']).should.equal('success') (result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')

View File

@ -78,6 +78,31 @@ describe '/ticket/comment/' do
(lastLog['type']).should.equal('COMMENT') (lastLog['type']).should.equal('COMMENT')
end end
it 'should add comment to ticket created by staff' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
result = request('/ticket/comment', {
content: 'some comment content',
ticketNumber: $ticketNumberByStaff,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', $ticketNumberByStaff, 'ticket_number')
comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id')
(comment['content']).should.equal('some comment content')
(comment['type']).should.equal('COMMENT')
(comment['author_staff_id']).should.equal($csrf_userid)
(ticket['unread_staff']).should.equal('1')
lastLog = $database.getLastRow('log')
(lastLog['type']).should.equal('COMMENT')
request('/user/logout')
end
it 'should fail if user is not the author nor owner' do it 'should fail if user is not the author nor owner' do
Scripts.createUser('no_commenter@comment.com', 'no_commenter', 'No Commenter') Scripts.createUser('no_commenter@comment.com', 'no_commenter', 'No Commenter')
Scripts.login('no_commenter@comment.com', 'no_commenter') Scripts.login('no_commenter@comment.com', 'no_commenter')

View File

@ -144,4 +144,24 @@ describe '/ticket/create' do
(ticket2).should.equal((ticket0 - 100000 + 2 * ticket_number_gap) % 900000 + 100000) (ticket2).should.equal((ticket0 - 100000 + 2 * ticket_number_gap) % 900000 + 100000)
(ticket3).should.equal((ticket0 - 100000 + 3 * ticket_number_gap) % 900000 + 100000) (ticket3).should.equal((ticket0 - 100000 + 3 * ticket_number_gap) % 900000 + 100000)
end end
it 'should be able to create a ticket while being staff' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
result = request('/ticket/create', {
title: 'created by staff',
content: 'The staff created it',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', result['data']['ticketNumber'], 'ticket_number')
(ticket['author_id']).should.equal(nil)
(ticket['author_staff_id']).should.equal('1')
$ticketNumberByStaff = result['data']['ticketNumber']
request('/user/logout')
end
end end