Merged in os-80-staff-un-assign-ticket (pull request #61)

Os 80 staff un assign ticket
This commit is contained in:
Ivan Diaz 2016-10-14 19:35:02 +00:00
commit a42e00ad9b
4 changed files with 80 additions and 0 deletions

View File

@ -1,11 +1,13 @@
<?php
require_once 'staff/get.php';
require_once 'staff/assign-ticket.php';
require_once 'staff/un-assign-ticket.php';
$systemControllerGroup = new ControllerGroup();
$systemControllerGroup->setGroupPath('/staff');
$systemControllerGroup->addController(new GetStaffController);
$systemControllerGroup->addController(new AssignStaffController);
$systemControllerGroup->addController(new UnAssignStaffController);
$systemControllerGroup->finalize();

View File

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

View File

@ -24,3 +24,4 @@ require './ticket/get.rb'
require './ticket/custom-response.rb'
require './staff/get.rb'
require './staff/assign-ticket.rb'
require './staff/un-assign-ticket.rb'

View File

@ -0,0 +1,41 @@
describe '/staff/un-assign-ticket' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
#TODO: Create a staff without the ticket
#it 'should fail if staff is not assign to the ticket'do
#end
it 'should un assign ticket if everything is okey' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/staff/un-assign-ticket', {
ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
ticket = $database.getRow('ticket', 1 , 'id')
(ticket['owner_id']).should.equal(nil)
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
(staff_ticket).should.equal(nil)
end
it 'should fail if ticket is not yours' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/staff/un-assign-ticket', {
ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
end
end