opensupports/server/controllers/ticket/get.php

84 lines
2.6 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-17 04:59:11 +02:00
/**
* @api {post} /ticket/get Get ticket
2018-11-29 17:35:14 +01:00
* @apiVersion 4.3.2
2017-04-17 04:59:11 +02:00
*
* @apiName Get ticket
2017-04-17 04:59:11 +02:00
*
* @apiGroup Ticket
*
2017-04-21 08:09:24 +02:00
* @apiDescription This path retrieves information about a ticket.
2017-04-17 04:59:11 +02:00
*
* @apiPermission user
2017-04-17 04:59:11 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} ticketNumber The number of the ticket.
2017-04-17 04:59:11 +02:00
*
2017-04-20 05:55:38 +02:00
* @apiUse INVALID_TICKET
2017-06-13 06:03:06 +02:00
* @apiUse INVALID_TOKEN
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
2018-04-18 20:31:17 +02:00
*
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)} data Information about the requested ticket.
2018-04-18 20:31:17 +02:00
*
2017-04-17 04:59:11 +02:00
*/
2017-04-20 05:55:38 +02:00
class TicketGetController extends Controller {
const PATH = '/get';
const METHOD = 'POST';
2016-11-21 03:01:38 +01:00
private $ticket;
public function validations() {
$session = Session::getInstance();
if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
return [
'permission' => 'user',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
} else {
return [
'permission' => 'any',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::equals($session->getTicketNumber()),
'error' => ERRORS::INVALID_TICKET
],
'csrf_token' => [
'validation' => DataValidator::equals($session->getToken()),
2017-06-13 06:03:06 +02:00
'error' => ERRORS::INVALID_TOKEN
]
]
];
}
}
public function handler() {
2016-11-21 03:01:38 +01:00
$this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
if(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
if ($this->shouldDenyPermission()) {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::NO_PERMISSION);
} else {
Response::respondSuccess($this->ticket->toArray());
}
} else {
2016-11-21 03:01:38 +01:00
Response::respondSuccess($this->ticket->toArray());
}
}
2016-11-21 03:01:38 +01:00
private function shouldDenyPermission() {
$user = Controller::getLoggedUser();
return (!Controller::isStaffLogged() && (Controller::isUserSystemEnabled() && $this->ticket->author->id !== $user->id)) ||
(Controller::isStaffLogged() && (!$user->sharedTicketList->includesId($this->ticket->id) && !$user->sharedDepartmentList->includesId($this->ticket->department->id)));
2016-11-21 03:01:38 +01:00
}
2018-04-18 20:31:17 +02:00
}