From ba3d12ba1db50a9eb6be922f8d9242180b67b031 Mon Sep 17 00:00:00 2001 From: zak39 Date: Tue, 15 Oct 2024 14:32:12 +0200 Subject: [PATCH] feat(vue,php): Create an API for attaching a group to a workspace Fixes the issue where "Password confirmation is required" by allowing groups to be attached without needing password confirmation. --- appinfo/routes.php | 5 +++++ lib/Controller/GroupController.php | 25 ++++++++++++++++++++----- lib/Space/SpaceManager.php | 17 ++++++++++++++++- src/App.vue | 1 - src/services/spaceService.js | 24 ++++++++++++++++++++++++ src/store/actions.js | 4 ++-- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index cad3d8fa1..755947410 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -104,6 +104,11 @@ 'url' => '/api/group', 'verb' => 'POST', ], + [ + 'name' => 'group#attachGroupToSpace', + 'url' => '/spaces/{spaceId}/group-attach', + 'verb' => 'POST', + ], [ 'name' => 'group#delete', 'url' => '/api/group/{gid}', diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php index f9493e8fe..1fee10738 100644 --- a/lib/Controller/GroupController.php +++ b/lib/Controller/GroupController.php @@ -34,6 +34,7 @@ use OCA\Workspace\Service\User\UserFormatter; use OCA\Workspace\Service\User\UserWorkspace; use OCA\Workspace\Service\UserService; +use OCA\Workspace\Space\SpaceManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -52,10 +53,11 @@ public function __construct( private GroupsWorkspaceService $groupsWorkspace, private IGroupManager $groupManager, private LoggerInterface $logger, + private SpaceManager $spaceManager, private IUserManager $userManager, private UserFormatter $userFormatter, private UserService $userService, - private UserWorkspace $userWorkspace + private UserWorkspace $userWorkspace, ) { } @@ -67,9 +69,9 @@ public function __construct( * NB: This function could probably be abused by space managers to create arbitrary group. But, do we really care? * * @var array $data [ - * "gid" => 'Space01', - * "displayName" => 'Space01' - * ] + * "gid" => 'Space01', + * "displayName" => 'Space01' + * ] * @var string $spaceId for Middleware * */ @@ -237,7 +239,7 @@ public function addUser(string $spaceId, string $gid, string $user): JSONRespons public function removeUserFromWorkspace( array|string $space, string $gid, - string $user + string $user, ): JSONResponse { if (gettype($space) === 'string') { $space = json_decode($space, true); @@ -369,6 +371,19 @@ public function removeUser( ]); } + /** + * @NoAdminRequired + * @GeneralManagerRequired + */ + public function attachGroupToSpace(int $spaceId, string $gid) { + $workspace = $this->spaceManager->get($spaceId); + $this->spaceManager->attachGroup($workspace['groupfolder_id'], $gid); + + return new JSONResponse([ + 'message' => sprintf('The %s group is attached to the %s workspace (i.e groupfolder)', $gid, $workspace['name']), + ], Http::STATUS_ACCEPTED); + } + /** * @NoAdminRequired * @GeneralManagerRequired diff --git a/lib/Space/SpaceManager.php b/lib/Space/SpaceManager.php index df7a77d96..fda7d4473 100644 --- a/lib/Space/SpaceManager.php +++ b/lib/Space/SpaceManager.php @@ -57,7 +57,7 @@ public function create(string $spacename): array { } if ($this->workspaceCheck->containSpecialChar($spacename)) { - 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 ($this->workspaceCheck->isExist($spacename)) { @@ -122,6 +122,21 @@ public function create(string $spacename): array { ]; } + public function get(int $spaceId): array { + + $space = $this->spaceMapper->find($spaceId)->jsonSerialize(); + $workspace = array_merge( + $this->folderHelper->getFolder($space['groupfolder_id'], $this->rootFolder->getRootFolderStorageId()), + $space + ); + + return $workspace; + } + + public function attachGroup(int $folderId, string $gid): void { + $this->folderHelper->addApplicableGroup($folderId, $gid); + } + /** * @param string $spaceName it's the space name * @return string whithout the blank to start and end of the space name diff --git a/src/App.vue b/src/App.vue index 3a1350e75..20d5fc6e4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,4 +1,3 @@ -