@webiny/api-aco 6.5.2-beta.0 → 6.5.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createAcoContext.js +2 -0
- package/createAcoContext.js.map +1 -1
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js +55 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js +38 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.d.ts +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js +9 -5
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/canAccessEntryFolder.d.ts +21 -0
- package/features/cms/decorators/canAccessEntryFolder.js +25 -0
- package/features/cms/decorators/canAccessEntryFolder.js.map +1 -0
- package/features/cms/feature.js +20 -0
- package/features/cms/feature.js.map +1 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js +4 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js.map +1 -1
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +1 -1
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
- package/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js +2 -1
- package/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js.map +1 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js +3 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js +20 -2
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +1 -5
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
- package/features/folder/FolderTypePermissions/FolderTypeAccess.d.ts +11 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js +28 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js.map +1 -0
- package/features/folder/FolderTypePermissions/abstractions.d.ts +23 -0
- package/features/folder/FolderTypePermissions/abstractions.js +6 -0
- package/features/folder/FolderTypePermissions/abstractions.js.map +1 -0
- package/features/folder/FolderTypePermissions/decorators.d.ts +67 -0
- package/features/folder/FolderTypePermissions/decorators.js +128 -0
- package/features/folder/FolderTypePermissions/decorators.js.map +1 -0
- package/features/folder/FolderTypePermissions/feature.d.ts +4 -0
- package/features/folder/FolderTypePermissions/feature.js +18 -0
- package/features/folder/FolderTypePermissions/feature.js.map +1 -0
- package/features/folder/FolderTypePermissions/index.d.ts +2 -0
- package/features/folder/FolderTypePermissions/index.js +2 -0
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +8 -2
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
- package/features/folder/GetFolderHierarchy/abstractions.d.ts +3 -1
- package/features/folder/GetFolderHierarchy/abstractions.js.map +1 -1
- package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +5 -0
- package/features/folder/UpdateFolder/UpdateFolderRepository.js +33 -5
- package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +21 -5
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/shared/validatePermissionsInput.d.ts +7 -0
- package/features/folder/shared/validatePermissionsInput.js +12 -0
- package/features/folder/shared/validatePermissionsInput.js.map +1 -0
- package/filter/filter.so.js +12 -5
- package/filter/filter.so.js.map +1 -1
- package/package.json +21 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { EnsureFolderIsEmpty as Abstraction } from \"~/features/folder/EnsureFolderIsEmpty/abstractions.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { FolderNotAuthorizedError, FolderNotEmptyError } from \"~/domain/folder/errors.js\";\nimport { Result } from \"@webiny/feature/api\";\n\nclass EnsureFolderIsEmptyImpl implements Abstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private listFoldersUseCase: ListFoldersUseCase.Interface,\n private logger: Logger.Interface\n ) {}\n\n async execute(\n type: string,\n id: string,\n hasContentCallback: Abstraction.HasContentCallback\n ): Abstraction.Return {\n const hasFoldersCallback = async () => {\n const result = await this.listFoldersUseCase.execute({\n where: {\n type,\n parentId: id\n },\n limit: 1\n });\n if (result.isFail()) {\n this.logger.error(result.error);\n // Report the folder as non-empty so a failed lookup cannot green-light a delete.\n return true;\n }\n\n const { folders } = result.value;\n\n return folders.length > 0;\n };\n\n const [hasFolders, hasContent] = await Promise.all([\n hasFoldersCallback(),\n hasContentCallback()\n ]);\n\n if (hasFolders || hasContent) {\n return Result.fail(new FolderNotEmptyError());\n }\n\n /* Also check for folders / content the identity cannot see. Security: run this even when\n folder level permissions are not used, because other restrictions (e.g. \"own entries\n only\") also hide content, and the folder must not be deleted from under it. */\n const [hasInvisibleFolders, hasInvisibleContent] =\n await this.identityContext.withoutAuthorization(async () => {\n const [hasFolders, hasContent] = await Promise.all([\n hasFoldersCallback(),\n hasContentCallback()\n ]);\n return [hasFolders, hasContent];\n });\n\n // In case there are invisible folders or content, we'll throw a different error.\n // This is to prevent users from deleting folders that contain content they can't see.\n if (hasInvisibleFolders || hasInvisibleContent) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n\n return Result.ok();\n }\n}\n\nexport const EnsureFolderIsEmpty = Abstraction.createImplementation({\n implementation: EnsureFolderIsEmptyImpl,\n dependencies: [IdentityContext, ListFoldersUseCase, Logger]\n});\n"],"names":["EnsureFolderIsEmptyImpl","identityContext","listFoldersUseCase","logger","type","id","hasContentCallback","hasFoldersCallback","result","folders","hasFolders","hasContent","Promise","Result","FolderNotEmptyError","hasInvisibleFolders","hasInvisibleContent","FolderNotAuthorizedError","EnsureFolderIsEmpty","Abstraction","IdentityContext","ListFoldersUseCase","Logger"],"mappings":";;;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,kBAAgD,EAChDC,MAAwB,CAClC;aAHUF,eAAe,GAAfA;aACAC,kBAAkB,GAAlBA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,QACFC,IAAY,EACZC,EAAU,EACVC,kBAAkD,EAChC;QAClB,MAAMC,qBAAqB;YACvB,MAAMC,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBACjD,OAAO;oBACHJ;oBACA,UAAUC;gBACd;gBACA,OAAO;YACX;YACA,IAAIG,OAAO,MAAM,IAAI;gBACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAACA,OAAO,KAAK;gBAE9B,OAAO;YACX;YAEA,MAAM,EAAEC,OAAO,EAAE,GAAGD,OAAO,KAAK;YAEhC,OAAOC,QAAQ,MAAM,GAAG;QAC5B;QAEA,MAAM,CAACC,YAAYC,WAAW,GAAG,MAAMC,QAAQ,GAAG,CAAC;YAC/CL;YACAD;SACH;QAED,IAAII,cAAcC,YACd,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAM3B,MAAM,CAACC,qBAAqBC,oBAAoB,GAC5C,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC;YAC5C,MAAM,CAACN,YAAYC,WAAW,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBAC/CL;gBACAD;aACH;YACD,OAAO;gBAACI;gBAAYC;aAAW;QACnC;QAIJ,IAAII,uBAAuBC,qBACvB,OAAOH,OAAO,IAAI,CAAC,IAAII;QAG3B,OAAOJ,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMK,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgBnB;IAChB,cAAc;QAACoB;QAAiBC;QAAoBC;KAAO;AAC/D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FolderTypeAccess as Abstraction, FolderTypePermissions } from "./abstractions.js";
|
|
2
|
+
declare class FolderTypeAccessImpl implements Abstraction.Interface {
|
|
3
|
+
private permissions;
|
|
4
|
+
constructor(permissions: FolderTypePermissions.Interface[]);
|
|
5
|
+
canRead(type: string): Promise<boolean>;
|
|
6
|
+
canWrite(type: string): Promise<boolean>;
|
|
7
|
+
}
|
|
8
|
+
export declare const FolderTypeAccess: typeof FolderTypeAccessImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFolderTypeAccess>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FolderTypeAccess, FolderTypePermissions } from "./abstractions.js";
|
|
2
|
+
class FolderTypeAccessImpl {
|
|
3
|
+
constructor(permissions){
|
|
4
|
+
this.permissions = permissions;
|
|
5
|
+
}
|
|
6
|
+
async canRead(type) {
|
|
7
|
+
const handler = this.permissions.find((p)=>p.canHandle(type));
|
|
8
|
+
return handler ? handler.canRead(type) : true;
|
|
9
|
+
}
|
|
10
|
+
async canWrite(type) {
|
|
11
|
+
const handler = this.permissions.find((p)=>p.canHandle(type));
|
|
12
|
+
return handler ? handler.canWrite(type) : true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const FolderTypeAccess_FolderTypeAccess = FolderTypeAccess.createImplementation({
|
|
16
|
+
implementation: FolderTypeAccessImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
[
|
|
19
|
+
FolderTypePermissions,
|
|
20
|
+
{
|
|
21
|
+
multiple: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { FolderTypeAccess_FolderTypeAccess as FolderTypeAccess };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=FolderTypeAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/FolderTypeAccess.js","sources":["../../../../src/features/folder/FolderTypePermissions/FolderTypeAccess.ts"],"sourcesContent":["import { FolderTypeAccess as Abstraction, FolderTypePermissions } from \"./abstractions.js\";\n\nclass FolderTypeAccessImpl implements Abstraction.Interface {\n constructor(private permissions: FolderTypePermissions.Interface[]) {}\n\n async canRead(type: string): Promise<boolean> {\n const handler = this.permissions.find(p => p.canHandle(type));\n return handler ? handler.canRead(type) : true;\n }\n\n async canWrite(type: string): Promise<boolean> {\n const handler = this.permissions.find(p => p.canHandle(type));\n return handler ? handler.canWrite(type) : true;\n }\n}\n\nexport const FolderTypeAccess = Abstraction.createImplementation({\n implementation: FolderTypeAccessImpl,\n dependencies: [[FolderTypePermissions, { multiple: true }]]\n});\n"],"names":["FolderTypeAccessImpl","permissions","type","handler","p","FolderTypeAccess","Abstraction","FolderTypePermissions"],"mappings":";AAEA,MAAMA;IACF,YAAoBC,WAA8C,CAAE;aAAhDA,WAAW,GAAXA;IAAiD;IAErE,MAAM,QAAQC,IAAY,EAAoB;QAC1C,MAAMC,UAAU,IAAI,CAAC,WAAW,CAAC,IAAI,CAACC,CAAAA,IAAKA,EAAE,SAAS,CAACF;QACvD,OAAOC,UAAUA,QAAQ,OAAO,CAACD,QAAQ;IAC7C;IAEA,MAAM,SAASA,IAAY,EAAoB;QAC3C,MAAMC,UAAU,IAAI,CAAC,WAAW,CAAC,IAAI,CAACC,CAAAA,IAAKA,EAAE,SAAS,CAACF;QACvD,OAAOC,UAAUA,QAAQ,QAAQ,CAACD,QAAQ;IAC9C;AACJ;AAEO,MAAMG,oCAAmBC,iBAAAA,oBAAgC,CAAC;IAC7D,gBAAgBN;IAChB,cAAc;QAAC;YAACO;YAAuB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC/D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App permissions for folders of a given type. Each app that uses folders (File Manager,
|
|
3
|
+
* Website Builder, Headless CMS) registers an implementation for its folder types. These checks
|
|
4
|
+
* come on top of folder level permissions. Folder types no app handles are not restricted.
|
|
5
|
+
*/
|
|
6
|
+
export interface IFolderTypePermissions {
|
|
7
|
+
canHandle(type: string): boolean;
|
|
8
|
+
canRead(type: string): Promise<boolean>;
|
|
9
|
+
canWrite(type: string): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
export declare const FolderTypePermissions: import("@webiny/di").Abstraction<IFolderTypePermissions>;
|
|
12
|
+
export declare namespace FolderTypePermissions {
|
|
13
|
+
type Interface = IFolderTypePermissions;
|
|
14
|
+
}
|
|
15
|
+
/** Resolves the implementation for a folder type and runs its checks. */
|
|
16
|
+
export interface IFolderTypeAccess {
|
|
17
|
+
canRead(type: string): Promise<boolean>;
|
|
18
|
+
canWrite(type: string): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
export declare const FolderTypeAccess: import("@webiny/di").Abstraction<IFolderTypeAccess>;
|
|
21
|
+
export declare namespace FolderTypeAccess {
|
|
22
|
+
type Interface = IFolderTypeAccess;
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const FolderTypePermissions = createAbstraction("Aco/FolderTypePermissions");
|
|
3
|
+
const FolderTypeAccess = createAbstraction("Aco/FolderTypeAccess");
|
|
4
|
+
export { FolderTypeAccess, FolderTypePermissions };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/abstractions.js","sources":["../../../../src/features/folder/FolderTypePermissions/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * App permissions for folders of a given type. Each app that uses folders (File Manager,\n * Website Builder, Headless CMS) registers an implementation for its folder types. These checks\n * come on top of folder level permissions. Folder types no app handles are not restricted.\n */\nexport interface IFolderTypePermissions {\n canHandle(type: string): boolean;\n canRead(type: string): Promise<boolean>;\n canWrite(type: string): Promise<boolean>;\n}\n\nexport const FolderTypePermissions = createAbstraction<IFolderTypePermissions>(\n \"Aco/FolderTypePermissions\"\n);\n\nexport namespace FolderTypePermissions {\n export type Interface = IFolderTypePermissions;\n}\n\n/** Resolves the implementation for a folder type and runs its checks. */\nexport interface IFolderTypeAccess {\n canRead(type: string): Promise<boolean>;\n canWrite(type: string): Promise<boolean>;\n}\n\nexport const FolderTypeAccess = createAbstraction<IFolderTypeAccess>(\"Aco/FolderTypeAccess\");\n\nexport namespace FolderTypeAccess {\n export type Interface = IFolderTypeAccess;\n}\n"],"names":["FolderTypePermissions","createAbstraction","FolderTypeAccess"],"mappings":";AAaO,MAAMA,wBAAwBC,kBACjC;AAaG,MAAMC,mBAAmBD,kBAAqC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { FolderNotAuthorizedError } from "../../../domain/folder/errors.js";
|
|
3
|
+
import type { CreateFolderParams, UpdateFolderParams, ListFoldersParams, GetFolderHierarchyParams } from "../../../folder/folder.types.js";
|
|
4
|
+
import { ListFoldersUseCase } from "../ListFolders/abstractions.js";
|
|
5
|
+
import { GetFolderUseCase } from "../GetFolder/abstractions.js";
|
|
6
|
+
import { CreateFolderUseCase } from "../CreateFolder/abstractions.js";
|
|
7
|
+
import { UpdateFolderUseCase } from "../UpdateFolder/abstractions.js";
|
|
8
|
+
import { DeleteFolderUseCase } from "../DeleteFolder/abstractions.js";
|
|
9
|
+
import { GetFolderHierarchyUseCase } from "../GetFolderHierarchy/abstractions.js";
|
|
10
|
+
import { FolderTypeAccess } from "./abstractions.js";
|
|
11
|
+
declare class ListFoldersWithTypePermissionsImpl implements ListFoldersUseCase.Interface {
|
|
12
|
+
private access;
|
|
13
|
+
private decoratee;
|
|
14
|
+
constructor(access: FolderTypeAccess.Interface, decoratee: ListFoldersUseCase.Interface);
|
|
15
|
+
execute(params: ListFoldersParams): ListFoldersUseCase.Return;
|
|
16
|
+
}
|
|
17
|
+
declare class GetFolderHierarchyWithTypePermissionsImpl implements GetFolderHierarchyUseCase.Interface {
|
|
18
|
+
private access;
|
|
19
|
+
private decoratee;
|
|
20
|
+
constructor(access: FolderTypeAccess.Interface, decoratee: GetFolderHierarchyUseCase.Interface);
|
|
21
|
+
execute(params: GetFolderHierarchyParams): GetFolderHierarchyUseCase.Return;
|
|
22
|
+
}
|
|
23
|
+
declare class GetFolderWithTypePermissionsImpl implements GetFolderUseCase.Interface {
|
|
24
|
+
private access;
|
|
25
|
+
private decoratee;
|
|
26
|
+
constructor(access: FolderTypeAccess.Interface, decoratee: GetFolderUseCase.Interface);
|
|
27
|
+
execute(id: string): Promise<Result<import("~/folder/folder.types.js").Folder, FolderNotAuthorizedError | import("~/domain/folder/errors.js").FolderNotFoundError | import("~/domain/folder/errors.js").FolderPersistenceError>>;
|
|
28
|
+
}
|
|
29
|
+
declare class CreateFolderWithTypePermissionsImpl implements CreateFolderUseCase.Interface {
|
|
30
|
+
private access;
|
|
31
|
+
private decoratee;
|
|
32
|
+
constructor(access: FolderTypeAccess.Interface, decoratee: CreateFolderUseCase.Interface);
|
|
33
|
+
execute(params: CreateFolderParams): Promise<Result<import("~/folder/folder.types.js").Folder, FolderNotAuthorizedError | import("~/domain/folder/errors.js").FolderPersistenceError | import("~/domain/folder/errors.js").FolderValidationError>>;
|
|
34
|
+
}
|
|
35
|
+
declare class UpdateFolderWithTypePermissionsImpl implements UpdateFolderUseCase.Interface {
|
|
36
|
+
private access;
|
|
37
|
+
private getFolder;
|
|
38
|
+
private decoratee;
|
|
39
|
+
constructor(access: FolderTypeAccess.Interface, getFolder: GetFolderUseCase.Interface, decoratee: UpdateFolderUseCase.Interface);
|
|
40
|
+
execute(id: string, data: UpdateFolderParams): Promise<Result<import("~/folder/folder.types.js").Folder, import("~/domain/folder/errors.js").FolderCannotMoveToNewParent | FolderNotAuthorizedError | import("~/domain/folder/errors.js").FolderNotFoundError | import("~/domain/folder/errors.js").FolderPersistenceError | import("~/domain/folder/errors.js").FolderValidationError>>;
|
|
41
|
+
}
|
|
42
|
+
declare class DeleteFolderWithTypePermissionsImpl implements DeleteFolderUseCase.Interface {
|
|
43
|
+
private access;
|
|
44
|
+
private getFolder;
|
|
45
|
+
private decoratee;
|
|
46
|
+
constructor(access: FolderTypeAccess.Interface, getFolder: GetFolderUseCase.Interface, decoratee: DeleteFolderUseCase.Interface);
|
|
47
|
+
execute(id: string): Promise<Result<void, FolderNotAuthorizedError | import("~/domain/folder/errors.js").FolderNotEmptyError | import("~/domain/folder/errors.js").FolderNotFoundError | import("~/domain/folder/errors.js").FolderPersistenceError>>;
|
|
48
|
+
}
|
|
49
|
+
export declare const ListFoldersWithTypePermissions: typeof ListFoldersWithTypePermissionsImpl & {
|
|
50
|
+
__abstraction: import("@webiny/di").Abstraction<import("../ListFolders/abstractions.js").IListFoldersUseCase>;
|
|
51
|
+
};
|
|
52
|
+
export declare const GetFolderHierarchyWithTypePermissions: typeof GetFolderHierarchyWithTypePermissionsImpl & {
|
|
53
|
+
__abstraction: import("@webiny/di").Abstraction<import("../GetFolderHierarchy/abstractions.js").IGetFolderHierarchyUseCase>;
|
|
54
|
+
};
|
|
55
|
+
export declare const GetFolderWithTypePermissions: typeof GetFolderWithTypePermissionsImpl & {
|
|
56
|
+
__abstraction: import("@webiny/di").Abstraction<import("../GetFolder/abstractions.js").IGetFolderUseCase>;
|
|
57
|
+
};
|
|
58
|
+
export declare const CreateFolderWithTypePermissions: typeof CreateFolderWithTypePermissionsImpl & {
|
|
59
|
+
__abstraction: import("@webiny/di").Abstraction<import("../CreateFolder/abstractions.js").ICreateFolderUseCase>;
|
|
60
|
+
};
|
|
61
|
+
export declare const UpdateFolderWithTypePermissions: typeof UpdateFolderWithTypePermissionsImpl & {
|
|
62
|
+
__abstraction: import("@webiny/di").Abstraction<import("../UpdateFolder/abstractions.js").IUpdateFolderUseCase>;
|
|
63
|
+
};
|
|
64
|
+
export declare const DeleteFolderWithTypePermissions: typeof DeleteFolderWithTypePermissionsImpl & {
|
|
65
|
+
__abstraction: import("@webiny/di").Abstraction<import("../DeleteFolder/abstractions.js").IDeleteFolderUseCase>;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { FolderNotAuthorizedError } from "../../../domain/folder/errors.js";
|
|
3
|
+
import { ListFoldersUseCase } from "../ListFolders/abstractions.js";
|
|
4
|
+
import { GetFolderUseCase } from "../GetFolder/abstractions.js";
|
|
5
|
+
import { CreateFolderUseCase } from "../CreateFolder/abstractions.js";
|
|
6
|
+
import { UpdateFolderUseCase } from "../UpdateFolder/abstractions.js";
|
|
7
|
+
import { DeleteFolderUseCase } from "../DeleteFolder/abstractions.js";
|
|
8
|
+
import { GetFolderHierarchyUseCase } from "../GetFolderHierarchy/abstractions.js";
|
|
9
|
+
import { FolderTypeAccess } from "./abstractions.js";
|
|
10
|
+
class ListFoldersWithTypePermissionsImpl {
|
|
11
|
+
constructor(access, decoratee){
|
|
12
|
+
this.access = access;
|
|
13
|
+
this.decoratee = decoratee;
|
|
14
|
+
}
|
|
15
|
+
async execute(params) {
|
|
16
|
+
if (!await this.access.canRead(params.where.type)) return Result.ok({
|
|
17
|
+
folders: [],
|
|
18
|
+
meta: {
|
|
19
|
+
cursor: null,
|
|
20
|
+
hasMoreItems: false,
|
|
21
|
+
totalCount: 0
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return this.decoratee.execute(params);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class GetFolderHierarchyWithTypePermissionsImpl {
|
|
28
|
+
constructor(access, decoratee){
|
|
29
|
+
this.access = access;
|
|
30
|
+
this.decoratee = decoratee;
|
|
31
|
+
}
|
|
32
|
+
async execute(params) {
|
|
33
|
+
if (!await this.access.canRead(params.type)) return Result.ok({
|
|
34
|
+
parents: [],
|
|
35
|
+
siblings: []
|
|
36
|
+
});
|
|
37
|
+
return this.decoratee.execute(params);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class GetFolderWithTypePermissionsImpl {
|
|
41
|
+
constructor(access, decoratee){
|
|
42
|
+
this.access = access;
|
|
43
|
+
this.decoratee = decoratee;
|
|
44
|
+
}
|
|
45
|
+
async execute(id) {
|
|
46
|
+
const result = await this.decoratee.execute(id);
|
|
47
|
+
if (result.isFail()) return result;
|
|
48
|
+
if (!await this.access.canRead(result.value.type)) return Result.fail(new FolderNotAuthorizedError());
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class CreateFolderWithTypePermissionsImpl {
|
|
53
|
+
constructor(access, decoratee){
|
|
54
|
+
this.access = access;
|
|
55
|
+
this.decoratee = decoratee;
|
|
56
|
+
}
|
|
57
|
+
async execute(params) {
|
|
58
|
+
if (!await this.access.canWrite(params.type)) return Result.fail(new FolderNotAuthorizedError());
|
|
59
|
+
return this.decoratee.execute(params);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class UpdateFolderWithTypePermissionsImpl {
|
|
63
|
+
constructor(access, getFolder, decoratee){
|
|
64
|
+
this.access = access;
|
|
65
|
+
this.getFolder = getFolder;
|
|
66
|
+
this.decoratee = decoratee;
|
|
67
|
+
}
|
|
68
|
+
async execute(id, data) {
|
|
69
|
+
const folder = await this.getFolder.execute(id);
|
|
70
|
+
if (folder.isFail()) return Result.fail(folder.error);
|
|
71
|
+
if (!await this.access.canWrite(folder.value.type)) return Result.fail(new FolderNotAuthorizedError());
|
|
72
|
+
return this.decoratee.execute(id, data);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class DeleteFolderWithTypePermissionsImpl {
|
|
76
|
+
constructor(access, getFolder, decoratee){
|
|
77
|
+
this.access = access;
|
|
78
|
+
this.getFolder = getFolder;
|
|
79
|
+
this.decoratee = decoratee;
|
|
80
|
+
}
|
|
81
|
+
async execute(id) {
|
|
82
|
+
const folder = await this.getFolder.execute(id);
|
|
83
|
+
if (folder.isFail()) return Result.fail(folder.error);
|
|
84
|
+
if (!await this.access.canWrite(folder.value.type)) return Result.fail(new FolderNotAuthorizedError());
|
|
85
|
+
return this.decoratee.execute(id);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const ListFoldersWithTypePermissions = ListFoldersUseCase.createDecorator({
|
|
89
|
+
decorator: ListFoldersWithTypePermissionsImpl,
|
|
90
|
+
dependencies: [
|
|
91
|
+
FolderTypeAccess
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
const GetFolderHierarchyWithTypePermissions = GetFolderHierarchyUseCase.createDecorator({
|
|
95
|
+
decorator: GetFolderHierarchyWithTypePermissionsImpl,
|
|
96
|
+
dependencies: [
|
|
97
|
+
FolderTypeAccess
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
const GetFolderWithTypePermissions = GetFolderUseCase.createDecorator({
|
|
101
|
+
decorator: GetFolderWithTypePermissionsImpl,
|
|
102
|
+
dependencies: [
|
|
103
|
+
FolderTypeAccess
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
const CreateFolderWithTypePermissions = CreateFolderUseCase.createDecorator({
|
|
107
|
+
decorator: CreateFolderWithTypePermissionsImpl,
|
|
108
|
+
dependencies: [
|
|
109
|
+
FolderTypeAccess
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
const UpdateFolderWithTypePermissions = UpdateFolderUseCase.createDecorator({
|
|
113
|
+
decorator: UpdateFolderWithTypePermissionsImpl,
|
|
114
|
+
dependencies: [
|
|
115
|
+
FolderTypeAccess,
|
|
116
|
+
GetFolderUseCase
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
const DeleteFolderWithTypePermissions = DeleteFolderUseCase.createDecorator({
|
|
120
|
+
decorator: DeleteFolderWithTypePermissionsImpl,
|
|
121
|
+
dependencies: [
|
|
122
|
+
FolderTypeAccess,
|
|
123
|
+
GetFolderUseCase
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
export { CreateFolderWithTypePermissions, DeleteFolderWithTypePermissions, GetFolderHierarchyWithTypePermissions, GetFolderWithTypePermissions, ListFoldersWithTypePermissions, UpdateFolderWithTypePermissions };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/decorators.js","sources":["../../../../src/features/folder/FolderTypePermissions/decorators.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { FolderNotAuthorizedError } from \"~/domain/folder/errors.js\";\nimport type {\n CreateFolderParams,\n UpdateFolderParams,\n ListFoldersParams,\n GetFolderHierarchyParams\n} from \"~/folder/folder.types.js\";\nimport { ListFoldersUseCase } from \"../ListFolders/abstractions.js\";\nimport { GetFolderUseCase } from \"../GetFolder/abstractions.js\";\nimport { CreateFolderUseCase } from \"../CreateFolder/abstractions.js\";\nimport { UpdateFolderUseCase } from \"../UpdateFolder/abstractions.js\";\nimport { DeleteFolderUseCase } from \"../DeleteFolder/abstractions.js\";\nimport { GetFolderHierarchyUseCase } from \"../GetFolderHierarchy/abstractions.js\";\nimport { FolderTypeAccess } from \"./abstractions.js\";\n\nclass ListFoldersWithTypePermissionsImpl implements ListFoldersUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private decoratee: ListFoldersUseCase.Interface\n ) {}\n\n async execute(params: ListFoldersParams): ListFoldersUseCase.Return {\n // No app access: the app's folders are simply not listed.\n if (!(await this.access.canRead(params.where.type))) {\n return Result.ok({\n folders: [],\n meta: { cursor: null, hasMoreItems: false, totalCount: 0 }\n });\n }\n return this.decoratee.execute(params);\n }\n}\n\nclass GetFolderHierarchyWithTypePermissionsImpl implements GetFolderHierarchyUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private decoratee: GetFolderHierarchyUseCase.Interface\n ) {}\n\n async execute(params: GetFolderHierarchyParams): GetFolderHierarchyUseCase.Return {\n // No app access: same as listing, the app's folders are not returned.\n if (!(await this.access.canRead(params.type))) {\n return Result.ok({ parents: [], siblings: [] });\n }\n return this.decoratee.execute(params);\n }\n}\n\nclass GetFolderWithTypePermissionsImpl implements GetFolderUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private decoratee: GetFolderUseCase.Interface\n ) {}\n\n async execute(id: string) {\n const result = await this.decoratee.execute(id);\n if (result.isFail()) {\n return result;\n }\n if (!(await this.access.canRead(result.value.type))) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return result;\n }\n}\n\nclass CreateFolderWithTypePermissionsImpl implements CreateFolderUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private decoratee: CreateFolderUseCase.Interface\n ) {}\n\n async execute(params: CreateFolderParams) {\n if (!(await this.access.canWrite(params.type))) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return this.decoratee.execute(params);\n }\n}\n\nclass UpdateFolderWithTypePermissionsImpl implements UpdateFolderUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private getFolder: GetFolderUseCase.Interface,\n private decoratee: UpdateFolderUseCase.Interface\n ) {}\n\n async execute(id: string, data: UpdateFolderParams) {\n const folder = await this.getFolder.execute(id);\n if (folder.isFail()) {\n return Result.fail(folder.error);\n }\n if (!(await this.access.canWrite(folder.value.type))) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return this.decoratee.execute(id, data);\n }\n}\n\nclass DeleteFolderWithTypePermissionsImpl implements DeleteFolderUseCase.Interface {\n constructor(\n private access: FolderTypeAccess.Interface,\n private getFolder: GetFolderUseCase.Interface,\n private decoratee: DeleteFolderUseCase.Interface\n ) {}\n\n async execute(id: string) {\n const folder = await this.getFolder.execute(id);\n if (folder.isFail()) {\n return Result.fail(folder.error);\n }\n if (!(await this.access.canWrite(folder.value.type))) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return this.decoratee.execute(id);\n }\n}\n\nexport const ListFoldersWithTypePermissions = ListFoldersUseCase.createDecorator({\n decorator: ListFoldersWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess]\n});\n\nexport const GetFolderHierarchyWithTypePermissions = GetFolderHierarchyUseCase.createDecorator({\n decorator: GetFolderHierarchyWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess]\n});\n\nexport const GetFolderWithTypePermissions = GetFolderUseCase.createDecorator({\n decorator: GetFolderWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess]\n});\n\nexport const CreateFolderWithTypePermissions = CreateFolderUseCase.createDecorator({\n decorator: CreateFolderWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess]\n});\n\nexport const UpdateFolderWithTypePermissions = UpdateFolderUseCase.createDecorator({\n decorator: UpdateFolderWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess, GetFolderUseCase]\n});\n\nexport const DeleteFolderWithTypePermissions = DeleteFolderUseCase.createDecorator({\n decorator: DeleteFolderWithTypePermissionsImpl,\n dependencies: [FolderTypeAccess, GetFolderUseCase]\n});\n"],"names":["ListFoldersWithTypePermissionsImpl","access","decoratee","params","Result","GetFolderHierarchyWithTypePermissionsImpl","GetFolderWithTypePermissionsImpl","id","result","FolderNotAuthorizedError","CreateFolderWithTypePermissionsImpl","UpdateFolderWithTypePermissionsImpl","getFolder","data","folder","DeleteFolderWithTypePermissionsImpl","ListFoldersWithTypePermissions","ListFoldersUseCase","FolderTypeAccess","GetFolderHierarchyWithTypePermissions","GetFolderHierarchyUseCase","GetFolderWithTypePermissions","GetFolderUseCase","CreateFolderWithTypePermissions","CreateFolderUseCase","UpdateFolderWithTypePermissions","UpdateFolderUseCase","DeleteFolderWithTypePermissions","DeleteFolderUseCase"],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { FolderTypeAccess } from "./FolderTypeAccess.js";
|
|
3
|
+
import { CreateFolderWithTypePermissions, DeleteFolderWithTypePermissions, GetFolderHierarchyWithTypePermissions, GetFolderWithTypePermissions, ListFoldersWithTypePermissions, UpdateFolderWithTypePermissions } from "./decorators.js";
|
|
4
|
+
const FolderTypePermissionsFeature = createFeature({
|
|
5
|
+
name: "Aco/FolderTypePermissions",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(FolderTypeAccess);
|
|
8
|
+
container.registerDecorator(ListFoldersWithTypePermissions);
|
|
9
|
+
container.registerDecorator(GetFolderWithTypePermissions);
|
|
10
|
+
container.registerDecorator(GetFolderHierarchyWithTypePermissions);
|
|
11
|
+
container.registerDecorator(CreateFolderWithTypePermissions);
|
|
12
|
+
container.registerDecorator(UpdateFolderWithTypePermissions);
|
|
13
|
+
container.registerDecorator(DeleteFolderWithTypePermissions);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export { FolderTypePermissionsFeature };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/feature.js","sources":["../../../../src/features/folder/FolderTypePermissions/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FolderTypeAccess } from \"./FolderTypeAccess.js\";\nimport {\n ListFoldersWithTypePermissions,\n GetFolderWithTypePermissions,\n GetFolderHierarchyWithTypePermissions,\n CreateFolderWithTypePermissions,\n UpdateFolderWithTypePermissions,\n DeleteFolderWithTypePermissions\n} from \"./decorators.js\";\n\nexport const FolderTypePermissionsFeature = createFeature({\n name: \"Aco/FolderTypePermissions\",\n register(container) {\n container.register(FolderTypeAccess);\n container.registerDecorator(ListFoldersWithTypePermissions);\n container.registerDecorator(GetFolderWithTypePermissions);\n container.registerDecorator(GetFolderHierarchyWithTypePermissions);\n container.registerDecorator(CreateFolderWithTypePermissions);\n container.registerDecorator(UpdateFolderWithTypePermissions);\n container.registerDecorator(DeleteFolderWithTypePermissions);\n }\n});\n"],"names":["FolderTypePermissionsFeature","createFeature","container","FolderTypeAccess","ListFoldersWithTypePermissions","GetFolderWithTypePermissions","GetFolderHierarchyWithTypePermissions","CreateFolderWithTypePermissions","UpdateFolderWithTypePermissions","DeleteFolderWithTypePermissions"],"mappings":";;;AAWO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,iBAAiB,CAACE;QAC5BF,UAAU,iBAAiB,CAACG;QAC5BH,UAAU,iBAAiB,CAACI;QAC5BJ,UAAU,iBAAiB,CAACK;QAC5BL,UAAU,iBAAiB,CAACM;QAC5BN,UAAU,iBAAiB,CAACO;IAChC;AACJ"}
|
|
@@ -5,7 +5,7 @@ import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/cont
|
|
|
5
5
|
import { EntryId } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
|
|
6
6
|
import { FolderModel } from "../../../domain/folder/abstractions.js";
|
|
7
7
|
import { EntryToFolderMapper } from "../shared/EntryToFolderMapper.js";
|
|
8
|
-
import { FolderPersistenceError } from "../../../domain/folder/errors.js";
|
|
8
|
+
import { FolderNotFoundError, FolderPersistenceError } from "../../../domain/folder/errors.js";
|
|
9
9
|
import { ROOT_FOLDER } from "../../../constants.js";
|
|
10
10
|
const FIXED_FOLDER_LISTING_LIMIT = 10000;
|
|
11
11
|
class GetFolderHierarchyRepositoryImpl {
|
|
@@ -37,6 +37,7 @@ class GetFolderHierarchyRepositoryImpl {
|
|
|
37
37
|
const folderResult = await this.getEntryById.execute(this.folderModel, entryId.toString());
|
|
38
38
|
if (folderResult.isFail()) return Result.fail(new FolderPersistenceError(folderResult.error));
|
|
39
39
|
const folder = EntryToFolderMapper.toFolder(folderResult.value);
|
|
40
|
+
if (folder.type !== params.type) return Result.fail(new FolderNotFoundError(params.id));
|
|
40
41
|
parents.push(folder);
|
|
41
42
|
const getFolderParentResult = await this.getFolderParent(folder, parents);
|
|
42
43
|
if (getFolderParentResult.isFail()) return Result.fail(getFolderParentResult.error);
|
|
@@ -61,10 +62,15 @@ class GetFolderHierarchyRepositoryImpl {
|
|
|
61
62
|
}
|
|
62
63
|
async getFolderParent(folder, parents) {
|
|
63
64
|
let currentFolder = folder;
|
|
64
|
-
|
|
65
|
+
const visited = new Set([
|
|
66
|
+
folder.id
|
|
67
|
+
]);
|
|
68
|
+
while(currentFolder.parentId && !visited.has(currentFolder.parentId)){
|
|
69
|
+
visited.add(currentFolder.parentId);
|
|
65
70
|
const parentResult = await this.getEntryById.execute(this.folderModel, EntryId.from(currentFolder.parentId).toString());
|
|
66
71
|
if (parentResult.isFail()) return Result.fail(new FolderPersistenceError(parentResult.error));
|
|
67
72
|
const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);
|
|
73
|
+
if (parentFolder.type !== folder.type) break;
|
|
68
74
|
parents.push(parentFolder);
|
|
69
75
|
currentFolder = parentFolder;
|
|
70
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js","sources":["../../../../src/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n GetFolderHierarchyRepository as RepositoryAbstraction,\n type IGetFolderHierarchyRepository\n} from \"./abstractions.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type {\n CmsEntryFolder,\n Folder,\n GetFolderHierarchyParams,\n GetFolderHierarchyResponse\n} from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderPersistenceError } from \"~/domain/folder/errors.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\n\nconst FIXED_FOLDER_LISTING_LIMIT = 10_000;\n\nclass GetFolderHierarchyRepositoryImpl implements IGetFolderHierarchyRepository {\n constructor(\n private getEntryById: GetEntryByIdUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(\n params: GetFolderHierarchyParams\n ): Promise<Result<GetFolderHierarchyResponse, RepositoryAbstraction.Error>> {\n const parents: Folder[] = [];\n const siblings: Folder[] = [];\n\n // Get root folders (siblings at root level)\n const rootFoldersResult = await this.listLatestEntries.execute<CmsEntryFolder>(\n this.folderModel,\n {\n where: {\n values: {\n type: params.type,\n parentId: null\n }\n },\n limit: FIXED_FOLDER_LISTING_LIMIT\n }\n );\n\n if (rootFoldersResult.isFail()) {\n return Result.fail(new FolderPersistenceError(rootFoldersResult.error));\n }\n\n const { entries: rootEntries } = rootFoldersResult.value;\n siblings.push(...rootEntries.map(entry => EntryToFolderMapper.toFolder(entry)));\n\n if (params.id === ROOT_FOLDER) {\n return Result.ok({\n parents,\n siblings\n });\n }\n\n // Get the folder by id\n const entryId = EntryId.from(params.id);\n const folderResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString()\n );\n\n if (folderResult.isFail()) {\n return Result.fail(new FolderPersistenceError(folderResult.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(folderResult.value);\n parents.push(folder);\n\n // Recursively get all parent folders\n const getFolderParentResult = await this.getFolderParent(folder, parents);\n if (getFolderParentResult.isFail()) {\n return Result.fail(getFolderParentResult.error);\n }\n\n // Get all child folders of all parents (these are siblings at different levels)\n const parentIds = parents.map(f => f.id);\n\n const childFoldersResult = await this.listLatestEntries.execute<CmsEntryFolder>(\n this.folderModel,\n {\n where: {\n entryId_not_in: parentIds,\n values: {\n type: folder.type,\n parentId_in: parentIds\n }\n },\n limit: FIXED_FOLDER_LISTING_LIMIT\n }\n );\n\n if (childFoldersResult.isFail()) {\n return Result.fail(new FolderPersistenceError(childFoldersResult.error));\n }\n\n const { entries: childEntries } = childFoldersResult.value;\n siblings.push(...childEntries.map(entry => EntryToFolderMapper.toFolder(entry)));\n\n return Result.ok({\n parents,\n siblings\n });\n }\n\n private async getFolderParent(\n folder: Folder,\n parents: Folder[]\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n let currentFolder = folder;\n\n while (currentFolder.parentId) {\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(currentFolder.parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(new FolderPersistenceError(parentResult.error));\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n parents.push(parentFolder);\n currentFolder = parentFolder;\n }\n\n return Result.ok();\n }\n}\n\nexport const GetFolderHierarchyRepository = RepositoryAbstraction.createImplementation({\n implementation: GetFolderHierarchyRepositoryImpl,\n dependencies: [GetEntryByIdUseCase, ListLatestEntriesUseCase, FolderModel]\n});\n"],"names":["FIXED_FOLDER_LISTING_LIMIT","GetFolderHierarchyRepositoryImpl","getEntryById","listLatestEntries","folderModel","params","parents","siblings","rootFoldersResult","Result","FolderPersistenceError","rootEntries","entry","EntryToFolderMapper","ROOT_FOLDER","entryId","EntryId","folderResult","folder","getFolderParentResult","parentIds","f","childFoldersResult","childEntries","currentFolder","parentResult","parentFolder","GetFolderHierarchyRepository","RepositoryAbstraction","GetEntryByIdUseCase","ListLatestEntriesUseCase","FolderModel"],"mappings":";;;;;;;;;AAmBA,MAAMA,6BAA6B;AAEnC,MAAMC;IACF,YACYC,YAA2C,EAC3CC,iBAAqD,EACrDC,WAAkC,CAC5C;aAHUF,YAAY,GAAZA;aACAC,iBAAiB,GAAjBA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,MAAgC,EACwC;QACxE,MAAMC,UAAoB,EAAE;QAC5B,MAAMC,WAAqB,EAAE;QAG7B,MAAMC,oBAAoB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAC1D,IAAI,CAAC,WAAW,EAChB;YACI,OAAO;gBACH,QAAQ;oBACJ,MAAMH,OAAO,IAAI;oBACjB,UAAU;gBACd;YACJ;YACA,OAAOL;QACX;QAGJ,IAAIQ,kBAAkB,MAAM,IACxB,OAAOC,OAAO,IAAI,CAAC,IAAIC,uBAAuBF,kBAAkB,KAAK;QAGzE,MAAM,EAAE,SAASG,WAAW,EAAE,GAAGH,kBAAkB,KAAK;QACxDD,SAAS,IAAI,IAAII,YAAY,GAAG,CAACC,CAAAA,QAASC,oBAAoB,QAAQ,CAACD;QAEvE,IAAIP,OAAO,EAAE,KAAKS,aACd,OAAOL,OAAO,EAAE,CAAC;YACbH;YACAC;QACJ;QAIJ,MAAMQ,UAAUC,QAAQ,IAAI,CAACX,OAAO,EAAE;QACtC,MAAMY,eAAe,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAChD,IAAI,CAAC,WAAW,EAChBF,QAAQ,QAAQ;QAGpB,IAAIE,aAAa,MAAM,IACnB,OAAOR,OAAO,IAAI,CAAC,IAAIC,uBAAuBO,aAAa,KAAK;QAGpE,MAAMC,SAASL,oBAAoB,QAAQ,CAACI,aAAa,KAAK;
|
|
1
|
+
{"version":3,"file":"features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js","sources":["../../../../src/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n GetFolderHierarchyRepository as RepositoryAbstraction,\n type IGetFolderHierarchyRepository\n} from \"./abstractions.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type {\n CmsEntryFolder,\n Folder,\n GetFolderHierarchyParams,\n GetFolderHierarchyResponse\n} from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderNotFoundError, FolderPersistenceError } from \"~/domain/folder/errors.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\n\nconst FIXED_FOLDER_LISTING_LIMIT = 10_000;\n\nclass GetFolderHierarchyRepositoryImpl implements IGetFolderHierarchyRepository {\n constructor(\n private getEntryById: GetEntryByIdUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(\n params: GetFolderHierarchyParams\n ): Promise<Result<GetFolderHierarchyResponse, RepositoryAbstraction.Error>> {\n const parents: Folder[] = [];\n const siblings: Folder[] = [];\n\n // Get root folders (siblings at root level)\n const rootFoldersResult = await this.listLatestEntries.execute<CmsEntryFolder>(\n this.folderModel,\n {\n where: {\n values: {\n type: params.type,\n parentId: null\n }\n },\n limit: FIXED_FOLDER_LISTING_LIMIT\n }\n );\n\n if (rootFoldersResult.isFail()) {\n return Result.fail(new FolderPersistenceError(rootFoldersResult.error));\n }\n\n const { entries: rootEntries } = rootFoldersResult.value;\n siblings.push(...rootEntries.map(entry => EntryToFolderMapper.toFolder(entry)));\n\n if (params.id === ROOT_FOLDER) {\n return Result.ok({\n parents,\n siblings\n });\n }\n\n // Get the folder by id\n const entryId = EntryId.from(params.id);\n const folderResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString()\n );\n\n if (folderResult.isFail()) {\n return Result.fail(new FolderPersistenceError(folderResult.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(folderResult.value);\n\n // Security: app permissions are checked against `params.type`, so a folder of another\n // type must not be returned (it would expose another app's folder tree).\n if (folder.type !== params.type) {\n return Result.fail(new FolderNotFoundError(params.id));\n }\n\n parents.push(folder);\n\n // Recursively get all parent folders\n const getFolderParentResult = await this.getFolderParent(folder, parents);\n if (getFolderParentResult.isFail()) {\n return Result.fail(getFolderParentResult.error);\n }\n\n // Get all child folders of all parents (these are siblings at different levels)\n const parentIds = parents.map(f => f.id);\n\n const childFoldersResult = await this.listLatestEntries.execute<CmsEntryFolder>(\n this.folderModel,\n {\n where: {\n entryId_not_in: parentIds,\n values: {\n type: folder.type,\n parentId_in: parentIds\n }\n },\n limit: FIXED_FOLDER_LISTING_LIMIT\n }\n );\n\n if (childFoldersResult.isFail()) {\n return Result.fail(new FolderPersistenceError(childFoldersResult.error));\n }\n\n const { entries: childEntries } = childFoldersResult.value;\n siblings.push(...childEntries.map(entry => EntryToFolderMapper.toFolder(entry)));\n\n return Result.ok({\n parents,\n siblings\n });\n }\n\n private async getFolderParent(\n folder: Folder,\n parents: Folder[]\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n let currentFolder = folder;\n // Security: guard against parent cycles in stored data (would otherwise loop forever).\n const visited = new Set<string>([folder.id]);\n\n while (currentFolder.parentId && !visited.has(currentFolder.parentId)) {\n visited.add(currentFolder.parentId);\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(currentFolder.parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(new FolderPersistenceError(parentResult.error));\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n // Never walk into another app's folders.\n if (parentFolder.type !== folder.type) {\n break;\n }\n parents.push(parentFolder);\n currentFolder = parentFolder;\n }\n\n return Result.ok();\n }\n}\n\nexport const GetFolderHierarchyRepository = RepositoryAbstraction.createImplementation({\n implementation: GetFolderHierarchyRepositoryImpl,\n dependencies: [GetEntryByIdUseCase, ListLatestEntriesUseCase, FolderModel]\n});\n"],"names":["FIXED_FOLDER_LISTING_LIMIT","GetFolderHierarchyRepositoryImpl","getEntryById","listLatestEntries","folderModel","params","parents","siblings","rootFoldersResult","Result","FolderPersistenceError","rootEntries","entry","EntryToFolderMapper","ROOT_FOLDER","entryId","EntryId","folderResult","folder","FolderNotFoundError","getFolderParentResult","parentIds","f","childFoldersResult","childEntries","currentFolder","visited","Set","parentResult","parentFolder","GetFolderHierarchyRepository","RepositoryAbstraction","GetEntryByIdUseCase","ListLatestEntriesUseCase","FolderModel"],"mappings":"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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { GetFolderHierarchyParams, GetFolderHierarchyResponse } from "../../../folder/folder.types.js";
|
|
3
|
-
import type { FolderNotAuthorizedError, FolderPersistenceError } from "../../../domain/folder/errors.js";
|
|
3
|
+
import type { FolderNotAuthorizedError, FolderNotFoundError, FolderPersistenceError } from "../../../domain/folder/errors.js";
|
|
4
4
|
/**
|
|
5
5
|
* GetFolderHierarchy repository interface
|
|
6
6
|
*/
|
|
@@ -8,6 +8,7 @@ export interface IGetFolderHierarchyRepository {
|
|
|
8
8
|
execute(params: GetFolderHierarchyParams): Promise<Result<GetFolderHierarchyResponse, RepositoryError>>;
|
|
9
9
|
}
|
|
10
10
|
export interface IGetFolderHierarchyRepositoryErrors {
|
|
11
|
+
notFound: FolderNotFoundError;
|
|
11
12
|
persistence: FolderPersistenceError;
|
|
12
13
|
}
|
|
13
14
|
type RepositoryError = IGetFolderHierarchyRepositoryErrors[keyof IGetFolderHierarchyRepositoryErrors];
|
|
@@ -25,6 +26,7 @@ export interface IGetFolderHierarchyUseCase {
|
|
|
25
26
|
}
|
|
26
27
|
export interface IGetFolderHierarchyUseCaseErrors {
|
|
27
28
|
notAuthorized: FolderNotAuthorizedError;
|
|
29
|
+
notFound: FolderNotFoundError;
|
|
28
30
|
persistence: FolderPersistenceError;
|
|
29
31
|
}
|
|
30
32
|
type UseCaseError = IGetFolderHierarchyUseCaseErrors[keyof IGetFolderHierarchyUseCaseErrors];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/GetFolderHierarchy/abstractions.js","sources":["../../../../src/features/folder/GetFolderHierarchy/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type {\n GetFolderHierarchyParams,\n GetFolderHierarchyResponse\n} from \"~/folder/folder.types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/folder/GetFolderHierarchy/abstractions.js","sources":["../../../../src/features/folder/GetFolderHierarchy/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type {\n GetFolderHierarchyParams,\n GetFolderHierarchyResponse\n} from \"~/folder/folder.types.js\";\nimport type {\n FolderNotAuthorizedError,\n FolderNotFoundError,\n FolderPersistenceError\n} from \"~/domain/folder/errors.js\";\n\n/**\n * GetFolderHierarchy repository interface\n */\nexport interface IGetFolderHierarchyRepository {\n execute(\n params: GetFolderHierarchyParams\n ): Promise<Result<GetFolderHierarchyResponse, RepositoryError>>;\n}\n\nexport interface IGetFolderHierarchyRepositoryErrors {\n notFound: FolderNotFoundError;\n persistence: FolderPersistenceError;\n}\n\ntype RepositoryError =\n IGetFolderHierarchyRepositoryErrors[keyof IGetFolderHierarchyRepositoryErrors];\n\n/** Fetch folder hierarchy from storage. */\nexport const GetFolderHierarchyRepository = createAbstraction<IGetFolderHierarchyRepository>(\n \"GetFolderHierarchyRepository\"\n);\n\nexport namespace GetFolderHierarchyRepository {\n export type Interface = IGetFolderHierarchyRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * GetFolderHierarchy use case interface\n */\nexport interface IGetFolderHierarchyUseCase {\n execute(\n params: GetFolderHierarchyParams\n ): Promise<Result<GetFolderHierarchyResponse, UseCaseError>>;\n}\n\nexport interface IGetFolderHierarchyUseCaseErrors {\n notAuthorized: FolderNotAuthorizedError;\n notFound: FolderNotFoundError;\n persistence: FolderPersistenceError;\n}\n\ntype UseCaseError = IGetFolderHierarchyUseCaseErrors[keyof IGetFolderHierarchyUseCaseErrors];\n\n/** Retrieve the full folder hierarchy. */\nexport const GetFolderHierarchyUseCase = createAbstraction<IGetFolderHierarchyUseCase>(\n \"GetFolderHierarchyUseCase\"\n);\n\nexport namespace GetFolderHierarchyUseCase {\n export type Interface = IGetFolderHierarchyUseCase;\n export type Return = Promise<Result<GetFolderHierarchyResponse, UseCaseError>>;\n export type Error = UseCaseError;\n}\n"],"names":["GetFolderHierarchyRepository","createAbstraction","GetFolderHierarchyUseCase"],"mappings":";AA8BO,MAAMA,+BAA+BC,kBACxC;AA0BG,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -12,6 +12,11 @@ declare class UpdateFolderRepositoryImpl implements IUpdateFolderRepository {
|
|
|
12
12
|
private folderModel;
|
|
13
13
|
constructor(updateEntry: UpdateEntryUseCase.Interface, getEntryById: GetEntryByIdUseCase.Interface, listLatestEntries: ListLatestEntriesUseCase.Interface, folderModel: FolderModel.Interface);
|
|
14
14
|
execute(id: string, data: UpdateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>>;
|
|
15
|
+
/**
|
|
16
|
+
* Security: the new parent must be a folder of the same type, and must not be the folder
|
|
17
|
+
* itself or one of its descendants (that would create a cycle in the tree).
|
|
18
|
+
*/
|
|
19
|
+
private validateNewParent;
|
|
15
20
|
private checkExistingFolder;
|
|
16
21
|
private createFolderPath;
|
|
17
22
|
}
|
|
@@ -20,21 +20,30 @@ class UpdateFolderRepositoryImpl {
|
|
|
20
20
|
const originalResult = await this.getEntryById.execute(this.folderModel, entryId.toString());
|
|
21
21
|
if (originalResult.isFail()) return Result.fail(new FolderPersistenceError(originalResult.error));
|
|
22
22
|
const original = EntryToFolderMapper.toFolder(originalResult.value);
|
|
23
|
+
const input = {
|
|
24
|
+
...data
|
|
25
|
+
};
|
|
26
|
+
delete input.type;
|
|
27
|
+
delete input.path;
|
|
28
|
+
if (input.parentId && input.parentId !== original.parentId) {
|
|
29
|
+
const parentResult = await this.validateNewParent(original, input.parentId);
|
|
30
|
+
if (parentResult.isFail()) return Result.fail(parentResult.error);
|
|
31
|
+
}
|
|
23
32
|
const checkResult = await this.checkExistingFolder({
|
|
24
33
|
id,
|
|
25
34
|
type: original.type,
|
|
26
|
-
slug:
|
|
27
|
-
parentId: void 0 !==
|
|
35
|
+
slug: input.slug || original.slug,
|
|
36
|
+
parentId: void 0 !== input.parentId ? input.parentId : original.parentId
|
|
28
37
|
});
|
|
29
38
|
if (checkResult.isFail()) return Result.fail(checkResult.error);
|
|
30
39
|
const pathResult = await this.createFolderPath({
|
|
31
|
-
slug:
|
|
32
|
-
parentId: void 0 !==
|
|
40
|
+
slug: input.slug || original.slug,
|
|
41
|
+
parentId: void 0 !== input.parentId ? input.parentId : original.parentId
|
|
33
42
|
});
|
|
34
43
|
if (pathResult.isFail()) return Result.fail(pathResult.error);
|
|
35
44
|
const result = await this.updateEntry.execute(this.folderModel, entryId.toString(), {
|
|
36
45
|
values: {
|
|
37
|
-
...
|
|
46
|
+
...input,
|
|
38
47
|
path: pathResult.value
|
|
39
48
|
}
|
|
40
49
|
});
|
|
@@ -42,6 +51,25 @@ class UpdateFolderRepositoryImpl {
|
|
|
42
51
|
const updatedFolder = EntryToFolderMapper.toFolder(result.value);
|
|
43
52
|
return Result.ok(updatedFolder);
|
|
44
53
|
}
|
|
54
|
+
async validateNewParent(folder, parentId) {
|
|
55
|
+
if (parentId === folder.id) return Result.fail(new FolderValidationError("A folder cannot be its own parent."));
|
|
56
|
+
const parentResult = await this.getEntryById.execute(this.folderModel, EntryId.from(parentId).toString());
|
|
57
|
+
if (parentResult.isFail()) return Result.fail(new FolderValidationError("Parent folder not found."));
|
|
58
|
+
const parent = EntryToFolderMapper.toFolder(parentResult.value);
|
|
59
|
+
if (parent.type !== folder.type) return Result.fail(new FolderValidationError("Parent folder must be of the same type as the folder."));
|
|
60
|
+
const visited = new Set([
|
|
61
|
+
parent.id
|
|
62
|
+
]);
|
|
63
|
+
let ancestorId = parent.parentId;
|
|
64
|
+
while(ancestorId && !visited.has(ancestorId)){
|
|
65
|
+
if (ancestorId === folder.id) return Result.fail(new FolderValidationError("A folder cannot be moved into one of its own subfolders."));
|
|
66
|
+
visited.add(ancestorId);
|
|
67
|
+
const ancestorResult = await this.getEntryById.execute(this.folderModel, EntryId.from(ancestorId).toString());
|
|
68
|
+
if (ancestorResult.isFail()) break;
|
|
69
|
+
ancestorId = ancestorResult.value.values.parentId ?? null;
|
|
70
|
+
}
|
|
71
|
+
return Result.ok();
|
|
72
|
+
}
|
|
45
73
|
async checkExistingFolder(params) {
|
|
46
74
|
const { id, type, slug, parentId } = params;
|
|
47
75
|
const result = await this.listLatestEntries.execute(this.folderModel, {
|