diff --git a/lib/Helper/UserHelper.php b/lib/Helper/UserHelper.php index 3c84cff274..1f4a37f5c8 100644 --- a/lib/Helper/UserHelper.php +++ b/lib/Helper/UserHelper.php @@ -8,7 +8,6 @@ namespace OCA\Tables\Helper; use OCA\Tables\Errors\InternalError; -use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; @@ -48,30 +47,16 @@ private function getUser(string $userId): IUser { throw new InternalError('User not found for ' . $userId); } - /** - * @param string $userId - * @return IGroup[] - * @throws InternalError - */ - public function getGroupsForUser(string $userId): array { - $user = $this->getUser($userId); - return $this->groupManager->getUserGroups($user); - } - /** * @param string $userId * @return array|null */ public function getGroupIdsForUser(string $userId): ?array { try { - $userGroups = $this->getGroupsForUser($userId); + $user = $this->getUser($userId); + return $this->groupManager->getUserGroupIds($user); } catch (InternalError $e) { return null; } - - $groupArray = array_map(function (IGroup $group) { - return $group->getGID(); - }, $userGroups); - return $groupArray; } } diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index 74f3169692..69c8cea967 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -438,9 +438,9 @@ public function canReadShare(Share $share, ?string $userId = null): bool { if ($share->getReceiverType() === 'group') { try { - $userGroups = $this->userHelper->getGroupsForUser($userId); - foreach ($userGroups as $userGroup) { - if ($userGroup->getGID() === $share->getReceiver()) { + $userGroups = $this->userHelper->getGroupIdsForUser($userId); + foreach ($userGroups as $userGroupId) { + if ($userGroupId === $share->getReceiver()) { return true; } } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 72f8a09524..f7d08bb5f8 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -39,7 +39,6 @@ use OCP\AppFramework\Db\TTransactional; use OCP\DB\Exception; use OCP\IDBConnection; -use OCP\IGroup; use OCP\IUserManager; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; @@ -234,8 +233,7 @@ private function findElementsSharedWithMe(string $elementType = 'table', ?string try { $shares['user'] = $this->mapper->findAllSharesFor($elementType, [$userId], $userId); - $userGroups = $this->userHelper->getGroupsForUser($userId); - $userGroupIds = array_map(static fn (IGroup $group) => $group->getGid(), $userGroups); + $userGroupIds = $this->userHelper->getGroupIdsForUser($userId); $shares['groups'] = $this->mapper->findAllSharesFor($elementType, $userGroupIds, $userId, ShareReceiverType::GROUP); $userCircles = $this->circleHelper->getUserCircles($userId);