From df0a148ed8719cc7e37d82812d5caf8da24a726a Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Thu, 17 Nov 2022 12:52:48 +0100 Subject: [PATCH] [PS 1624]CLI get and delete folder command, fails if using GUID and Session key (#4026) * Resolve get&delete folder cmd on cli using GUID&Sessionkey * Using the getFromState on the edit.command.ts Co-authored-by: dynwee --- apps/cli/src/commands/delete.command.ts | 2 +- apps/cli/src/commands/edit.command.ts | 2 +- apps/cli/src/commands/get.command.ts | 2 +- .../folder/folder.service.abstraction.ts | 4 ++++ libs/common/src/services/folder/folder.service.ts | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/cli/src/commands/delete.command.ts b/apps/cli/src/commands/delete.command.ts index 9a4480df68..5866e2a6fd 100644 --- a/apps/cli/src/commands/delete.command.ts +++ b/apps/cli/src/commands/delete.command.ts @@ -88,7 +88,7 @@ export class DeleteCommand { } private async deleteFolder(id: string) { - const folder = await this.folderService.get(id); + const folder = await this.folderService.getFromState(id); if (folder == null) { return Response.notFound(); } diff --git a/apps/cli/src/commands/edit.command.ts b/apps/cli/src/commands/edit.command.ts index a8ed1b0f28..f486acbe99 100644 --- a/apps/cli/src/commands/edit.command.ts +++ b/apps/cli/src/commands/edit.command.ts @@ -118,7 +118,7 @@ export class EditCommand { } private async editFolder(id: string, req: FolderExport) { - const folder = await this.folderService.get(id); + const folder = await this.folderService.getFromState(id); if (folder == null) { return Response.notFound(); } diff --git a/apps/cli/src/commands/get.command.ts b/apps/cli/src/commands/get.command.ts index d2ca9edbd4..594dc5c183 100644 --- a/apps/cli/src/commands/get.command.ts +++ b/apps/cli/src/commands/get.command.ts @@ -353,7 +353,7 @@ export class GetCommand extends DownloadCommand { private async getFolder(id: string) { let decFolder: FolderView = null; if (Utils.isGuid(id)) { - const folder = await this.folderService.get(id); + const folder = await this.folderService.getFromState(id); if (folder != null) { decFolder = await folder.decrypt(); } diff --git a/libs/common/src/abstractions/folder/folder.service.abstraction.ts b/libs/common/src/abstractions/folder/folder.service.abstraction.ts index f8df1f7db6..44db4a985b 100644 --- a/libs/common/src/abstractions/folder/folder.service.abstraction.ts +++ b/libs/common/src/abstractions/folder/folder.service.abstraction.ts @@ -12,6 +12,10 @@ export abstract class FolderService { clearCache: () => Promise; encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise; get: (id: string) => Promise; + /** + * @deprecated Only use in CLI! + */ + getFromState: (id: string) => Promise; /** * @deprecated Only use in CLI! */ diff --git a/libs/common/src/services/folder/folder.service.ts b/libs/common/src/services/folder/folder.service.ts index 4d8981c4ea..096d89cea9 100644 --- a/libs/common/src/services/folder/folder.service.ts +++ b/libs/common/src/services/folder/folder.service.ts @@ -64,6 +64,20 @@ export class FolderService implements InternalFolderServiceAbstraction { return folders.find((folder) => folder.id === id); } + /** + * @deprecated For the CLI only + * @param id id of the folder + */ + async getFromState(id: string): Promise { + const foldersMap = await this.stateService.getEncryptedFolders(); + const folder = foldersMap[id]; + if (folder == null) { + return null; + } + + return new Folder(folder); + } + /** * @deprecated Only use in CLI! */