Merged in OS-95-Path-ticket-change-priority (pull request #65)
guillermo- path-ticket-change-priority
This commit is contained in:
commit
03105ebf9b
|
@ -9,6 +9,7 @@ include 'ticket/get-custom-responses.php';
|
|||
include 'ticket/change-department.php';
|
||||
include 'ticket/close.php';
|
||||
include 'ticket/re-open.php';
|
||||
include 'ticket/change-priority.php';
|
||||
|
||||
$ticketControllers = new ControllerGroup();
|
||||
$ticketControllers->setGroupPath('/ticket');
|
||||
|
@ -23,4 +24,6 @@ $ticketControllers->addController(new GetCustomResponsesController);
|
|||
$ticketControllers->addController(new ChangeDepartmentController);
|
||||
$ticketControllers->addController(new CloseController);
|
||||
$ticketControllers->addController(new ReOpenController);
|
||||
$ticketControllers->addController(new ChangePriorityController);
|
||||
|
||||
$ticketControllers->finalize();
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class ChangePriorityController extends Controller {
|
||||
const PATH = '/change-priority';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_1',
|
||||
'requestData' => [
|
||||
'ticketNumber' => [
|
||||
'validation' => DataValidator::validTicketNumber(),
|
||||
'error' => ERRORS::INVALID_TICKET
|
||||
],
|
||||
'priority' => [
|
||||
'validation' => DataValidator::in(['low', 'medium', 'high']),
|
||||
'error' => ERRORS::INVALID_PRIORITY
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$ticketNumber = Controller::request('ticketNumber');
|
||||
$priority = Controller::request('priority');
|
||||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||
$user = Controller::getLoggedUser();
|
||||
|
||||
if($ticket->owner && $user->id === $ticket->owner->id) {
|
||||
$ticket->priority = $priority;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -18,4 +18,5 @@ class ERRORS {
|
|||
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
|
||||
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
|
||||
const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED';
|
||||
const INVALID_PRIORITY = 'INVALID_PRIORITY';
|
||||
}
|
||||
|
|
|
@ -29,4 +29,6 @@ require './staff/get.rb'
|
|||
require './staff/assign-ticket.rb'
|
||||
require './staff/un-assign-ticket.rb'
|
||||
require './staff/get-tickets.rb'
|
||||
require './ticket/change-priority.rb'
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
describe '/ticket/change-priority' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
#TODO: things that Ivan don't forget
|
||||
|
||||
it 'should change priority to high if everything is okey' do
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
|
||||
result = request('/ticket/change-priority', {
|
||||
priority:'high',
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('high')
|
||||
end
|
||||
|
||||
it 'should change priority to medium if everything is okey' do
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
|
||||
result = request('/ticket/change-priority', {
|
||||
priority:'medium',
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('medium')
|
||||
end
|
||||
|
||||
it 'should change priority to low if everything is okey' do
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
|
||||
result = request('/ticket/change-priority', {
|
||||
priority:'low',
|
||||
ticketNumber: ticket['ticket_number'],
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['priority']).should.equal('low')
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue