Commit 589d2ed6 authored by Quentin Ribac's avatar Quentin Ribac
Browse files

FEAT #17436 TIME 0:15 GET/groups/{id}/privilege/{privilegeId}

parent 3218479c
......@@ -112,6 +112,7 @@ $app->get('/groups/{id}', \Group\controllers\GroupController::class . ':getById'
$app->delete('/groups/{id}', \Group\controllers\GroupController::class . ':delete');
$app->put('/groups/{id}', \Group\controllers\GroupController::class . ':update');
$app->put('/groups/{id}/privilege/{privilegeId}', \Group\controllers\GroupController::class . ':updateGroupPrivilege');
$app->get('/groups/{id}/privilege/{privilegeId}', \Group\controllers\GroupController::class . ':getGroupPrivilege');
$app->put('/groups/{id}/users', \Group\controllers\GroupController::class . ':addUser');
$app->delete('/groups/{id}/users/{userId}', \Group\controllers\GroupController::class . ':removeUser');
......
......@@ -172,6 +172,31 @@ class GroupController
return $response->withStatus(204);
}
public function getGroupPrivilege(Request $request, Response $response, array $args)
{
if (!UserGroupModel::hasGroup(['userId' => $GLOBALS['id'], 'groupId' => $args['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Current user out of target group']);
}
$privilege = GroupPrivilegeModel::getPrivileges([
'where' => ['group_id = ?', 'privilege = ?'],
'data' => [$args['id'], $args['privilegeId']],
'limit' => 1
]);
if (empty($privilege[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Privilege not enabled for this group']);
}
$privilege = [
'groupId' => $privilege[0]['group_id'],
'privilege' => $privilege[0]['privilege'],
'parameters' => json_decode($privilege[0]['parameters'], true)
];
return $response->withJson($privilege);
}
public function updateGroupPrivilege(Request $request, Response $response, array $aArgs)
{
if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_groups'])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment