From 006dfcdd49371a75dc5b472df0fdf3b3affa6e3b Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Mon, 4 Nov 2019 17:48:55 +0100 Subject: [PATCH] FEAT #12003 TIME 0:20 added privileges in currentUser profile --- .../group/controllers/ServiceController.php | 25 +++++++++++++++++++ src/app/user/controllers/UserController.php | 1 + 2 files changed, 26 insertions(+) diff --git a/src/app/group/controllers/ServiceController.php b/src/app/group/controllers/ServiceController.php index d8a9e6914b8..9035bd685e8 100755 --- a/src/app/group/controllers/ServiceController.php +++ b/src/app/group/controllers/ServiceController.php @@ -189,4 +189,29 @@ class ServiceController return !empty($aServices); } + + public static function getPrivilegesByUser(array $args) { + ValidatorModel::notEmpty($args, ['userId']); + ValidatorModel::intVal($args, ['userId']); + + $user = UserModel::getById([ + 'select' => ['user_id'], + 'id' => $args['userId'] + ]); + if ($user['user_id'] == 'superadmin') { + $allPrivileges = array_merge( + ServiceController::PRIVILEGE_ADMIN_SUPERVISION, + ServiceController::PRIVILEGE_ADMIN_PRODUCTION, + ServiceController::PRIVILEGE_ADMIN_CLASSIFYING, + ServiceController::PRIVILEGE_ADMIN_ORGANIZATION, + ServiceController::PRIVILEGE_MENU); + + return $allPrivileges; + } + + $rawPrivilegesStoredInDB = ServiceModel::getByUser(['id' => $args['userId']]); + $privilegesStoredInDB = array_column($rawPrivilegesStoredInDB, 'service_id'); + + return $privilegesStoredInDB; + } } diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 70e5f1aeefd..d572438528d 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -455,6 +455,7 @@ class UserController $user['regroupedBaskets'] = BasketModel::getRegroupedBasketsByUserId(['userId' => $user['user_id']]); $user['passwordRules'] = PasswordModel::getEnabledRules(); $user['canModifyPassword'] = true; + $user['privileges'] = ServiceController::getPrivilegesByUser(['userId' => $user['id']]); $loggingMethod = CoreConfigModel::getLoggingMethod(); if (in_array($loggingMethod['id'], self::ALTERNATIVES_CONNECTIONS_METHODS)) { -- GitLab