remove tag path

This commit is contained in:
Ivan Diaz 2019-02-22 14:08:49 -03:00
parent 7092d19c27
commit fad0e8eafb
3 changed files with 65 additions and 2 deletions

View File

@ -56,7 +56,8 @@ class GetSettingsController extends Controller {
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages(),
'session-prefix' => Setting::getSetting('session-prefix')->getValue(),
'mail-template-header-image' => Setting::getSetting('mail-template-header-image')->getValue()
'mail-template-header-image' => Setting::getSetting('mail-template-header-image')->getValue(),
'tags' => Tag::getAll()->toArray()
];
} else {
$settingsList = [
@ -73,7 +74,8 @@ class GetSettingsController extends Controller {
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages(),
'user-system-enabled' => intval(Setting::getSetting('user-system-enabled')->getValue()),
'session-prefix' => Setting::getSetting('session-prefix')->getValue()
'session-prefix' => Setting::getSetting('session-prefix')->getValue(),
'tags' => Tag::getAll()->toArray()
];
}
}

View File

@ -21,5 +21,6 @@ $ticketControllers->addController(new EditTagController);
$ticketControllers->addController(new DeleteTagController);
$ticketControllers->addController(new GetTagsController);
$ticketControllers->addController(new AddTagController);
$ticketControllers->addController(new RemoveTagController);
$ticketControllers->finalize();

View File

@ -0,0 +1,60 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
/**
* @api {post} /ticket/remove-tag Remove tag
* @apiVersion 4.3.2
*
* @apiName Remove tag
*
* @apiGroup Ticket
*
* @apiDescription This path removes a tag from a ticket.
*
* @apiPermission staff1
*
* @apiParam {Number} ticketNumber The number of the ticket which the tag is going to be removed.
* @apiParam {String} tagId The id of the tag to be removed.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
* @apiUse INVALID_TAG
*
* @apiSuccess {Object} data Empty object
*
*/
class RemoveTagController extends Controller {
const PATH = '/remove-tag';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
],
'tagId' => [
'validation' => DataValidator::dataStoreId('tag'),
'error' => ERRORS::INVALID_TAG
]
]
];
}
public function handler() {
$tagId = Controller::request('tagId');
$tag = Tag::getDataStore($tagId);
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
if (!$ticket->sharedTagList->includesId($tagId)) throw new RequestException(ERRORS::INVALID_TAG);
$ticket->sharedTagList->remove($tag);
$ticket->store();
Response::respondSuccess();
}
}