diff options
author | Baptiste Fotia <fotia.baptiste@hotmail.com> | 2022-07-08 18:36:53 +0300 |
---|---|---|
committer | Baptiste Fotia <fotia.baptiste@hotmail.com> | 2022-09-19 17:18:23 +0300 |
commit | cf33553d434e4acd9626a285979b83056057ebe4 (patch) | |
tree | bc840910f11b3dcd7a679d33f655ef49edfc0ca3 /lib/Service/DelegationService.php | |
parent | 53af68b5ae995f4a1ae4887e480b6ee6673fc645 (diff) |
feat(PHP): Explode the isAdmin function
I exloded the isAdmin function in 2 functions : isAdmin() to check if an user is admin or admin from 'delegated-admins' of appconfig
And isSubAdmin() function to check if an user is in the group from delegated-sub-admins of appconfig
Signed-off-by: Baptiste Fotia <fotia.baptiste@arawa.fr>
Signed-off-by: Baptiste Fotia <fotia.baptiste@hotmail.com>
Diffstat (limited to 'lib/Service/DelegationService.php')
-rw-r--r-- | lib/Service/DelegationService.php | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/Service/DelegationService.php b/lib/Service/DelegationService.php index 36dbad86..568b2bb9 100644 --- a/lib/Service/DelegationService.php +++ b/lib/Service/DelegationService.php @@ -45,14 +45,13 @@ class DelegationService { } /** - * Return true if user is an admin, or a member of a group that + * Return true if user is a member of a group that * has been granted admin rights on groupfolders * * @return bool */ public function isAdmin() { - $userId = $this->userSession->getUser()->getUID(); - if ($this->groupManager->isAdmin($userId)) { + if ($this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { return true; } $allowedGroups = json_decode($this->config->getAppValue('groupfolders', 'delegated-admins', '[]')); @@ -63,7 +62,29 @@ class DelegationService { } } return false; + } + + /** + * Return true if user is an admin. + * @return bool + */ + public function isSubAdmin() { + $allowedGroups = json_decode($this->config->getAppValue('groupfolders', 'delegated-sub-admins', '[]')); + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); + foreach($userGroups as $userGroup) { + if (in_array($userGroup->getGID(), $allowedGroups)) { + return true; + } + } + return false; + } + /** + * Return true if user is admin or subadmin. + * @return bool + */ + public function isAdminOrSubAdmin() { + return $this->isAdmin() || $this->isSubAdmin(); } } |