Skip to content
Snippets Groups Projects
Commit 5c7b5fab authored by Florian Azizian's avatar Florian Azizian
Browse files

FIX #17109 TIME 1 change privilege control for user route

parent 8e7720d3
No related branches found
No related tags found
No related merge requests found
...@@ -79,26 +79,28 @@ class UserController ...@@ -79,26 +79,28 @@ class UserController
public function getById(Request $request, Response $response, array $args) public function getById(Request $request, Response $response, array $args)
{ {
if ($GLOBALS['id'] != $args['id'] && !PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) {
return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']);
}
if (!Validator::intVal()->notEmpty()->validate($args['id'])) { if (!Validator::intVal()->notEmpty()->validate($args['id'])) {
return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']);
} }
$user = UserController::getUserInformationsById(['id' => $args['id']]); if ($GLOBALS['id'] == $args['id'] || PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) {
$user = UserController::getUserInformationsById(['id' => $args['id']]);
} else {
$user = UserModel::getById(['select' => ['id', 'firstname', 'lastname', 'email', 'phone'], 'id' => $args['id']]);
}
if (empty($user)) { if (empty($user)) {
return $response->withStatus(400)->withJson(['errors' => 'User does not exist']); return $response->withStatus(400)->withJson(['errors' => 'User does not exist']);
} }
$user['groups'] = []; if ($GLOBALS['id'] == $args['id'] || PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) {
$user['groups'] = [];
$userGroups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['id']]]); $userGroups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['id']]]);
$groupsIds = array_column($userGroups, 'group_id'); $groupsIds = array_column($userGroups, 'group_id');
if (!empty($groupsIds)) { if (!empty($groupsIds)) {
$groups = GroupModel::get(['select' => ['label'], 'where' => ['id in (?)'], 'data' => [$groupsIds]]); $groups = GroupModel::get(['select' => ['label'], 'where' => ['id in (?)'], 'data' => [$groupsIds]]);
$user['groups'] = $groups; $user['groups'] = $groups;
}
} }
HistoryController::add([ HistoryController::add([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment