Skip to content

Commit

Permalink
fix(mapper,service): Find all added groups instead of just one
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zak39 committed Jan 21, 2025
1 parent 2a9e054 commit 15b0a1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Db/GroupFoldersGroupsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ])
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions lib/Service/Group/ConnectedGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 15b0a1e

Please sign in to comment.