From 15b0a1eb52330a7a1b5d2ac91bb09983e0ea5cfe Mon Sep 17 00:00:00 2001 From: zak39 Date: Tue, 21 Jan 2025 16:21:16 +0100 Subject: [PATCH] fix(mapper,service): Find all added groups instead of just one This fix resolves an issue with displaying workspaces, which could trigger an error notification. A user can belong to multiple groups, and this change ensures that all groups are considered. --- lib/Db/GroupFoldersGroupsMapper.php | 4 ++-- lib/Service/Group/ConnectedGroupsService.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Db/GroupFoldersGroupsMapper.php b/lib/Db/GroupFoldersGroupsMapper.php index 5d57bd97..33d69391 100644 --- a/lib/Db/GroupFoldersGroupsMapper.php +++ b/lib/Db/GroupFoldersGroupsMapper.php @@ -93,7 +93,7 @@ public function findAllAddedGroups() : array { return $this->findEntities($query); } - public function findAddedGroup($groupfolderId) : ConnectedGroup|false { + public function findAddedGroups($groupfolderId) : array|false { $qb = $this->db->getQueryBuilder(); $query = $qb ->select([ 'space_id', 'group_id as gid' ]) @@ -122,7 +122,7 @@ public function findAddedGroup($groupfolderId) : ConnectedGroup|false { return false; } - return $this->findEntity($query); + return $this->findEntities($query); } public function isUserConnectedGroup(string $uid, string $gid): mixed { diff --git a/lib/Service/Group/ConnectedGroupsService.php b/lib/Service/Group/ConnectedGroupsService.php index 1cf243d4..0749fd7e 100644 --- a/lib/Service/Group/ConnectedGroupsService.php +++ b/lib/Service/Group/ConnectedGroupsService.php @@ -160,15 +160,21 @@ public function add(IGroup $group, Space $space): bool { public function isUserConnectedGroup(string $uid, int $groupfolderId): bool { - $connectedGroup = $this->mapper->findAddedGroup($groupfolderId); + $connectedGroups = $this->mapper->findAddedGroups($groupfolderId); - if ($connectedGroup === false) { + if ($connectedGroups === false) { return false; } - $group = $this->groupManager->get($connectedGroup->getGid()); $user = $this->userManager->get($uid); + $groups = array_map(fn ($group) => $this->groupManager->get($group->getGid()), $connectedGroups); + + foreach($groups as $group) { + if ($group->inGroup($user)) { + return true; + } + } - return $group->inGroup($user); + return false; } }