diff --git a/rest/index.php b/rest/index.php index 63619db57a9971e691876dbe436341fbc4d463c5..afbf9d6677bca535ce2cc7514e20815a055afb32 100755 --- a/rest/index.php +++ b/rest/index.php @@ -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'); diff --git a/src/app/group/controllers/GroupController.php b/src/app/group/controllers/GroupController.php index 50ebbf0c636aa598c4870063f304d0c2675502da..d24cd8765fb57e09bf81e5759bb85b8e03bde486 100755 --- a/src/app/group/controllers/GroupController.php +++ b/src/app/group/controllers/GroupController.php @@ -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'])) {