Merged in OS88-path-ticket-seen (pull request #70)

Os88 path ticket seen
This commit is contained in:
Ivan Diaz 2016-10-21 19:40:48 +00:00
commit 642409a47b
19 changed files with 113 additions and 6 deletions

View File

@ -34,6 +34,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->store(); $this->ticket->store();
$this->user->store(); $this->user->store();

View File

@ -26,6 +26,7 @@ class UnAssignStaffController extends Controller {
$user->sharedTicketList->remove($ticket); $user->sharedTicketList->remove($ticket);
$user->store(); $user->store();
$ticket->owner = null; $ticket->owner = null;
$ticket->unread = true;
$ticket->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();
} else { } else {

View File

@ -10,6 +10,7 @@ include 'ticket/change-department.php';
include 'ticket/close.php'; include 'ticket/close.php';
include 'ticket/re-open.php'; include 'ticket/re-open.php';
include 'ticket/change-priority.php'; include 'ticket/change-priority.php';
include 'ticket/seen.php';
$ticketControllers = new ControllerGroup(); $ticketControllers = new ControllerGroup();
$ticketControllers->setGroupPath('/ticket'); $ticketControllers->setGroupPath('/ticket');
@ -25,5 +26,6 @@ $ticketControllers->addController(new ChangeDepartmentController);
$ticketControllers->addController(new CloseController); $ticketControllers->addController(new CloseController);
$ticketControllers->addController(new ReOpenController); $ticketControllers->addController(new ReOpenController);
$ticketControllers->addController(new ChangePriorityController); $ticketControllers->addController(new ChangePriorityController);
$ticketControllers->addController(new SeenController);
$ticketControllers->finalize(); $ticketControllers->finalize();

View File

@ -34,6 +34,7 @@ class ChangeDepartmentController extends Controller {
} }
$ticket->department = $department; $ticket->department = $department;
$ticket->unread = true;
$ticket->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();
} }

View File

@ -28,6 +28,7 @@ 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->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();
} else { } else {

View File

@ -31,7 +31,12 @@ class CloseController extends Controller {
Response::respondError(ERRORS::NO_PERMISSION); Response::respondError(ERRORS::NO_PERMISSION);
return; return;
} }
if(Controller::isStaffLogged()) {
$ticket->unread = true;
} else {
$ticket->unreadStaff = true;
}
$ticket->closed = true; $ticket->closed = true;
$ticket->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();

View File

@ -51,11 +51,11 @@ class CommentController extends Controller {
)); ));
if(Controller::isStaffLogged()) { if(Controller::isStaffLogged()) {
$comment->authorUser = Controller::getLoggedUser(); $this->ticket->unread = true;
} else { } else {
$comment->authorUser = Controller::getLoggedUser(); $this->ticket->unreadStaff = true;
} }
$comment->authorUser = Controller::getLoggedUser();
$this->ticket->addEvent($comment); $this->ticket->addEvent($comment);
$this->ticket->store(); $this->ticket->store();
} }

View File

@ -58,6 +58,7 @@ class CreateController extends Controller {
'file' => '', 'file' => '',
'date' => Date::getCurrentDate(), 'date' => Date::getCurrentDate(),
'unread' => false, 'unread' => false,
'unreadStaff' => true,
'closed' => false, 'closed' => false,
)); ));

View File

@ -30,7 +30,11 @@ class ReOpenController extends Controller {
Response::respondError(ERRORS::NO_PERMISSION); Response::respondError(ERRORS::NO_PERMISSION);
return; return;
} }
if(Controller::isStaffLogged()) {
$ticket->unread = true;
} else {
$ticket->unreadStaff = true;
}
$ticket->closed = false; $ticket->closed = false;
$ticket->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();

View File

@ -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);
}
}

View File

@ -18,7 +18,8 @@ class Ticket extends DataStore {
'priority', 'priority',
'author', 'author',
'owner', 'owner',
'ownTicketeventList' 'ownTicketeventList',
'unreadStaff'
); );
} }
@ -33,6 +34,8 @@ class Ticket extends DataStore {
public function getDefaultProps() { public function getDefaultProps() {
return array( return array(
'priority' => 'low', 'priority' => 'low',
'unread' => false,
'unreadStaff' => true,
'ticketNumber' => $this->generateUniqueTicketNumber() 'ticketNumber' => $this->generateUniqueTicketNumber()
); );
} }

View File

@ -22,6 +22,8 @@ describe '/staff/assign-ticket' do
(ticket['owner_id']).should.equal('1') (ticket['owner_id']).should.equal('1')
(ticket['unread']).should.equal('1')
staff_ticket = $database.getRow('staff_ticket', 1 , 'id') staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
(staff_ticket['staff_id']).should.equal('1') (staff_ticket['staff_id']).should.equal('1')

View File

@ -21,6 +21,7 @@ describe '/staff/un-assign-ticket' do
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')
(ticket['owner_id']).should.equal(nil) (ticket['owner_id']).should.equal(nil)
(ticket['unread']).should.equal('1')
staff_ticket = $database.getRow('staff_ticket', 1 , 'id') staff_ticket = $database.getRow('staff_ticket', 1 , 'id')

View File

@ -17,6 +17,7 @@ describe '/ticket/change-department' do
(result['status']).should.equal('success') (result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')
(ticket['unread']).should.equal('1')
(ticket['department_id']).should.equal('2') (ticket['department_id']).should.equal('2')
end end
end end

View File

@ -18,6 +18,7 @@ describe '/ticket/change-priority' do
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')
(ticket['priority']).should.equal('high') (ticket['priority']).should.equal('high')
(ticket['unread']).should.equal('1')
end end
it 'should change priority to medium if everything is okey' do 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 = $database.getRow('ticket', 1 , 'id')
(ticket['priority']).should.equal('medium') (ticket['priority']).should.equal('medium')
(ticket['unread']).should.equal('1')
end end
it 'should change priority to low if everything is okey' do 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 = $database.getRow('ticket', 1 , 'id')
(ticket['priority']).should.equal('low') (ticket['priority']).should.equal('low')
(ticket['unread']).should.equal('1')
end end
end end

View File

@ -17,6 +17,7 @@ describe '/ticket/close' do
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')
(ticket['closed']).should.equal('1') (ticket['closed']).should.equal('1')
(ticket['unread']).should.equal('1')
end end
end end

View File

@ -72,6 +72,7 @@ describe '/ticket/comment/' do
(comment['content']).should.equal('some comment content') (comment['content']).should.equal('some comment content')
(comment['type']).should.equal('COMMENT') (comment['type']).should.equal('COMMENT')
(comment['author_user_id']).should.equal($csrf_userid) (comment['author_user_id']).should.equal($csrf_userid)
(ticket['unread_staff']).should.equal('1')
end 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

View File

@ -17,6 +17,7 @@ describe '/ticket/re-open' do
ticket = $database.getRow('ticket', 1 , 'id') ticket = $database.getRow('ticket', 1 , 'id')
(ticket['closed']).should.equal('0') (ticket['closed']).should.equal('0')
(ticket['unread']).should.equal('1')
end end
end end

39
tests/ticket/seen.rb Normal file
View File

@ -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