opensupports/server/controllers/staff/un-assign-ticket.php

82 lines
2.2 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
2017-04-18 06:39:55 +02:00
/**
* @api {post} /staff/un-assign-ticket Un-assign ticket
2019-03-06 16:47:24 +01:00
* @apiVersion 4.4.0
2017-04-18 06:39:55 +02:00
*
* @apiName Un-assign ticket
*
* @apiGroup Staff
2017-04-18 06:39:55 +02:00
*
* @apiDescription This path un-assigns a ticket to the current staff member.
2017-04-18 06:39:55 +02:00
*
* @apiPermission staff1
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} ticketNumber Ticket number to un-assign.
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
2017-04-18 06:39:55 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiSuccess {Object} data Empty object
2017-04-18 06:39:55 +02:00
*
*/
class UnAssignStaffController extends Controller {
const PATH = '/un-assign-ticket';
const METHOD = 'POST';
2018-11-16 00:51:44 +01:00
private $user;
public function __construct($user=null) {
$this->user = $user;
}
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
]
]
];
}
public function handler() {
$ticketNumber = Controller::request('ticketNumber');
2018-11-16 00:51:44 +01:00
$user = ($this->user? $this->user : Controller::getLoggedUser());
$ticket = Ticket::getByTicketNumber($ticketNumber);
2018-04-18 20:31:17 +02:00
$owner = $ticket->owner;
2019-07-05 01:22:38 +02:00
if(!$user->canManageTicket($ticket)) {
throw new RequestException(ERRORS::NO_PERMISSION);
}
if($owner && ($ticket->isOwner($user) || $user->level > 2)) {
if(!$ticket->isAuthor($owner)) {
$owner->sharedTicketList->remove($ticket);
$owner->store();
}
2018-03-09 19:17:28 +01:00
$ticket->owner = null;
$ticket->unread = !$ticket->isAuthor($user);
2018-03-09 19:17:28 +01:00
$event = Ticketevent::getEvent(Ticketevent::UN_ASSIGN);
$event->setProperties(array(
'authorStaff' => $user,
'date' => Date::getCurrentDate(),
'content' => $owner->name
));
2018-03-09 19:17:28 +01:00
$ticket->addEvent($event);
$ticket->store();
Response::respondSuccess();
} else {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::NO_PERMISSION);
}
}
2018-03-09 19:17:28 +01:00
}