guillermo- path-ticket-close and path-ticket-re-open [skip ci]

This commit is contained in:
ivan 2016-10-15 03:23:12 -03:00
parent 6961b3c6a0
commit 073a429231
7 changed files with 133 additions and 4 deletions

View File

@ -7,6 +7,8 @@ include 'ticket/delete-custom-response.php';
include 'ticket/edit-custom-response.php';
include 'ticket/get-custom-responses.php';
include 'ticket/change-department.php';
include 'ticket/close.php';
include 'ticket/re-open.php';
$ticketControllers = new ControllerGroup();
$ticketControllers->setGroupPath('/ticket');
@ -19,5 +21,6 @@ $ticketControllers->addController(new DeleteCustomResponseController);
$ticketControllers->addController(new EditCustomResponseController);
$ticketControllers->addController(new GetCustomResponsesController);
$ticketControllers->addController(new ChangeDepartmentController);
$ticketControllers->addController(new CloseController);
$ticketControllers->addController(new ReOpenController);
$ticketControllers->finalize();

View File

@ -0,0 +1,39 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class CloseController extends Controller {
const PATH = '/close';
public function validations() {
return [
'permission' => 'user',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$ticket = Ticket::getByTicketNumber($ticketNumber);
$user = Controller::getLoggedUser();
if(!Controller::isStaffLogged() && $ticket->author->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
if(Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
$ticket->closed = true;
$ticket->store();
Response::respondSuccess();
}
}

View File

@ -0,0 +1,38 @@
<?php
use Respect\Validation\Validator as DataValidator;
class ReOpenController extends Controller {
const PATH = '/re-open';
public function validations() {
return [
'permission' => 'user',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$ticket = Ticket::getByTicketNumber($ticketNumber);
$user = Controller::getLoggedUser();
if(!Controller::isStaffLogged() && $ticket->author->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
if(Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id !== $user->id){
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
$ticket->closed = false;
$ticket->store();
Response::respondSuccess();
}
}

View File

@ -22,7 +22,11 @@ require './ticket/create.rb'
require './ticket/comment.rb'
require './ticket/get.rb'
require './ticket/custom-response.rb'
require './ticket/change-department.rb'
require './ticket/close.rb'
require './ticket/re-open.rb'
require './staff/get.rb'
require './staff/assign-ticket.rb'
require './staff/un-assign-ticket.rb'
require './staff/get-tickets.rb'

View File

@ -5,10 +5,11 @@ describe '/ticket/change-department' do
#TODO: Create tests
it 'should change department if everything is okey' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/ticket/change-department', {
ticketNumber:1,
departmentId:2,
ticketNumber: ticket['ticket_number'],
departmentId: 2,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -16,6 +17,6 @@ describe '/ticket/change-department' do
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id')
(ticket['department']).should.equal('2')
(ticket['department_id']).should.equal('2')
end
end

22
tests/ticket/close.rb Normal file
View File

@ -0,0 +1,22 @@
describe '/ticket/close' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
#TODO: DO THINGS
it 'should close a ticket if everything is okey' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/ticket/close', {
ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id')
(ticket['closed']).should.equal('1')
end
end

22
tests/ticket/re-open.rb Normal file
View File

@ -0,0 +1,22 @@
describe '/ticket/re-open' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
#TODO: DO THINGS
it 'should re open a ticket if everything is okey' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/ticket/re-open', {
ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id')
(ticket['closed']).should.equal('0')
end
end