Categories can be deleted, fixed request methods

master
Mike Koch 7 years ago
parent dd690decb2
commit 9582689f2a

@ -117,4 +117,13 @@ class CategoryHandler {
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() {
global $hesk_settings, $applicationContext;
global $hesk_settings, $userContext, $applicationContext;
$data = JsonRetriever::getJsonData();
@ -43,9 +43,9 @@ class CategoryController {
/* @var $categoryHandler CategoryHandler */
$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) {
global $hesk_settings, $applicationContext;
global $hesk_settings, $userContext, $applicationContext;
$data = JsonRetriever::getJsonData();
@ -81,12 +81,19 @@ class CategoryController {
/* @var $categoryHandler CategoryHandler */
$categoryHandler = $applicationContext->get[CategoryHandler::class];
$category = $categoryHandler->editCategory($category, $hesk_settings);
$category = $categoryHandler->editCategory($category, $userContext, $hesk_settings);
return output($category);
}
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();
}
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];
if( isset( $routeDesc[2] )) {
$middleware = $routeDesc[2];
$acceptedMethods = $routeDesc[3];
}
}
else

@ -189,7 +189,7 @@ Link::all(array(
// Categories
'/v1/categories/all' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
'/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
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
// Tickets - Staff

Loading…
Cancel
Save