diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-05-21 10:53:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-21 10:53:45 +0300 |
commit | cac844d915d6130587fb891726b30016ba4ebb35 (patch) | |
tree | 631ea97196d2c63d563c63a2e16a4f92589a5a1b /lib | |
parent | bd0a1b6e7d19d5f82b689bf7f04411290c552ec2 (diff) | |
parent | aa83b0b22d26e2d16b7798d3df09f5caf19df1ae (diff) |
Merge pull request #20814 from nextcloud/group-id-only
dont get the group details if we only ask for the id
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Group/Manager.php | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 73c07a6197f..6056bcdb3e3 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -77,7 +77,7 @@ class Manager extends PublicEmitter implements IGroupManager { /** @var \OC\Group\Group[] */ private $cachedGroups = []; - /** @var \OC\Group\Group[] */ + /** @var (string[])[] */ private $cachedUserGroups = []; /** @var \OC\SubAdmin */ @@ -276,25 +276,18 @@ class Manager extends PublicEmitter implements IGroupManager { * @return \OC\Group\Group[] */ public function getUserIdGroups($uid) { - if (isset($this->cachedUserGroups[$uid])) { - return $this->cachedUserGroups[$uid]; - } $groups = []; - foreach ($this->backends as $backend) { - $groupIds = $backend->getUserGroups($uid); - if (is_array($groupIds)) { - foreach ($groupIds as $groupId) { - $aGroup = $this->get($groupId); - if ($aGroup instanceof IGroup) { - $groups[$groupId] = $aGroup; - } else { - $this->logger->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', ['app' => 'core']); - } - } + + foreach ($this->getUserIdGroupIds($uid) as $groupId) { + $aGroup = $this->get($groupId); + if ($aGroup instanceof IGroup) { + $groups[$groupId] = $aGroup; + } else { + $this->logger->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', ['app' => 'core']); } } - $this->cachedUserGroups[$uid] = $groups; - return $this->cachedUserGroups[$uid]; + + return $groups; } /** @@ -320,7 +313,7 @@ class Manager extends PublicEmitter implements IGroupManager { * @return bool if in group */ public function isInGroup($userId, $group) { - return array_key_exists($group, $this->getUserIdGroups($userId)); + return array_search($group, $this->getUserIdGroupIds($userId)) !== false; } /** @@ -330,9 +323,25 @@ class Manager extends PublicEmitter implements IGroupManager { * @return array with group ids */ public function getUserGroupIds(IUser $user) { - return array_map(function ($value) { - return (string)$value; - }, array_keys($this->getUserGroups($user))); + return $this->getUserIdGroupIds($user->getUID()); + } + + /** + * @param string $uid the user id + * @return GroupInterface[] + */ + private function getUserIdGroupIds($uid) { + if (!isset($this->cachedUserGroups[$uid])) { + $groups = []; + foreach ($this->backends as $backend) { + if ($groupIds = $backend->getUserGroups($uid)) { + $groups = array_merge($groups, $groupIds); + } + } + $this->cachedUserGroups[$uid] = $groups; + } + + return $this->cachedUserGroups[$uid]; } /** |