Categories can be deleted, fixed request methods
This commit is contained in:
parent
dd690decb2
commit
9582689f2a
@ -117,4 +117,13 @@ class CategoryHandler {
|
|||||||
|
|
||||||
return $allCategories[$category->id];
|
return $allCategories[$category->id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteCategory($id, $userContext, $heskSettings) {
|
||||||
|
if (!$this->permissionChecker->doesUserHavePermission($userContext, UserPrivilege::CAN_MANAGE_CATEGORIES)) {
|
||||||
|
throw new AccessViolationException('User cannot manage categories!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->categoryGateway->deleteCategory($id, $heskSettings);
|
||||||
|
$this->categoryGateway->resortAllCategories($heskSettings);
|
||||||
|
}
|
||||||
}
|
}
|
@ -34,7 +34,7 @@ class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function post() {
|
function post() {
|
||||||
global $hesk_settings, $applicationContext;
|
global $hesk_settings, $userContext, $applicationContext;
|
||||||
|
|
||||||
$data = JsonRetriever::getJsonData();
|
$data = JsonRetriever::getJsonData();
|
||||||
|
|
||||||
@ -43,9 +43,9 @@ class CategoryController {
|
|||||||
/* @var $categoryHandler CategoryHandler */
|
/* @var $categoryHandler CategoryHandler */
|
||||||
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
||||||
|
|
||||||
$category = $categoryHandler->createCategory($category, $hesk_settings);
|
$category = $categoryHandler->createCategory($category, $userContext, $hesk_settings);
|
||||||
|
|
||||||
return output($category);
|
return output($category, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +71,7 @@ class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function put($id) {
|
function put($id) {
|
||||||
global $hesk_settings, $applicationContext;
|
global $hesk_settings, $userContext, $applicationContext;
|
||||||
|
|
||||||
$data = JsonRetriever::getJsonData();
|
$data = JsonRetriever::getJsonData();
|
||||||
|
|
||||||
@ -81,12 +81,19 @@ class CategoryController {
|
|||||||
/* @var $categoryHandler CategoryHandler */
|
/* @var $categoryHandler CategoryHandler */
|
||||||
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
||||||
|
|
||||||
$category = $categoryHandler->editCategory($category, $hesk_settings);
|
$category = $categoryHandler->editCategory($category, $userContext, $hesk_settings);
|
||||||
|
|
||||||
return output($category);
|
return output($category);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
//-- TODO: Delete category
|
global $hesk_settings, $userContext, $applicationContext;
|
||||||
|
|
||||||
|
/* @var $categoryHandler CategoryHandler */
|
||||||
|
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
||||||
|
|
||||||
|
$categoryHandler->deleteCategory($id, $userContext, $hesk_settings);
|
||||||
|
|
||||||
|
return http_response_code(204);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -116,4 +116,12 @@ class CategoryGateway extends CommonDao {
|
|||||||
|
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteCategory($id, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` WHERE `id` = " . intval($id));
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
}
|
}
|
@ -82,6 +82,7 @@ class Link
|
|||||||
$handler = $routeDesc[0];
|
$handler = $routeDesc[0];
|
||||||
if( isset( $routeDesc[2] )) {
|
if( isset( $routeDesc[2] )) {
|
||||||
$middleware = $routeDesc[2];
|
$middleware = $routeDesc[2];
|
||||||
|
$acceptedMethods = $routeDesc[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -189,7 +189,7 @@ Link::all(array(
|
|||||||
// Categories
|
// Categories
|
||||||
'/v1/categories/all' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
|
'/v1/categories/all' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
|
||||||
'/v1/categories' => action(\Controllers\Categories\CategoryController::class, [RequestMethod::POST]),
|
'/v1/categories' => action(\Controllers\Categories\CategoryController::class, [RequestMethod::POST]),
|
||||||
'/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::class),
|
'/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::class, [RequestMethod::GET, RequestMethod::PUT, RequestMethod::DELETE]),
|
||||||
// Tickets
|
// Tickets
|
||||||
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
|
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
|
||||||
// Tickets - Staff
|
// Tickets - Staff
|
||||||
|
Loading…
x
Reference in New Issue
Block a user