Merged in OS-79-assign-ticket-to-staff (pull request #59)

OS-79 assign ticket to staff
This commit is contained in:
Ivan Diaz 2016-10-10 14:26:52 -03:00
commit 884bea6713
6 changed files with 105 additions and 1 deletions

View File

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

View File

@ -0,0 +1,56 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class AssignStaffController extends Controller {
const PATH = '/assign-ticket';
private $ticket;
private $user;
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
$this->user = Controller::getLoggedUser();
$this->ticket = Ticket::getByTicketNumber($ticketNumber);
if($this->ticket->owner) {
Response::respondError(ERRORS::TICKET_ALREADY_ASSIGNED);
return;
}
if(!$this->ticketHasStaffDepartment()) {
Response::respondError(ERRORS::INVALID_DEPARTMENT);
} else {
$this->user->sharedTicketList->add($this->ticket);
$this->ticket->owner = $this->user;
$this->ticket->store();
$this->user->store();
Response::respondSuccess();
}
}
public function ticketHasStaffDepartment() {
$departmentMatch = false;
foreach ($this->user->sharedDepartmentList as $department) {
if($this->ticket->department->id === $department->id) {
$departmentMatch = true;
}
}
return $departmentMatch;
}
}

View File

@ -17,4 +17,5 @@ class ERRORS {
const INVALID_CAPTCHA = 'INVALID_CAPTCHA';
const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT';
const INVALID_LANGUAGE = 'INVALID_LANGUAGE';
const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED';
}

View File

@ -32,7 +32,6 @@ class Ticket extends DataStore {
public function getDefaultProps() {
return array(
'owner' => null,
'priority' => 'low',
'ticketNumber' => $this->generateUniqueTicketNumber()
);

View File

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

View File

@ -0,0 +1,45 @@
describe '/staff/assign-ticket' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
#TODO: Create a staff without all department
#it 'should fail if staff is not in the same department'do
#end
it 'should assign ticket if everything is okey' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/staff/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('1')
staff_ticket = $database.getRow('staff_ticket', 1 , 'id')
(staff_ticket['staff_id']).should.equal('1')
(staff_ticket['ticket_id']).should.equal('1')
end
it 'should fail if ticket is already owned' do
ticket = $database.getRow('ticket', 1 , 'id')
result = request('/staff/assign-ticket', {
ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('TICKET_ALREADY_ASSIGNED')
end
end