From 156fe956f3d91f28edb9280782a602ac60830ebb Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 3 Sep 2024 08:21:37 +0200 Subject: [PATCH] refactor(settings): Return entire folder on creation Signed-off-by: provokateurin --- lib/Controller/FolderController.php | 8 +++++++- src/settings/Api.ts | 4 ++-- src/settings/App.tsx | 12 ++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 2578a458a..8ea5ebe35 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -14,6 +14,7 @@ use OCA\GroupFolders\Service\FoldersFilter; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; use OCP\Files\IRootFolder; use OCP\IGroupManager; @@ -145,10 +146,15 @@ private function getRootFolderStorageId(): ?int { /** * @RequireGroupFolderAdmin * @NoAdminRequired + * @throws OCSNotFoundException */ public function addFolder(string $mountpoint): DataResponse { $id = $this->manager->createFolder(trim($mountpoint)); - return new DataResponse(['id' => $id]); + $folder = $this->manager->getFolder($id, $this->rootFolder->getMountPoint()->getNumericStorageId()); + if ($folder === false) { + throw new OCSNotFoundException(); + } + return new DataResponse($folder); } /** diff --git a/src/settings/Api.ts b/src/settings/Api.ts index 6057569cb..5aeb6f3ae 100644 --- a/src/settings/Api.ts +++ b/src/settings/Api.ts @@ -85,10 +85,10 @@ export class Api { }).then((data) => data.data) } - createFolder(mountPoint: string): Thenable { + createFolder(mountPoint: string): Thenable { return $.post(this.getUrl('folders'), { mountpoint: mountPoint - }, null, 'json').then((data: OCSResult<{ id: number; }>) => data.ocs.data.id) + }, null, 'json').then((data: OCSResult) => data.ocs.data) } deleteFolder(id: number): Thenable { diff --git a/src/settings/App.tsx b/src/settings/App.tsx index 4fa3623b5..dcdcf649e 100644 --- a/src/settings/App.tsx +++ b/src/settings/App.tsx @@ -89,17 +89,9 @@ export class App extends Component<{}, AppState> implements OC.Plugin { + this.api.createFolder(mountPoint).then((folder) => { const folders = this.state.folders - folders.push({ - mount_point: mountPoint, - groups: {}, - quota: -3, - size: 0, - id, - acl: false, - manage: [], - }) + folders.push(folder) this.setState({ folders }) }) }