diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index cffdeb0acec66c5494f0c5147dc30737ddd73879..142157718f3716aa7d5c03fc86d1ac14ddcefe9d 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -108,6 +108,14 @@ class UserController if ($GLOBALS['id'] == $args['id'] || PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_users'])) { $user = UserController::getUserInformationsById(['id' => $args['id']]); + $user['groups'] = []; + $userGroups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['id']]]); + $groupsIds = array_column($userGroups, 'group_id'); + if ($GLOBALS['id'] != $args['id']) { + $groupsIds = array_values(array_intersect($groupsIds, array_column(UserController::getManageableGroups(['userId' => $GLOBALS['id']]), 'id'))); + } + $groups = GroupModel::get(['select' => ['label', 'id'], 'where' => ['id in (?)'], 'data' => [$groupsIds]]); + $user['groups'] = $groups; } else { $user = UserModel::getById(['select' => ['id', 'firstname', 'lastname', 'email', 'phone', 'substitute'], 'id' => $args['id']]); } @@ -116,24 +124,6 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'User does not exist']); } - $user['groups'] = []; - $userGroups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['id']]]); - $groupsIds = array_column($userGroups, 'group_id'); - - $actuallyAlone = false; - if (empty($groupsIds)) { - $actuallyAlone = true; - } elseif ($GLOBALS['id'] != $args['id']) { - $groupsIds = array_values(array_intersect($groupsIds, array_column(UserController::getManageableGroups(['userId' => $GLOBALS['id']]), 'id'))); - } - - if (!empty($groupsIds)) { - $groups = GroupModel::get(['select' => ['label', 'id'], 'where' => ['id in (?)'], 'data' => [$groupsIds]]); - $user['groups'] = $groups; - } elseif (!$actuallyAlone) { - return $response->withStatus(403)->withJson(['errors' => 'User out of perimeter']); - } - HistoryController::add([ 'code' => 'OK', 'objectType' => 'users',