Merged in OS88-path-ticket-seen (pull request #70)
Os88 path ticket seen
This commit is contained in:
commit
642409a47b
|
@ -34,6 +34,7 @@ class AssignStaffController extends Controller {
|
|||
} else {
|
||||
$this->user->sharedTicketList->add($this->ticket);
|
||||
$this->ticket->owner = $this->user;
|
||||
$this->ticket->unread = true;
|
||||
$this->ticket->store();
|
||||
$this->user->store();
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class UnAssignStaffController extends Controller {
|
|||
$user->sharedTicketList->remove($ticket);
|
||||
$user->store();
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = true;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
|
|
|
@ -10,6 +10,7 @@ include 'ticket/change-department.php';
|
|||
include 'ticket/close.php';
|
||||
include 'ticket/re-open.php';
|
||||
include 'ticket/change-priority.php';
|
||||
include 'ticket/seen.php';
|
||||
|
||||
$ticketControllers = new ControllerGroup();
|
||||
$ticketControllers->setGroupPath('/ticket');
|
||||
|
@ -25,5 +26,6 @@ $ticketControllers->addController(new ChangeDepartmentController);
|
|||
$ticketControllers->addController(new CloseController);
|
||||
$ticketControllers->addController(new ReOpenController);
|
||||
$ticketControllers->addController(new ChangePriorityController);
|
||||
$ticketControllers->addController(new SeenController);
|
||||
|
||||
$ticketControllers->finalize();
|
|
@ -34,6 +34,7 @@ class ChangeDepartmentController extends Controller {
|
|||
}
|
||||
|
||||
$ticket->department = $department;
|
||||
$ticket->unread = true;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class ChangePriorityController extends Controller {
|
|||
|
||||
if($ticket->owner && $user->id === $ticket->owner->id) {
|
||||
$ticket->priority = $priority;
|
||||
$ticket->unread = true;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
|
|
|
@ -31,7 +31,12 @@ class CloseController extends Controller {
|
|||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(Controller::isStaffLogged()) {
|
||||
$ticket->unread = true;
|
||||
} else {
|
||||
$ticket->unreadStaff = true;
|
||||
}
|
||||
$ticket->closed = true;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
|
|
|
@ -51,11 +51,11 @@ class CommentController extends Controller {
|
|||
));
|
||||
|
||||
if(Controller::isStaffLogged()) {
|
||||
$comment->authorUser = Controller::getLoggedUser();
|
||||
$this->ticket->unread = true;
|
||||
} else {
|
||||
$comment->authorUser = Controller::getLoggedUser();
|
||||
$this->ticket->unreadStaff = true;
|
||||
}
|
||||
|
||||
$comment->authorUser = Controller::getLoggedUser();
|
||||
$this->ticket->addEvent($comment);
|
||||
$this->ticket->store();
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ class CreateController extends Controller {
|
|||
'file' => '',
|
||||
'date' => Date::getCurrentDate(),
|
||||
'unread' => false,
|
||||
'unreadStaff' => true,
|
||||
'closed' => false,
|
||||
));
|
||||
|
||||
|
|
|
@ -30,7 +30,11 @@ class ReOpenController extends Controller {
|
|||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Controller::isStaffLogged()) {
|
||||
$ticket->unread = true;
|
||||
} else {
|
||||
$ticket->unreadStaff = true;
|
||||
}
|
||||
$ticket->closed = false;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class SeenController extends Controller {
|
||||
const PATH = '/seen';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'user',
|
||||
'requestData' => [
|
||||
'ticketNumber' => [
|
||||
'validation' => DataValidator::validTicketNumber(),
|
||||
'error' => ERRORS::INVALID_TICKET
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$ticketnumber = Controller::request('ticketNumber');
|
||||
$user = Controller::getLoggedUser();
|
||||
$ticket = Ticket::getByTicketNumber($ticketnumber);
|
||||
|
||||
if (Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id === $user->id) {
|
||||
$ticket->unreadStaff = false;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
return;
|
||||
}
|
||||
if (!Controller::isStaffLogged() && $ticket->author && $user->id === $ticket->author->id) {
|
||||
$ticket->unread = false;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
return;
|
||||
}
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
|
||||
}
|
||||
}
|
|
@ -18,7 +18,8 @@ class Ticket extends DataStore {
|
|||
'priority',
|
||||
'author',
|
||||
'owner',
|
||||
'ownTicketeventList'
|
||||
'ownTicketeventList',
|
||||
'unreadStaff'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -33,6 +34,8 @@ class Ticket extends DataStore {
|
|||
public function getDefaultProps() {
|
||||
return array(
|
||||
'priority' => 'low',
|
||||
'unread' => false,
|
||||
'unreadStaff' => true,
|
||||
'ticketNumber' => $this->generateUniqueTicketNumber()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ describe '/staff/assign-ticket' do
|
|||
|
||||
(ticket['owner_id']).should.equal('1')
|
||||
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
||||
|
||||
(staff_ticket['staff_id']).should.equal('1')
|
||||
|
|
|
@ -21,6 +21,7 @@ describe '/staff/un-assign-ticket' do
|
|||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
|
||||
(ticket['owner_id']).should.equal(nil)
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ describe '/ticket/change-department' do
|
|||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['unread']).should.equal('1')
|
||||
(ticket['department_id']).should.equal('2')
|
||||
end
|
||||
end
|
|
@ -18,6 +18,7 @@ describe '/ticket/change-priority' do
|
|||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('high')
|
||||
(ticket['unread']).should.equal('1')
|
||||
end
|
||||
|
||||
it 'should change priority to medium if everything is okey' do
|
||||
|
@ -34,6 +35,7 @@ describe '/ticket/change-priority' do
|
|||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('medium')
|
||||
(ticket['unread']).should.equal('1')
|
||||
end
|
||||
|
||||
it 'should change priority to low if everything is okey' do
|
||||
|
@ -50,6 +52,7 @@ describe '/ticket/change-priority' do
|
|||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('low')
|
||||
(ticket['unread']).should.equal('1')
|
||||
end
|
||||
|
||||
end
|
|
@ -17,6 +17,7 @@ describe '/ticket/close' do
|
|||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['closed']).should.equal('1')
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
end
|
||||
end
|
|
@ -72,6 +72,7 @@ describe '/ticket/comment/' do
|
|||
(comment['content']).should.equal('some comment content')
|
||||
(comment['type']).should.equal('COMMENT')
|
||||
(comment['author_user_id']).should.equal($csrf_userid)
|
||||
(ticket['unread_staff']).should.equal('1')
|
||||
end
|
||||
|
||||
it 'should fail if user is not the author nor owner' do
|
||||
|
|
|
@ -17,6 +17,7 @@ describe '/ticket/re-open' do
|
|||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['closed']).should.equal('0')
|
||||
(ticket['unread']).should.equal('1')
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,39 @@
|
|||
describe '/ticket/seen' do
|
||||
|
||||
describe 'when a staff is logged' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
it 'should change unread if everything is okey ' do
|
||||
ticket = $database.getRow('ticket', 1, 'id')
|
||||
result = request('/ticket/seen', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
ticket = $database.getRow('ticket', 1, 'id')
|
||||
(ticket['unreadStaff']).should.equal('0')
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a user is logged' do
|
||||
|
||||
request('/user/logout')
|
||||
Scripts.login()
|
||||
it 'should change unread if everything is okey ' do
|
||||
ticket = $database.getRow('ticket', 1, 'id')
|
||||
result = request('/ticket/seen', {
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
ticket = $database.getRow('ticket', 1, 'id')
|
||||
(ticket['unread']).should.equal('0')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue