diff options
author | Joas Schilling <coding@schilljs.com> | 2020-04-27 09:37:53 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-04-27 09:37:53 +0300 |
commit | e24e9ec0a9cf7081eea0f9fd41ac27f29a674c31 (patch) | |
tree | 906e71b0035f4cc735bc4340438a468bc5add007 | |
parent | 6ffde74928651db451a8ca23ba440f16f8512681 (diff) |
Don't loop over all groups to check for subadmins
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/SubAdmin.php | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/private/SubAdmin.php b/lib/private/SubAdmin.php index 9a758ac4423..890bcf67b3b 100644 --- a/lib/private/SubAdmin.php +++ b/lib/private/SubAdmin.php @@ -110,6 +110,25 @@ class SubAdmin extends PublicEmitter implements ISubAdmin { * @return IGroup[] */ public function getSubAdminsGroups(IUser $user): array { + $groupIds = $this->getSubAdminsGroupIds($user); + + $groups = []; + foreach ($groupIds as $groupId) { + $group = $this->groupManager->get($groupId); + if ($group !== null) { + $groups[$group->getGID()] = $group; + } + } + + return $groups; + } + + /** + * Get group ids of a SubAdmin + * @param IUser $user the SubAdmin + * @return string[] + */ + public function getSubAdminsGroupIds(IUser $user): array { $qb = $this->dbConn->getQueryBuilder(); $result = $qb->select('gid') @@ -119,10 +138,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin { $groups = []; while ($row = $result->fetch()) { - $group = $this->groupManager->get($row['gid']); - if (!is_null($group)) { - $groups[$group->getGID()] = $group; - } + $groups[] = $row['gid']; } $result->closeCursor(); @@ -256,13 +272,10 @@ class SubAdmin extends PublicEmitter implements ISubAdmin { return false; } - $accessibleGroups = $this->getSubAdminsGroups($subadmin); - foreach ($accessibleGroups as $accessibleGroup) { - if ($accessibleGroup->inGroup($user)) { - return true; - } - } - return false; + $accessibleGroups = $this->getSubAdminsGroupIds($subadmin); + $userGroups = $this->groupManager->getUserGroupIds($user); + + return !empty(array_intersect($accessibleGroups, $userGroups)); } /** |