guillermo- path-ticket-close and path-ticket-re-open [skip ci]
This commit is contained in:
parent
6961b3c6a0
commit
073a429231
|
@ -7,6 +7,8 @@ include 'ticket/delete-custom-response.php';
|
||||||
include 'ticket/edit-custom-response.php';
|
include 'ticket/edit-custom-response.php';
|
||||||
include 'ticket/get-custom-responses.php';
|
include 'ticket/get-custom-responses.php';
|
||||||
include 'ticket/change-department.php';
|
include 'ticket/change-department.php';
|
||||||
|
include 'ticket/close.php';
|
||||||
|
include 'ticket/re-open.php';
|
||||||
|
|
||||||
$ticketControllers = new ControllerGroup();
|
$ticketControllers = new ControllerGroup();
|
||||||
$ticketControllers->setGroupPath('/ticket');
|
$ticketControllers->setGroupPath('/ticket');
|
||||||
|
@ -19,5 +21,6 @@ $ticketControllers->addController(new DeleteCustomResponseController);
|
||||||
$ticketControllers->addController(new EditCustomResponseController);
|
$ticketControllers->addController(new EditCustomResponseController);
|
||||||
$ticketControllers->addController(new GetCustomResponsesController);
|
$ticketControllers->addController(new GetCustomResponsesController);
|
||||||
$ticketControllers->addController(new ChangeDepartmentController);
|
$ticketControllers->addController(new ChangeDepartmentController);
|
||||||
|
$ticketControllers->addController(new CloseController);
|
||||||
|
$ticketControllers->addController(new ReOpenController);
|
||||||
$ticketControllers->finalize();
|
$ticketControllers->finalize();
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,11 @@ require './ticket/create.rb'
|
||||||
require './ticket/comment.rb'
|
require './ticket/comment.rb'
|
||||||
require './ticket/get.rb'
|
require './ticket/get.rb'
|
||||||
require './ticket/custom-response.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/get.rb'
|
||||||
require './staff/assign-ticket.rb'
|
require './staff/assign-ticket.rb'
|
||||||
require './staff/un-assign-ticket.rb'
|
require './staff/un-assign-ticket.rb'
|
||||||
require './staff/get-tickets.rb'
|
require './staff/get-tickets.rb'
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,11 @@ describe '/ticket/change-department' do
|
||||||
#TODO: Create tests
|
#TODO: Create tests
|
||||||
|
|
||||||
it 'should change department if everything is okey' do
|
it 'should change department if everything is okey' do
|
||||||
|
ticket = $database.getRow('ticket', 1 , 'id')
|
||||||
|
|
||||||
result = request('/ticket/change-department', {
|
result = request('/ticket/change-department', {
|
||||||
ticketNumber:1,
|
ticketNumber: ticket['ticket_number'],
|
||||||
departmentId:2,
|
departmentId: 2,
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -16,6 +17,6 @@ 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['department']).should.equal('2')
|
(ticket['department_id']).should.equal('2')
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue