From e2b0a63b0d4b43f9924dbe0aafaac79efa7861b8 Mon Sep 17 00:00:00 2001 From: zak39 Date: Mon, 9 Sep 2024 12:33:49 +0200 Subject: [PATCH 1/2] fix(controller): Check if the group already exist before rendering It's possible for a group not to exist, but still to be attached to a groupfolder. This change allows for this issue. --- lib/Controller/WorkspaceController.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 055e0ef9..781d1ac0 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -196,8 +196,24 @@ public function findAll(): JSONResponse { ) : $workspace; $gids = array_keys($space['groups'] ?? []); - $groups = array_map(fn ($gid) => $this->groupManager->get($gid), $gids); - + + $groups = []; + + foreach ($gids as $gid) { + $group = $this->groupManager->get($gid); + + if (is_null($group)) { + $this->logger->warning( + "Be careful, the $gid group is not exist in the oc_groups table." + . " But, it's present in the oc_group_folders_groups table." + . "It necessary to recreate it with the occ command." + ); + continue; + } + + $groups[] = $group; + } + $space['groups'] = GroupFormatter::formatGroups($groups); $space['users'] = $this->workspaceService->addUsersInfo($space); From cd9faffbc5311002d6d4e747660b3fc479e9856a Mon Sep 17 00:00:00 2001 From: zak39 Date: Mon, 9 Sep 2024 12:40:45 +0200 Subject: [PATCH 2/2] style: Run composer run cs:fix --- lib/Controller/WorkspaceController.php | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 781d1ac0..f92d2946 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -96,8 +96,8 @@ public function createWorkspace(string $spaceName, throw new BadRequestException('spaceName must be provided'); } - if($this->workspaceCheck->containSpecialChar($spaceName)) { - throw new BadRequestException('Your Workspace name must not contain the following characters: ' . implode(" ", str_split(WorkspaceCheckService::CHARACTERS_SPECIAL))); + if ($this->workspaceCheck->containSpecialChar($spaceName)) { + throw new BadRequestException('Your Workspace name must not contain the following characters: ' . implode(' ', str_split(WorkspaceCheckService::CHARACTERS_SPECIAL))); } if ($this->workspaceCheck->isExist($spaceName)) { @@ -197,22 +197,22 @@ public function findAll(): JSONResponse { $gids = array_keys($space['groups'] ?? []); - $groups = []; + $groups = []; - foreach ($gids as $gid) { - $group = $this->groupManager->get($gid); + foreach ($gids as $gid) { + $group = $this->groupManager->get($gid); - if (is_null($group)) { - $this->logger->warning( - "Be careful, the $gid group is not exist in the oc_groups table." - . " But, it's present in the oc_group_folders_groups table." - . "It necessary to recreate it with the occ command." - ); - continue; - } + if (is_null($group)) { + $this->logger->warning( + "Be careful, the $gid group is not exist in the oc_groups table." + . " But, it's present in the oc_group_folders_groups table." + . 'It necessary to recreate it with the occ command.' + ); + continue; + } - $groups[] = $group; - } + $groups[] = $group; + } $space['groups'] = GroupFormatter::formatGroups($groups); $space['users'] = $this->workspaceService->addUsersInfo($space); @@ -320,7 +320,7 @@ public function renameSpace(array|string $workspace, } if ($this->workspaceCheck->containSpecialChar($newSpaceName)) { - throw new BadRequestException('Your Workspace name must not contain the following characters: ' . implode(" ", str_split(WorkspaceCheckService::CHARACTERS_SPECIAL))); + throw new BadRequestException('Your Workspace name must not contain the following characters: ' . implode(' ', str_split(WorkspaceCheckService::CHARACTERS_SPECIAL))); } if ($newSpaceName === false ||