From d3f2d4bd0d34116e36fd6a333c2114fab99cc9c8 Mon Sep 17 00:00:00 2001 From: zak39 Date: Tue, 29 Oct 2024 17:47:32 +0100 Subject: [PATCH 01/16] chore(route): Remove a TODO --- appinfo/routes.php | 1 - 1 file changed, 1 deletion(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 75594741..31a6fae5 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -55,7 +55,6 @@ ], [ 'name' => 'workspace#createWorkspace', - // TODO move this route to /api/spaces 'url' => '/spaces', 'verb' => 'POST' ], From 34967e257fda47fa615239fa056cab26aa0a8e63 Mon Sep 17 00:00:00 2001 From: zak39 Date: Tue, 29 Oct 2024 17:49:06 +0100 Subject: [PATCH 02/16] refactor: Creating a groupfolder on the back-end side --- lib/Controller/WorkspaceController.php | 58 +++++--------------------- src/LeftSidebar.vue | 21 ++-------- src/services/groupfoldersService.js | 2 + src/services/spaceService.js | 3 +- 4 files changed, 18 insertions(+), 66 deletions(-) diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index f92d2946..961809b8 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -41,6 +41,7 @@ use OCA\Workspace\Service\UserService; use OCA\Workspace\Service\Workspace\WorkspaceCheckService; use OCA\Workspace\Service\WorkspaceService; +use OCA\Workspace\Space\SpaceManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -64,6 +65,7 @@ public function __construct( private WorkspaceService $workspaceService, private UserGroup $userGroup, private WorkspaceManagerGroup $workspaceManagerGroup, + private SpaceManager $spaceManager, public $AppName ) { parent::__construct($AppName, $request); @@ -82,56 +84,18 @@ private function deleteBlankSpaceName(string $spaceName): string { * @NoAdminRequired * @GeneralManagerRequired * @param string $spaceName - * @param int $folderId - * @throws BadRequestException - * @throws CreateWorkspaceException - * @throws CreateGroupException */ - public function createWorkspace(string $spaceName, - int $folderId): JSONResponse { - if ($spaceName === false || - $spaceName === null || - $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->isExist($spaceName)) { - throw new WorkspaceNameExistException("The $spaceName space name already exist", Http::STATUS_CONFLICT); - } + public function createWorkspace(string $spaceName): JSONResponse { - $spaceName = $this->deleteBlankSpaceName($spaceName); + $workspace = $this->spaceManager->create($spaceName); - $space = new Space(); - $space->setSpaceName($spaceName); - $space->setGroupfolderId($folderId); - $space->setColorCode('#' . substr(md5(mt_rand()), 0, 6)); // mt_rand() (MT - Mersenne Twister) is taller efficient than rand() function. - $this->spaceMapper->insert($space); - - if (is_null($space)) { - throw new CreateWorkspaceException('Error to create a space.', Http::STATUS_CONFLICT); - } - - // #2 create groups - $newSpaceManagerGroup = $this->workspaceManagerGroup->create($space); - $newSpaceUsersGroup = $this->userGroup->create($space); - - // #3 Returns result - return new JSONResponse([ - 'name' => $space->getSpaceName(), - 'id_space' => $space->getId(), - 'folder_id' => $space->getGroupfolderId(), - 'color' => $space->getColorCode(), - 'groups' => GroupFormatter::formatGroups([ - $newSpaceManagerGroup, - $newSpaceUsersGroup - ]), - 'statuscode' => Http::STATUS_CREATED, - ]); + return new JSONResponse( + array_merge( + $workspace, + [ 'statuscode' => Http::STATUS_CREATED ] + ) + ) + ; } /** diff --git a/src/LeftSidebar.vue b/src/LeftSidebar.vue index e05fd1c5..22e1201c 100644 --- a/src/LeftSidebar.vue +++ b/src/LeftSidebar.vue @@ -56,8 +56,8 @@