diff options
author | Baptiste Fotia <fotia.baptiste@hotmail.com> | 2022-07-07 18:08:59 +0300 |
---|---|---|
committer | Baptiste Fotia <fotia.baptiste@hotmail.com> | 2022-09-19 17:18:23 +0300 |
commit | 8988beda395f5e05fc5dd1b5f41a8545e76b5c68 (patch) | |
tree | ce526e50f6fdeac72b0b89c4930d15e96984ece1 /lib/Service/DelegationService.php | |
parent | d6158b0a841e06ac38621504a3c34aec2aaa627b (diff) |
feat(PHP, TS) Apply the the code allow-admin-delegation-stable21 branch for stable23
I transposed the code from the allow-admin-delegation-stable21 branch to allow-admin-delegation-stable23
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 | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Service/DelegationService.php b/lib/Service/DelegationService.php new file mode 100644 index 00000000..36dbad86 --- /dev/null +++ b/lib/Service/DelegationService.php @@ -0,0 +1,70 @@ +<?php + +/** + * @author Cyrille Bollu <cyr.debian@bollu.be> for Arawa (https://arawa.fr) + * + * GroupFolders + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\GroupFolders\Service; + +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IUserSession; + +class DelegationService { + + /** @var IConfig */ + private $config; + + /** @var IGroupManager */ + private $groupManager; + + /** @var IUserSession */ + private $userSession; + + public function __construct(IConfig $config, + IGroupManager $groupManager, + IUserSession $userSession) { + $this->config = $config; + $this->groupManager = $groupManager; + $this->userSession = $userSession; + } + + /** + * Return true if user is an admin, or 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)) { + return true; + } + $allowedGroups = json_decode($this->config->getAppValue('groupfolders', 'delegated-admins', '[]')); + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); + foreach($userGroups as $userGroup) { + if (in_array($userGroup->getGID(), $allowedGroups)) { + return true; + } + } + return false; + + } + +} + |