@webiny/api-aco 6.4.5 → 6.6.0-alpha.0
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/AcoFeature.d.ts +5 -0
- package/AcoFeature.js +122 -0
- package/AcoFeature.js.map +1 -0
- package/AcoInitializer.d.ts +25 -0
- package/AcoInitializer.js +79 -0
- package/AcoInitializer.js.map +1 -0
- package/createAcoGraphQL.d.ts +7 -4
- package/createAcoGraphQL.js +56 -96
- package/createAcoGraphQL.js.map +1 -1
- package/exports/api/aco/folder.d.ts +1 -1
- package/exports/api/aco/folder.js +1 -1
- package/features/cms/decorators/ListDeletedEntriesWithFlpDecorator.js +1 -0
- package/features/cms/decorators/ListDeletedEntriesWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/ListEntriesWithFlpDecorator.js +1 -0
- package/features/cms/decorators/ListEntriesWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/ListLatestEntriesWithFlpDecorator.js +1 -0
- package/features/cms/decorators/ListLatestEntriesWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/ListPublishedEntriesWithFlpDecorator.js +1 -0
- package/features/cms/decorators/ListPublishedEntriesWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/MoveEntryWithFlpDecorator.d.ts +1 -1
- package/features/flp/CreateFlp/CreateFlpUseCase.d.ts +3 -3
- package/features/flp/CreateFlp/CreateFlpUseCase.js +4 -4
- package/features/flp/CreateFlp/CreateFlpUseCase.js.map +1 -1
- package/features/flp/CreateFlp/feature.d.ts +1 -6
- package/features/flp/CreateFlp/feature.js +3 -2
- package/features/flp/CreateFlp/feature.js.map +1 -1
- package/features/flp/DeleteFlp/DeleteFlpUseCase.d.ts +3 -3
- package/features/flp/DeleteFlp/DeleteFlpUseCase.js +3 -3
- package/features/flp/DeleteFlp/DeleteFlpUseCase.js.map +1 -1
- package/features/flp/DeleteFlp/feature.d.ts +1 -6
- package/features/flp/DeleteFlp/feature.js +3 -2
- package/features/flp/DeleteFlp/feature.js.map +1 -1
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.d.ts +25 -0
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js +48 -0
- package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js.map +1 -0
- package/features/flp/FolderLevelPermissions/index.d.ts +1 -0
- package/features/flp/FolderLevelPermissions/index.js +1 -0
- package/features/flp/GetFlp/feature.d.ts +1 -1
- package/features/flp/GetFlp/feature.js +3 -2
- package/features/flp/GetFlp/feature.js.map +1 -1
- package/features/flp/ListFlps/feature.d.ts +1 -1
- package/features/flp/ListFlps/feature.js +3 -2
- package/features/flp/ListFlps/feature.js.map +1 -1
- package/features/flp/UpdateFlp/UpdateFlpUseCase.d.ts +11 -3
- package/features/flp/UpdateFlp/UpdateFlpUseCase.js +14 -13
- package/features/flp/UpdateFlp/UpdateFlpUseCase.js.map +1 -1
- package/features/flp/UpdateFlp/feature.d.ts +1 -6
- package/features/flp/UpdateFlp/feature.js +7 -2
- package/features/flp/UpdateFlp/feature.js.map +1 -1
- package/features/folder/DeleteFolder/decorators/DeleteFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +4 -0
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
- package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js +4 -0
- package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js.map +1 -1
- package/features/folder/GetFolder/decorators/GetFolderWithFolderLevelPermissions.d.ts +8 -8
- package/features/folder/shared/abstractions.d.ts +14 -0
- package/features/folder/shared/abstractions.js +4 -1
- package/features/folder/shared/abstractions.js.map +1 -1
- package/filter/filter.gql.d.ts +2 -3
- package/filter/filter.gql.js +61 -27
- package/filter/filter.gql.js.map +1 -1
- package/filter/filter.so.d.ts +10 -2
- package/filter/filter.so.js +2 -2
- package/filter/filter.so.js.map +1 -1
- package/flp/index.d.ts +0 -1
- package/flp/index.js +0 -1
- package/flp/tasks/createFlp.task.d.ts +2 -2
- package/flp/tasks/deleteFlp.task.d.ts +2 -2
- package/flp/tasks/index.d.ts +0 -1
- package/flp/tasks/index.js +1 -14
- package/flp/tasks/index.js.map +1 -1
- package/flp/tasks/syncFlp.task.d.ts +2 -2
- package/flp/tasks/syncFlp.task.js +12 -0
- package/flp/tasks/syncFlp.task.js.map +1 -1
- package/flp/tasks/updateFlp.task.d.ts +2 -2
- package/folder/folder.gql.d.ts +1 -1
- package/folder/folder.gql.js +9 -3
- package/folder/folder.gql.js.map +1 -1
- package/index.d.ts +1 -6
- package/index.js +1 -11
- package/package.json +20 -22
- package/utils/createOperationsWrapper.d.ts +5 -2
- package/utils/createOperationsWrapper.js +2 -2
- package/utils/createOperationsWrapper.js.map +1 -1
- package/utils/decorators/CmsEntriesCrudDecorators.js +9 -5
- package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -1
- package/utils/resolve.d.ts +2 -2
- package/utils/resolve.js +1 -1
- package/utils/resolve.js.map +1 -1
- package/createAcoContext.d.ts +0 -9
- package/createAcoContext.js +0 -109
- package/createAcoContext.js.map +0 -1
- package/createAcoStorageOperations.d.ts +0 -12
- package/createAcoStorageOperations.js +0 -9
- package/createAcoStorageOperations.js.map +0 -1
- package/createAcoTasks.d.ts +0 -1
- package/createAcoTasks.js +0 -14
- package/createAcoTasks.js.map +0 -1
- package/flp/flp.so.d.ts +0 -20
- package/flp/flp.so.js +0 -183
- package/flp/flp.so.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -9,7 +9,7 @@ declare class MoveEntryWithFlpDecoratorImpl implements MoveEntryUseCase.Interfac
|
|
|
9
9
|
private getRevisionById;
|
|
10
10
|
private decoratee;
|
|
11
11
|
constructor(folderLevelPermissions: FolderLevelPermissions.Interface, getRevisionById: GetRevisionByIdUseCase.Interface, decoratee: MoveEntryUseCase.Interface);
|
|
12
|
-
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string, targetFolderId: string): Promise<Result<import("@webiny/api-headless-cms/types/types").CmsEntry<T>, EntryNotAuthorizedError | import("@webiny/api-headless-cms/domain/contentEntry/errors.js").
|
|
12
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string, targetFolderId: string): Promise<Result<import("@webiny/api-headless-cms/types/types").CmsEntry<T>, EntryNotAuthorizedError | import("@webiny/api-headless-cms/domain/contentEntry/errors.js").EntryNotFoundError | import("@webiny/api-headless-cms/domain/contentEntry/errors.js").EntryPersistenceError>>;
|
|
13
13
|
}
|
|
14
14
|
export declare const MoveEntryWithFlpDecorator: typeof MoveEntryWithFlpDecoratorImpl;
|
|
15
15
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CreateFlpUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
2
|
import type { Folder } from "../../../folder/folder.types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AcoFlpCrud } from "../../../features/folder/shared/abstractions.js";
|
|
4
4
|
export declare class CreateFlpUseCase implements UseCaseAbstraction.Interface {
|
|
5
|
-
private
|
|
6
|
-
constructor(
|
|
5
|
+
private flpCrud;
|
|
6
|
+
constructor(flpCrud: AcoFlpCrud.Interface);
|
|
7
7
|
execute(folder: Folder): Promise<void>;
|
|
8
8
|
}
|
|
@@ -2,18 +2,18 @@ import { WebinyError } from "@webiny/error";
|
|
|
2
2
|
import { Path } from "../../../utils/Path.js";
|
|
3
3
|
import { Permissions, ROOT_FOLDER } from "@webiny/shared-aco";
|
|
4
4
|
class CreateFlpUseCase {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
5
|
+
constructor(flpCrud){
|
|
6
|
+
this.flpCrud = flpCrud;
|
|
7
7
|
}
|
|
8
8
|
async execute(folder) {
|
|
9
9
|
try {
|
|
10
10
|
const { id, type, slug, parentId, permissions } = folder;
|
|
11
11
|
let parentFlp = null;
|
|
12
12
|
if (parentId) {
|
|
13
|
-
parentFlp = await this.
|
|
13
|
+
parentFlp = await this.flpCrud.get(parentId);
|
|
14
14
|
if (!parentFlp) throw new WebinyError("Parent folder level permission not found. Unable to create a new record in the FLP catalog.", "ERROR_CREATE_FLP_USE_CASE_PARENT_FLP_NOT_FOUND");
|
|
15
15
|
}
|
|
16
|
-
await this.
|
|
16
|
+
await this.flpCrud.create({
|
|
17
17
|
id,
|
|
18
18
|
type,
|
|
19
19
|
slug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/CreateFlp/CreateFlpUseCase.js","sources":["../../../../src/features/flp/CreateFlp/CreateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { CreateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { FolderLevelPermission as IFolderLevelPermission } from \"~/flp/flp.types.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/flp/CreateFlp/CreateFlpUseCase.js","sources":["../../../../src/features/flp/CreateFlp/CreateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { CreateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { FolderLevelPermission as IFolderLevelPermission } from \"~/flp/flp.types.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport class CreateFlpUseCase implements UseCaseAbstraction.Interface {\n constructor(private flpCrud: AcoFlpCrud.Interface) {}\n\n async execute(folder: Folder): Promise<void> {\n try {\n const { id, type, slug, parentId, permissions } = folder;\n let parentFlp: IFolderLevelPermission | null = null;\n\n if (parentId) {\n parentFlp = await this.flpCrud.get(parentId);\n\n if (!parentFlp) {\n throw new WebinyError(\n \"Parent folder level permission not found. Unable to create a new record in the FLP catalog.\",\n \"ERROR_CREATE_FLP_USE_CASE_PARENT_FLP_NOT_FOUND\"\n );\n }\n }\n\n await this.flpCrud.create({\n id,\n type,\n slug,\n parentId: parentId ?? ROOT_FOLDER,\n path: Path.create(slug, parentFlp?.path),\n permissions: Permissions.create(permissions, parentFlp)\n });\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while creating FLP\",\n code: \"ERROR_CREATE_FLP_USE_CASE\"\n });\n }\n }\n}\n"],"names":["CreateFlpUseCase","flpCrud","folder","id","type","slug","parentId","permissions","parentFlp","WebinyError","ROOT_FOLDER","Path","Permissions","error"],"mappings":";;;AAQO,MAAMA;IACT,YAAoBC,OAA6B,CAAE;aAA/BA,OAAO,GAAPA;IAAgC;IAEpD,MAAM,QAAQC,MAAc,EAAiB;QACzC,IAAI;YACA,MAAM,EAAEC,EAAE,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,WAAW,EAAE,GAAGL;YAClD,IAAIM,YAA2C;YAE/C,IAAIF,UAAU;gBACVE,YAAY,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF;gBAEnC,IAAI,CAACE,WACD,MAAM,IAAIC,YACN,+FACA;YAGZ;YAEA,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;gBACtBN;gBACAC;gBACAC;gBACA,UAAUC,YAAYI;gBACtB,MAAMC,KAAK,MAAM,CAACN,MAAMG,WAAW;gBACnC,aAAaI,YAAY,MAAM,CAACL,aAAaC;YACjD;QACJ,EAAE,OAAOK,OAAO;YACZ,MAAMJ,YAAY,IAAI,CAACI,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
|
-
import type { AcoContext } from "../../../types.js";
|
|
3
|
-
interface LegacyDeps {
|
|
4
|
-
context: AcoContext;
|
|
5
|
-
}
|
|
6
2
|
export declare const CreateFlpFeature: {
|
|
7
3
|
name: string;
|
|
8
|
-
register(container: Container
|
|
4
|
+
register(container: Container): void;
|
|
9
5
|
};
|
|
10
|
-
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CreateFlpUseCase } from "./CreateFlpUseCase.js";
|
|
3
3
|
import { CreateFlpUseCase as external_abstractions_js_CreateFlpUseCase } from "./abstractions.js";
|
|
4
|
+
import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
|
|
4
5
|
const CreateFlpFeature = createFeature({
|
|
5
6
|
name: "CreateFlp",
|
|
6
|
-
register (container
|
|
7
|
-
container.registerFactory(external_abstractions_js_CreateFlpUseCase, ()=>new CreateFlpUseCase(
|
|
7
|
+
register (container) {
|
|
8
|
+
container.registerFactory(external_abstractions_js_CreateFlpUseCase, ()=>new CreateFlpUseCase(container.resolve(AcoFlpCrud)));
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
export { CreateFlpFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/CreateFlp/feature.js","sources":["../../../../src/features/flp/CreateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { CreateFlpUseCase } from \"./CreateFlpUseCase.js\";\nimport { CreateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/flp/CreateFlp/feature.js","sources":["../../../../src/features/flp/CreateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { CreateFlpUseCase } from \"./CreateFlpUseCase.js\";\nimport { CreateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const CreateFlpFeature = createFeature({\n name: \"CreateFlp\",\n register(container: Container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new CreateFlpUseCase(container.resolve(AcoFlpCrud));\n });\n }\n});\n"],"names":["CreateFlpFeature","createFeature","container","UseCaseAbstraction","CreateFlpUseCase","AcoFlpCrud"],"mappings":";;;;AAMO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,eAAe,CAACC,2CAAoB,IACnC,IAAIC,iBAAiBF,UAAU,OAAO,CAACG;IAEtD;AACJ"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DeleteFlpUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
2
|
import type { Folder } from "../../../folder/folder.types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AcoFlpCrud } from "../../../features/folder/shared/abstractions.js";
|
|
4
4
|
export declare class DeleteFlpUseCase implements UseCaseAbstraction.Interface {
|
|
5
|
-
private
|
|
6
|
-
constructor(
|
|
5
|
+
private flpCrud;
|
|
6
|
+
constructor(flpCrud: AcoFlpCrud.Interface);
|
|
7
7
|
execute(folder: Folder): Promise<void>;
|
|
8
8
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
2
|
class DeleteFlpUseCase {
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
3
|
+
constructor(flpCrud){
|
|
4
|
+
this.flpCrud = flpCrud;
|
|
5
5
|
}
|
|
6
6
|
async execute(folder) {
|
|
7
7
|
try {
|
|
8
8
|
if (!folder) throw new WebinyError("Missing `folder` from the task input, I can't delete the record from the FLP catalog.", "ERROR_DELETE_FLP_USE_CASE_FOLDER_NOT_PROVIDED", {
|
|
9
9
|
folder
|
|
10
10
|
});
|
|
11
|
-
await this.
|
|
11
|
+
await this.flpCrud.delete(folder.id);
|
|
12
12
|
} catch (error) {
|
|
13
13
|
throw WebinyError.from(error, {
|
|
14
14
|
message: "Error while deleting FLP",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/DeleteFlp/DeleteFlpUseCase.js","sources":["../../../../src/features/flp/DeleteFlp/DeleteFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { DeleteFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/flp/DeleteFlp/DeleteFlpUseCase.js","sources":["../../../../src/features/flp/DeleteFlp/DeleteFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { DeleteFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport class DeleteFlpUseCase implements UseCaseAbstraction.Interface {\n constructor(private flpCrud: AcoFlpCrud.Interface) {}\n\n async execute(folder: Folder): Promise<void> {\n try {\n if (!folder) {\n throw new WebinyError(\n \"Missing `folder` from the task input, I can't delete the record from the FLP catalog.\",\n \"ERROR_DELETE_FLP_USE_CASE_FOLDER_NOT_PROVIDED\",\n { folder }\n );\n }\n await this.flpCrud.delete(folder.id);\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while deleting FLP\",\n code: \"ERROR_DELETE_FLP_USE_CASE\"\n });\n }\n }\n}\n"],"names":["DeleteFlpUseCase","flpCrud","folder","WebinyError","error"],"mappings":";AAKO,MAAMA;IACT,YAAoBC,OAA6B,CAAE;aAA/BA,OAAO,GAAPA;IAAgC;IAEpD,MAAM,QAAQC,MAAc,EAAiB;QACzC,IAAI;YACA,IAAI,CAACA,QACD,MAAM,IAAIC,YACN,yFACA,iDACA;gBAAED;YAAO;YAGjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAACA,OAAO,EAAE;QACvC,EAAE,OAAOE,OAAO;YACZ,MAAMD,YAAY,IAAI,CAACC,OAAO;gBAC1B,SAAS;gBACT,MAAM;YACV;QACJ;IACJ;AACJ"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
|
-
import type { AcoContext } from "../../../types.js";
|
|
3
|
-
interface LegacyDeps {
|
|
4
|
-
context: AcoContext;
|
|
5
|
-
}
|
|
6
2
|
export declare const DeleteFlpFeature: {
|
|
7
3
|
name: string;
|
|
8
|
-
register(container: Container
|
|
4
|
+
register(container: Container): void;
|
|
9
5
|
};
|
|
10
|
-
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { DeleteFlpUseCase } from "./DeleteFlpUseCase.js";
|
|
3
3
|
import { DeleteFlpUseCase as external_abstractions_js_DeleteFlpUseCase } from "./abstractions.js";
|
|
4
|
+
import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
|
|
4
5
|
const DeleteFlpFeature = createFeature({
|
|
5
6
|
name: "DeleteFlp",
|
|
6
|
-
register (container
|
|
7
|
-
container.registerFactory(external_abstractions_js_DeleteFlpUseCase, ()=>new DeleteFlpUseCase(
|
|
7
|
+
register (container) {
|
|
8
|
+
container.registerFactory(external_abstractions_js_DeleteFlpUseCase, ()=>new DeleteFlpUseCase(container.resolve(AcoFlpCrud)));
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
export { DeleteFlpFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/DeleteFlp/feature.js","sources":["../../../../src/features/flp/DeleteFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { DeleteFlpUseCase } from \"./DeleteFlpUseCase.js\";\nimport { DeleteFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/flp/DeleteFlp/feature.js","sources":["../../../../src/features/flp/DeleteFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { DeleteFlpUseCase } from \"./DeleteFlpUseCase.js\";\nimport { DeleteFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const DeleteFlpFeature = createFeature({\n name: \"DeleteFlp\",\n register(container: Container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new DeleteFlpUseCase(container.resolve(AcoFlpCrud));\n });\n }\n});\n"],"names":["DeleteFlpFeature","createFeature","container","UseCaseAbstraction","DeleteFlpUseCase","AcoFlpCrud"],"mappings":";;;;AAMO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,eAAe,CAACC,2CAAoB,IACnC,IAAIC,iBAAiBF,UAAU,OAAO,CAACG;IAEtD;AACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type IFolderLevelPermissions } from "./abstractions.js";
|
|
2
|
+
import type { FolderPermission } from "../../../types.js";
|
|
3
|
+
declare class NoopFolderLevelPermissionsImpl implements IFolderLevelPermissions {
|
|
4
|
+
canUseFolderLevelPermissions(): boolean;
|
|
5
|
+
canUseTeams(): boolean;
|
|
6
|
+
canCreateFolderInRoot(): boolean;
|
|
7
|
+
permissionsIncludeNonInheritedPermissions(): boolean;
|
|
8
|
+
canAccessFolder(): Promise<boolean>;
|
|
9
|
+
canAccessFolderContent(): Promise<boolean>;
|
|
10
|
+
ensureCanAccessFolder(): Promise<void>;
|
|
11
|
+
ensureCanAccessFolderContent(): Promise<void>;
|
|
12
|
+
canManageFolderContent(): Promise<boolean>;
|
|
13
|
+
canManageFolderStructure(): Promise<boolean>;
|
|
14
|
+
canManageFolderPermissions(): Promise<boolean>;
|
|
15
|
+
getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]>;
|
|
16
|
+
listFolderLevelPermissions(): Promise<Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
permissions: FolderPermission[];
|
|
19
|
+
}>>;
|
|
20
|
+
getFolderLevelPermissions(): Promise<FolderPermission[]>;
|
|
21
|
+
}
|
|
22
|
+
export declare const NoopFolderLevelPermissions: typeof NoopFolderLevelPermissionsImpl & {
|
|
23
|
+
__abstraction: import("@webiny/di").Abstraction<IFolderLevelPermissions>;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FolderLevelPermissions } from "./abstractions.js";
|
|
2
|
+
class NoopFolderLevelPermissionsImpl {
|
|
3
|
+
canUseFolderLevelPermissions() {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
canUseTeams() {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
canCreateFolderInRoot() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
permissionsIncludeNonInheritedPermissions() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
async canAccessFolder() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
async canAccessFolderContent() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
async ensureCanAccessFolder() {}
|
|
22
|
+
async ensureCanAccessFolderContent() {}
|
|
23
|
+
async canManageFolderContent() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
async canManageFolderStructure() {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
async canManageFolderPermissions() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
async getDefaultPermissions(permissions) {
|
|
33
|
+
return permissions;
|
|
34
|
+
}
|
|
35
|
+
async listFolderLevelPermissions() {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
async getFolderLevelPermissions() {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const NoopFolderLevelPermissions = FolderLevelPermissions.createImplementation({
|
|
43
|
+
implementation: NoopFolderLevelPermissionsImpl,
|
|
44
|
+
dependencies: []
|
|
45
|
+
});
|
|
46
|
+
export { NoopFolderLevelPermissions };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=NoopFolderLevelPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.ts"],"sourcesContent":["import { FolderLevelPermissions, type IFolderLevelPermissions } from \"./abstractions.js\";\nimport type { FolderPermission } from \"~/types.js\";\n\nclass NoopFolderLevelPermissionsImpl implements IFolderLevelPermissions {\n canUseFolderLevelPermissions(): boolean {\n return false;\n }\n\n canUseTeams(): boolean {\n return false;\n }\n\n canCreateFolderInRoot(): boolean {\n return true;\n }\n\n permissionsIncludeNonInheritedPermissions(): boolean {\n return false;\n }\n\n async canAccessFolder(): Promise<boolean> {\n return true;\n }\n\n async canAccessFolderContent(): Promise<boolean> {\n return true;\n }\n\n async ensureCanAccessFolder(): Promise<void> {\n return;\n }\n\n async ensureCanAccessFolderContent(): Promise<void> {\n return;\n }\n\n async canManageFolderContent(): Promise<boolean> {\n return true;\n }\n\n async canManageFolderStructure(): Promise<boolean> {\n return true;\n }\n\n async canManageFolderPermissions(): Promise<boolean> {\n return true;\n }\n\n async getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n return permissions;\n }\n\n async listFolderLevelPermissions(): Promise<\n Array<{ id: string; permissions: FolderPermission[] }>\n > {\n return [];\n }\n\n async getFolderLevelPermissions(): Promise<FolderPermission[]> {\n return [];\n }\n}\n\nexport const NoopFolderLevelPermissions = FolderLevelPermissions.createImplementation({\n implementation: NoopFolderLevelPermissionsImpl,\n dependencies: []\n});\n"],"names":["NoopFolderLevelPermissionsImpl","permissions","NoopFolderLevelPermissions","FolderLevelPermissions"],"mappings":";AAGA,MAAMA;IACF,+BAAwC;QACpC,OAAO;IACX;IAEA,cAAuB;QACnB,OAAO;IACX;IAEA,wBAAiC;QAC7B,OAAO;IACX;IAEA,4CAAqD;QACjD,OAAO;IACX;IAEA,MAAM,kBAAoC;QACtC,OAAO;IACX;IAEA,MAAM,yBAA2C;QAC7C,OAAO;IACX;IAEA,MAAM,wBAAuC,CAE7C;IAEA,MAAM,+BAA8C,CAEpD;IAEA,MAAM,yBAA2C;QAC7C,OAAO;IACX;IAEA,MAAM,2BAA6C;QAC/C,OAAO;IACX;IAEA,MAAM,6BAA+C;QACjD,OAAO;IACX;IAEA,MAAM,sBAAsBC,WAA+B,EAA+B;QACtF,OAAOA;IACX;IAEA,MAAM,6BAEJ;QACE,OAAO,EAAE;IACb;IAEA,MAAM,4BAAyD;QAC3D,OAAO,EAAE;IACb;AACJ;AAEO,MAAMC,6BAA6BC,uBAAuB,oBAAoB,CAAC;IAClF,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { GetFlpUseCase } from "./GetFlpUseCase.js";
|
|
3
3
|
import { GetFlpUseCase as external_abstractions_js_GetFlpUseCase } from "./abstractions.js";
|
|
4
|
+
import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
|
|
4
5
|
const GetFlpFeature = createFeature({
|
|
5
6
|
name: "GetFlpFeature",
|
|
6
|
-
register (container
|
|
7
|
-
container.registerFactory(external_abstractions_js_GetFlpUseCase, ()=>new GetFlpUseCase(
|
|
7
|
+
register (container) {
|
|
8
|
+
container.registerFactory(external_abstractions_js_GetFlpUseCase, ()=>new GetFlpUseCase(container.resolve(AcoFlpCrud).get));
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
export { GetFlpFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/GetFlp/feature.js","sources":["../../../../src/features/flp/GetFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFlpUseCase } from \"./GetFlpUseCase.js\";\nimport { GetFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/flp/GetFlp/feature.js","sources":["../../../../src/features/flp/GetFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFlpUseCase } from \"./GetFlpUseCase.js\";\nimport { GetFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const GetFlpFeature = createFeature({\n name: \"GetFlpFeature\",\n register(container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new GetFlpUseCase(container.resolve(AcoFlpCrud).get);\n });\n }\n});\n"],"names":["GetFlpFeature","createFeature","container","UseCaseAbstraction","GetFlpUseCase","AcoFlpCrud"],"mappings":";;;;AAKO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,wCAAoB,IACnC,IAAIC,cAAcF,UAAU,OAAO,CAACG,YAAY,GAAG;IAElE;AACJ"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { ListFlpsUseCase } from "./ListFlpsUseCase.js";
|
|
3
3
|
import { ListFlpsUseCase as external_abstractions_js_ListFlpsUseCase } from "./abstractions.js";
|
|
4
|
+
import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
|
|
4
5
|
const ListFlpsFeature = createFeature({
|
|
5
6
|
name: "ListFlpsFeature",
|
|
6
|
-
register (container
|
|
7
|
-
container.registerFactory(external_abstractions_js_ListFlpsUseCase, ()=>new ListFlpsUseCase(
|
|
7
|
+
register (container) {
|
|
8
|
+
container.registerFactory(external_abstractions_js_ListFlpsUseCase, ()=>new ListFlpsUseCase(container.resolve(AcoFlpCrud).list));
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
export { ListFlpsFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/ListFlps/feature.js","sources":["../../../../src/features/flp/ListFlps/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListFlpsUseCase } from \"./ListFlpsUseCase.js\";\nimport { ListFlpsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/flp/ListFlps/feature.js","sources":["../../../../src/features/flp/ListFlps/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListFlpsUseCase } from \"./ListFlpsUseCase.js\";\nimport { ListFlpsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const ListFlpsFeature = createFeature({\n name: \"ListFlpsFeature\",\n register(container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new ListFlpsUseCase(container.resolve(AcoFlpCrud).list);\n });\n }\n});\n"],"names":["ListFlpsFeature","createFeature","container","UseCaseAbstraction","ListFlpsUseCase","AcoFlpCrud"],"mappings":";;;;AAKO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,0CAAoB,IACnC,IAAIC,gBAAgBF,UAAU,OAAO,CAACG,YAAY,IAAI;IAErE;AACJ"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AcoFlpCrud } from "../../../features/folder/shared/abstractions.js";
|
|
3
|
+
import type { ListFoldersUseCase } from "../../../features/folder/ListFolders/index.js";
|
|
4
|
+
import type { FolderModel } from "../../../domain/folder/abstractions.js";
|
|
5
|
+
import type { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
6
|
+
import type { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
3
7
|
export declare class UpdateFlpUseCase implements UseCaseAbstraction.Interface {
|
|
4
|
-
private
|
|
8
|
+
private flpCrud;
|
|
9
|
+
private listFoldersUseCase;
|
|
10
|
+
private folderModel;
|
|
11
|
+
private updateEntryUseCase;
|
|
12
|
+
private identityContext;
|
|
5
13
|
private isCloseToTimeout?;
|
|
6
14
|
private handleTimeout?;
|
|
7
15
|
private readonly queued;
|
|
8
16
|
private readonly flpsToUpdate;
|
|
9
|
-
constructor(
|
|
17
|
+
constructor(flpCrud: AcoFlpCrud.Interface, listFoldersUseCase: ListFoldersUseCase.Interface, folderModel: FolderModel.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, identityContext: IdentityContext.Interface);
|
|
10
18
|
execute(params: UpdateFlpParams): Promise<void>;
|
|
11
19
|
private collectBranchForUpdate;
|
|
12
20
|
private executeBatchUpdate;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
2
|
import { Path } from "../../../utils/Path.js";
|
|
3
3
|
import { Permissions, ROOT_FOLDER } from "@webiny/shared-aco";
|
|
4
|
-
import { ListFoldersUseCase } from "../../folder/ListFolders/index.js";
|
|
5
|
-
import { FolderModel } from "../../../domain/folder/abstractions.js";
|
|
6
4
|
import { EntryId } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
|
|
7
5
|
class UpdateFlpUseCase {
|
|
8
|
-
constructor(
|
|
6
|
+
constructor(flpCrud, listFoldersUseCase, folderModel, updateEntryUseCase, identityContext){
|
|
7
|
+
this.flpCrud = flpCrud;
|
|
8
|
+
this.listFoldersUseCase = listFoldersUseCase;
|
|
9
|
+
this.folderModel = folderModel;
|
|
10
|
+
this.updateEntryUseCase = updateEntryUseCase;
|
|
11
|
+
this.identityContext = identityContext;
|
|
9
12
|
this.queued = new Set();
|
|
10
13
|
this.flpsToUpdate = new Map();
|
|
11
|
-
this.context = context;
|
|
12
14
|
}
|
|
13
15
|
async execute(params) {
|
|
14
16
|
this.isCloseToTimeout = params.isCloseToTimeout;
|
|
@@ -20,7 +22,7 @@ class UpdateFlpUseCase {
|
|
|
20
22
|
folder
|
|
21
23
|
});
|
|
22
24
|
const flp = await this.getFlp(folder);
|
|
23
|
-
const parentFlp = folder.parentId ? await this.
|
|
25
|
+
const parentFlp = folder.parentId ? await this.flpCrud.get(folder.parentId) : null;
|
|
24
26
|
this.flpsToUpdate.set(folder.id, {
|
|
25
27
|
slug: folder.slug,
|
|
26
28
|
parentId: folder.parentId ?? ROOT_FOLDER,
|
|
@@ -84,16 +86,16 @@ class UpdateFlpUseCase {
|
|
|
84
86
|
permissions
|
|
85
87
|
}
|
|
86
88
|
}));
|
|
87
|
-
await this.
|
|
88
|
-
const folderModel = this.context.container.resolve(FolderModel);
|
|
89
|
+
await this.flpCrud.batchUpdate(items);
|
|
89
90
|
for (const item of items){
|
|
90
91
|
const { id, data } = item;
|
|
91
92
|
const entryId = EntryId.from(id);
|
|
92
|
-
await this.
|
|
93
|
+
const updateResult = await this.updateEntryUseCase.execute(this.folderModel, entryId.toString(), {
|
|
93
94
|
values: {
|
|
94
95
|
path: data.path
|
|
95
96
|
}
|
|
96
97
|
});
|
|
98
|
+
if (updateResult.isFail()) throw updateResult.error;
|
|
97
99
|
}
|
|
98
100
|
} catch (error) {
|
|
99
101
|
throw WebinyError.from(error, {
|
|
@@ -121,8 +123,7 @@ class UpdateFlpUseCase {
|
|
|
121
123
|
this.queued.clear();
|
|
122
124
|
}
|
|
123
125
|
async listDirectChildren(flp) {
|
|
124
|
-
const
|
|
125
|
-
const result = await this.context.security.withoutAuthorization(()=>listFolders.execute({
|
|
126
|
+
const result = await this.identityContext.withoutAuthorization(()=>this.listFoldersUseCase.execute({
|
|
126
127
|
where: {
|
|
127
128
|
type: flp.type,
|
|
128
129
|
parentId: flp.id
|
|
@@ -132,10 +133,10 @@ class UpdateFlpUseCase {
|
|
|
132
133
|
return await Promise.all(result.value.folders.map((folder)=>this.getFlp(folder)));
|
|
133
134
|
}
|
|
134
135
|
async getFlp({ id, type, parentId, slug, permissions }) {
|
|
135
|
-
const flp = await this.
|
|
136
|
+
const flp = await this.flpCrud.get(id);
|
|
136
137
|
if (!flp) {
|
|
137
|
-
const parentFlp = parentId ? await this.
|
|
138
|
-
return await this.
|
|
138
|
+
const parentFlp = parentId ? await this.flpCrud.get(parentId) : null;
|
|
139
|
+
return await this.flpCrud.create({
|
|
139
140
|
id,
|
|
140
141
|
type,
|
|
141
142
|
slug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/UpdateFlp/UpdateFlpUseCase.js","sources":["../../../../src/features/flp/UpdateFlp/UpdateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { AcoContext, Folder, FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\ninterface FlpUpdateData {\n parentId: string;\n slug: string;\n path: string;\n permissions: FolderPermission[];\n}\n\nexport class UpdateFlpUseCase implements UseCaseAbstraction.Interface {\n private context: AcoContext;\n private isCloseToTimeout?: () => boolean;\n private handleTimeout?: (updated: string[]) => void;\n\n private readonly queued: Set<string> = new Set();\n private readonly flpsToUpdate: Map<string, FlpUpdateData> = new Map();\n\n constructor(context: AcoContext) {\n this.context = context;\n }\n\n async execute(params: UpdateFlpParams): Promise<void> {\n this.isCloseToTimeout = params.isCloseToTimeout;\n this.handleTimeout = params.handleTimeout;\n\n if (params.queued) {\n params.queued.forEach(id => this.queued.add(id));\n }\n\n try {\n const { folder } = params;\n\n if (!folder) {\n throw new WebinyError(\n \"Missing `folder`, I can't update the FLP record.\",\n \"ERROR_UPDATING_FLP_USE_CASE_FOLDER_NOT_PROVIDED\",\n { folder }\n );\n }\n\n const flp = await this.getFlp(folder);\n const parentFlp = folder.parentId\n ? await this.context.aco.flp.get(folder.parentId)\n : null;\n\n // Add the root folder to the update collection\n this.flpsToUpdate.set(folder.id, {\n slug: folder.slug,\n parentId: folder.parentId ?? ROOT_FOLDER,\n path: Path.create(folder.slug, parentFlp?.path),\n permissions: Permissions.create(folder.permissions, parentFlp)\n });\n\n // Let's set the FLP as in queue\n this.setQueued(flp.id);\n\n // Get direct children and process each branch completely\n const directChildren = await this.listDirectChildren(flp);\n\n for (const child of directChildren) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n await this.collectBranchForUpdate(child, flp);\n }\n\n // Execute batch update\n await this.executeBatchUpdate();\n } catch (error) {\n // Clear the update collection in case of error\n this.flpsToUpdate.clear();\n this.queued.clear();\n throw WebinyError.from(error, {\n message: \"Error while updating FLP\",\n code: \"ERROR_UPDATING_FLP_USE_CASE\"\n });\n }\n }\n\n private async collectBranchForUpdate(\n flp: FolderLevelPermission,\n parentFlp: FolderLevelPermission\n ): Promise<void> {\n if (this.isQueued(flp.id)) {\n return;\n }\n\n // Get the parent's permissions from the update collection if available\n const parentFlpData = this.flpsToUpdate.get(parentFlp.id);\n const currentParentFlp = {\n ...parentFlp,\n ...(parentFlpData && { ...parentFlpData })\n };\n\n // Add the FLP to the update collection with inherited permissions\n this.flpsToUpdate.set(flp.id, {\n slug: flp.slug,\n parentId: flp.parentId,\n path: Path.create(flp.slug, currentParentFlp.path),\n permissions: Permissions.create(flp.permissions, currentParentFlp)\n });\n\n // Add the FLP to the queue list so we don't fetch it again\n this.setQueued(flp.id);\n\n // Process all children of this folder before moving to siblings\n const children = await this.listDirectChildren(flp);\n\n for (const child of children) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n // Pass the current FLP as the parent for the child\n await this.collectBranchForUpdate(child, flp);\n }\n }\n\n private async executeBatchUpdate(): Promise<void> {\n try {\n const items = Array.from(this.flpsToUpdate.entries()).map(\n ([id, { slug, parentId, path, permissions }]) => {\n return {\n id,\n data: {\n slug,\n parentId,\n path,\n permissions\n }\n };\n }\n );\n\n await this.context.aco.flp.batchUpdate(items);\n\n // Update all folders with the new path\n const folderModel = this.context.container.resolve(FolderModel);\n for (const item of items) {\n const { id, data } = item;\n // Directly update the folder in CMS storage to bypass any folder update event triggers.\n const entryId = EntryId.from(id);\n await this.context.cms.updateEntry(folderModel, entryId.toString(), {\n values: {\n path: data.path\n }\n });\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing batch update of FLPs\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: {\n items: Array.from(this.flpsToUpdate.keys())\n }\n });\n } finally {\n // Clear the update collection after the batch update\n this.flpsToUpdate.clear();\n\n //Let's remove all the updated FLPs ids from the queue cache\n this.clearQueuedList();\n }\n }\n\n private getQueuedList(): string[] {\n return Array.from(this.queued);\n }\n\n private setQueued(id: string): void {\n this.queued.add(id);\n }\n\n private isQueued(id: string): boolean {\n return this.queued.has(id);\n }\n\n private clearQueuedList(): void {\n this.queued.clear();\n }\n\n private async listDirectChildren(flp: FolderLevelPermission): Promise<FolderLevelPermission[]> {\n const listFolders = this.context.container.resolve(ListFoldersUseCase);\n\n const result = await this.context.security.withoutAuthorization(() => {\n return listFolders.execute({\n where: {\n type: flp.type,\n parentId: flp.id\n }\n });\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return await Promise.all(result.value.folders.map(folder => this.getFlp(folder)));\n }\n\n private async getFlp({\n id,\n type,\n parentId,\n slug,\n permissions\n }: Folder): Promise<FolderLevelPermission> {\n const flp = await this.context.aco.flp.get(id);\n\n if (!flp) {\n const parentFlp = parentId ? await this.context.aco.flp.get(parentId) : null;\n\n return await this.context.aco.flp.create({\n id,\n type,\n slug,\n parentId: parentId ?? ROOT_FOLDER,\n path: Path.create(slug, parentFlp?.path),\n permissions: Permissions.create(permissions, parentFlp)\n });\n }\n\n return flp;\n }\n}\n"],"names":["UpdateFlpUseCase","context","Set","Map","params","id","folder","WebinyError","flp","parentFlp","ROOT_FOLDER","Path","Permissions","directChildren","child","error","parentFlpData","currentParentFlp","children","items","Array","slug","parentId","path","permissions","folderModel","FolderModel","item","data","entryId","EntryId","listFolders","ListFoldersUseCase","result","Promise","type"],"mappings":";;;;;;AAgBO,MAAMA;IAQT,YAAYC,OAAmB,CAAE;aAHhB,MAAM,GAAgB,IAAIC;aAC1B,YAAY,GAA+B,IAAIC;QAG5D,IAAI,CAAC,OAAO,GAAGF;IACnB;IAEA,MAAM,QAAQG,MAAuB,EAAiB;QAClD,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;QAEzC,IAAIA,OAAO,MAAM,EACbA,OAAO,MAAM,CAAC,OAAO,CAACC,CAAAA,KAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;QAGhD,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGF;YAEnB,IAAI,CAACE,QACD,MAAM,IAAIC,YACN,oDACA,mDACA;gBAAED;YAAO;YAIjB,MAAME,MAAM,MAAM,IAAI,CAAC,MAAM,CAACF;YAC9B,MAAMG,YAAYH,OAAO,QAAQ,GAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAACA,OAAO,QAAQ,IAC9C;YAGN,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,OAAO,EAAE,EAAE;gBAC7B,MAAMA,OAAO,IAAI;gBACjB,UAAUA,OAAO,QAAQ,IAAII;gBAC7B,MAAMC,KAAK,MAAM,CAACL,OAAO,IAAI,EAAEG,WAAW;gBAC1C,aAAaG,YAAY,MAAM,CAACN,OAAO,WAAW,EAAEG;YACxD;YAGA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../../../src/features/flp/UpdateFlp/UpdateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { Folder, FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport type { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\nimport type { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport type { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport type { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\ninterface FlpUpdateData {\n parentId: string;\n slug: string;\n path: string;\n permissions: FolderPermission[];\n}\n\nexport class UpdateFlpUseCase implements UseCaseAbstraction.Interface {\n private isCloseToTimeout?: () => boolean;\n private handleTimeout?: (updated: string[]) => void;\n\n private readonly queued: Set<string> = new Set();\n private readonly flpsToUpdate: Map<string, FlpUpdateData> = new Map();\n\n constructor(\n private flpCrud: AcoFlpCrud.Interface,\n private listFoldersUseCase: ListFoldersUseCase.Interface,\n private folderModel: FolderModel.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(params: UpdateFlpParams): Promise<void> {\n this.isCloseToTimeout = params.isCloseToTimeout;\n this.handleTimeout = params.handleTimeout;\n\n if (params.queued) {\n params.queued.forEach(id => this.queued.add(id));\n }\n\n try {\n const { folder } = params;\n\n if (!folder) {\n throw new WebinyError(\n \"Missing `folder`, I can't update the FLP record.\",\n \"ERROR_UPDATING_FLP_USE_CASE_FOLDER_NOT_PROVIDED\",\n { folder }\n );\n }\n\n const flp = await this.getFlp(folder);\n const parentFlp = folder.parentId ? await this.flpCrud.get(folder.parentId) : null;\n\n // Add the root folder to the update collection\n this.flpsToUpdate.set(folder.id, {\n slug: folder.slug,\n parentId: folder.parentId ?? ROOT_FOLDER,\n path: Path.create(folder.slug, parentFlp?.path),\n permissions: Permissions.create(folder.permissions, parentFlp)\n });\n\n // Let's set the FLP as in queue\n this.setQueued(flp.id);\n\n // Get direct children and process each branch completely\n const directChildren = await this.listDirectChildren(flp);\n\n for (const child of directChildren) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n await this.collectBranchForUpdate(child, flp);\n }\n\n // Execute batch update\n await this.executeBatchUpdate();\n } catch (error) {\n // Clear the update collection in case of error\n this.flpsToUpdate.clear();\n this.queued.clear();\n throw WebinyError.from(error, {\n message: \"Error while updating FLP\",\n code: \"ERROR_UPDATING_FLP_USE_CASE\"\n });\n }\n }\n\n private async collectBranchForUpdate(\n flp: FolderLevelPermission,\n parentFlp: FolderLevelPermission\n ): Promise<void> {\n if (this.isQueued(flp.id)) {\n return;\n }\n\n // Get the parent's permissions from the update collection if available\n const parentFlpData = this.flpsToUpdate.get(parentFlp.id);\n const currentParentFlp = {\n ...parentFlp,\n ...(parentFlpData && { ...parentFlpData })\n };\n\n // Add the FLP to the update collection with inherited permissions\n this.flpsToUpdate.set(flp.id, {\n slug: flp.slug,\n parentId: flp.parentId,\n path: Path.create(flp.slug, currentParentFlp.path),\n permissions: Permissions.create(flp.permissions, currentParentFlp)\n });\n\n // Add the FLP to the queue list so we don't fetch it again\n this.setQueued(flp.id);\n\n // Process all children of this folder before moving to siblings\n const children = await this.listDirectChildren(flp);\n\n for (const child of children) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n // Pass the current FLP as the parent for the child\n await this.collectBranchForUpdate(child, flp);\n }\n }\n\n private async executeBatchUpdate(): Promise<void> {\n try {\n const items = Array.from(this.flpsToUpdate.entries()).map(\n ([id, { slug, parentId, path, permissions }]) => {\n return {\n id,\n data: {\n slug,\n parentId,\n path,\n permissions\n }\n };\n }\n );\n\n await this.flpCrud.batchUpdate(items);\n\n // Update all folders with the new path\n for (const item of items) {\n const { id, data } = item;\n // Directly update the folder in CMS storage to bypass any folder update event triggers.\n const entryId = EntryId.from(id);\n const updateResult = await this.updateEntryUseCase.execute(\n this.folderModel,\n entryId.toString(),\n { values: { path: data.path } }\n );\n if (updateResult.isFail()) {\n throw updateResult.error;\n }\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing batch update of FLPs\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: {\n items: Array.from(this.flpsToUpdate.keys())\n }\n });\n } finally {\n // Clear the update collection after the batch update\n this.flpsToUpdate.clear();\n\n //Let's remove all the updated FLPs ids from the queue cache\n this.clearQueuedList();\n }\n }\n\n private getQueuedList(): string[] {\n return Array.from(this.queued);\n }\n\n private setQueued(id: string): void {\n this.queued.add(id);\n }\n\n private isQueued(id: string): boolean {\n return this.queued.has(id);\n }\n\n private clearQueuedList(): void {\n this.queued.clear();\n }\n\n private async listDirectChildren(flp: FolderLevelPermission): Promise<FolderLevelPermission[]> {\n const result = await this.identityContext.withoutAuthorization(() => {\n return this.listFoldersUseCase.execute({\n where: {\n type: flp.type,\n parentId: flp.id\n }\n });\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return await Promise.all(result.value.folders.map(folder => this.getFlp(folder)));\n }\n\n private async getFlp({\n id,\n type,\n parentId,\n slug,\n permissions\n }: Folder): Promise<FolderLevelPermission> {\n const flp = await this.flpCrud.get(id);\n\n if (!flp) {\n const parentFlp = parentId ? await this.flpCrud.get(parentId) : null;\n\n return await this.flpCrud.create({\n id,\n type,\n slug,\n parentId: parentId ?? ROOT_FOLDER,\n path: Path.create(slug, parentFlp?.path),\n permissions: Permissions.create(permissions, parentFlp)\n });\n }\n\n return flp;\n }\n}\n"],"names":["UpdateFlpUseCase","flpCrud","listFoldersUseCase","folderModel","updateEntryUseCase","identityContext","Set","Map","params","id","folder","WebinyError","flp","parentFlp","ROOT_FOLDER","Path","Permissions","directChildren","child","error","parentFlpData","currentParentFlp","children","items","Array","slug","parentId","path","permissions","item","data","entryId","EntryId","updateResult","result","Promise","type"],"mappings":";;;;AAmBO,MAAMA;IAOT,YACYC,OAA6B,EAC7BC,kBAAgD,EAChDC,WAAkC,EAClCC,kBAAgD,EAChDC,eAA0C,CACpD;aALUJ,OAAO,GAAPA;aACAC,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;aARK,MAAM,GAAgB,IAAIC;aAC1B,YAAY,GAA+B,IAAIC;IAQ7D;IAEH,MAAM,QAAQC,MAAuB,EAAiB;QAClD,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;QAEzC,IAAIA,OAAO,MAAM,EACbA,OAAO,MAAM,CAAC,OAAO,CAACC,CAAAA,KAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;QAGhD,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGF;YAEnB,IAAI,CAACE,QACD,MAAM,IAAIC,YACN,oDACA,mDACA;gBAAED;YAAO;YAIjB,MAAME,MAAM,MAAM,IAAI,CAAC,MAAM,CAACF;YAC9B,MAAMG,YAAYH,OAAO,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,OAAO,QAAQ,IAAI;YAG9E,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,OAAO,EAAE,EAAE;gBAC7B,MAAMA,OAAO,IAAI;gBACjB,UAAUA,OAAO,QAAQ,IAAII;gBAC7B,MAAMC,KAAK,MAAM,CAACL,OAAO,IAAI,EAAEG,WAAW;gBAC1C,aAAaG,YAAY,MAAM,CAACN,OAAO,WAAW,EAAEG;YACxD;YAGA,IAAI,CAAC,S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W;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;IAC3B;IAEQ,kBAAwB;QAC5B,IAAI,CAAC,MAAM,CAAC,KAAK;IACrB;IAEA,MAAc,mBAAmBG,GAA0B,EAAoC;QAC3F,MAAMsB,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACpD,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBACnC,OAAO;oBACH,MAAMtB,IAAI,IAAI;oBACd,UAAUA,IAAI,EAAE;gBACpB;YACJ;QAGJ,IAAIsB,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAO,MAAMC,QAAQ,GAAG,CAACD,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAACxB,CAAAA,SAAU,IAAI,CAAC,MAAM,CAACA;IAC5E;IAEA,MAAc,OAAO,EACjBD,EAAE,EACF2B,IAAI,EACJV,QAAQ,EACRD,IAAI,EACJG,WAAW,EACN,EAAkC;QACvC,MAAMhB,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACH;QAEnC,IAAI,CAACG,KAAK;YACN,MAAMC,YAAYa,WAAW,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,YAAY;YAEhE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;gBAC7BjB;gBACA2B;gBACAX;gBACA,UAAUC,YAAYZ;gBACtB,MAAMC,KAAK,MAAM,CAACU,MAAMZ,WAAW;gBACnC,aAAaG,YAAY,MAAM,CAACY,aAAaf;YACjD;QACJ;QAEA,OAAOD;IACX;AACJ"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
|
-
import type { AcoContext } from "../../../types.js";
|
|
3
|
-
interface LegacyDeps {
|
|
4
|
-
context: AcoContext;
|
|
5
|
-
}
|
|
6
2
|
export declare const UpdateFlpFeature: {
|
|
7
3
|
name: string;
|
|
8
|
-
register(container: Container
|
|
4
|
+
register(container: Container): void;
|
|
9
5
|
};
|
|
10
|
-
export {};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateFlpUseCase } from "./UpdateFlpUseCase.js";
|
|
3
3
|
import { UpdateFlpUseCase as external_abstractions_js_UpdateFlpUseCase } from "./abstractions.js";
|
|
4
|
+
import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
|
|
5
|
+
import { ListFoldersUseCase } from "../../folder/ListFolders/index.js";
|
|
6
|
+
import { FolderModel } from "../../../domain/folder/abstractions.js";
|
|
7
|
+
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
4
9
|
const UpdateFlpFeature = createFeature({
|
|
5
10
|
name: "UpdateFlp",
|
|
6
|
-
register (container
|
|
7
|
-
container.registerFactory(external_abstractions_js_UpdateFlpUseCase, ()=>new UpdateFlpUseCase(
|
|
11
|
+
register (container) {
|
|
12
|
+
container.registerFactory(external_abstractions_js_UpdateFlpUseCase, ()=>new UpdateFlpUseCase(container.resolve(AcoFlpCrud), container.resolve(ListFoldersUseCase), container.resolve(FolderModel), container.resolve(UpdateEntryUseCase), container.resolve(IdentityContext)));
|
|
8
13
|
}
|
|
9
14
|
});
|
|
10
15
|
export { UpdateFlpFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/UpdateFlp/feature.js","sources":["../../../../src/features/flp/UpdateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { UpdateFlpUseCase } from \"./UpdateFlpUseCase.js\";\nimport { UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/flp/UpdateFlp/feature.js","sources":["../../../../src/features/flp/UpdateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { UpdateFlpUseCase } from \"./UpdateFlpUseCase.js\";\nimport { UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\nexport const UpdateFlpFeature = createFeature({\n name: \"UpdateFlp\",\n register(container: Container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new UpdateFlpUseCase(\n container.resolve(AcoFlpCrud),\n container.resolve(ListFoldersUseCase),\n container.resolve(FolderModel),\n container.resolve(UpdateEntryUseCase),\n container.resolve(IdentityContext)\n );\n });\n }\n});\n"],"names":["UpdateFlpFeature","createFeature","container","UseCaseAbstraction","UpdateFlpUseCase","AcoFlpCrud","ListFoldersUseCase","FolderModel","UpdateEntryUseCase","IdentityContext"],"mappings":";;;;;;;;AAUO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,eAAe,CAACC,2CAAoB,IACnC,IAAIC,iBACPF,UAAU,OAAO,CAACG,aAClBH,UAAU,OAAO,CAACI,qBAClBJ,UAAU,OAAO,CAACK,cAClBL,UAAU,OAAO,CAACM,qBAClBN,UAAU,OAAO,CAACO;IAG9B;AACJ"}
|
|
@@ -5,7 +5,7 @@ declare class DeleteFolderWithFolderLevelPermissionsImpl implements DeleteFolder
|
|
|
5
5
|
private folderLevelPermissions;
|
|
6
6
|
private readonly decoretee;
|
|
7
7
|
constructor(folderLevelPermissions: FolderLevelPermissions.Interface, decoretee: DeleteFolderUseCase.Interface);
|
|
8
|
-
execute(id: string): Promise<Result<void, never> | Result<never, import("../../../../domain/folder/errors.js").
|
|
8
|
+
execute(id: string): Promise<Result<void, never> | Result<never, import("../../../../domain/folder/errors.js").FolderNotAuthorizedError | import("../../../../domain/folder/errors.js").FolderNotEmptyError | import("../../../../domain/folder/errors.js").FolderNotFoundError | import("../../../../domain/folder/errors.js").FolderPersistenceError>>;
|
|
9
9
|
}
|
|
10
10
|
export declare const DeleteFolderWithFolderLevelPermissions: typeof DeleteFolderWithFolderLevelPermissionsImpl;
|
|
11
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { EnsureFolderIsEmpty as Abstraction } from \"~/features/folder/EnsureFolderIsEmpty/abstractions.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 folderLevelPermissions: FolderLevelPermissions.Interface,\n private listFoldersUseCase: ListFoldersUseCase.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\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 // Let's also check if there are folders / content that are not visible because of folder permissions.\n if (!this.folderLevelPermissions.canUseFolderLevelPermissions()) {\n // If folder level permissions are not enabled, we can skip this check. This is because\n // in that case, all folders and content are visible to the user.\n return Result.ok();\n }\n\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, FolderLevelPermissions, ListFoldersUseCase]\n});\n"],"names":["EnsureFolderIsEmptyImpl","identityContext","folderLevelPermissions","listFoldersUseCase","type","id","hasContentCallback","hasFoldersCallback","result","folders","hasFolders","hasContent","Promise","Result","FolderNotEmptyError","hasInvisibleFolders","hasInvisibleContent","FolderNotAuthorizedError","EnsureFolderIsEmpty","Abstraction","IdentityContext","FolderLevelPermissions","ListFoldersUseCase"],"mappings":";;;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,sBAAwD,EACxDC,kBAAgD,CAC1D;aAHUF,eAAe,GAAfA;aACAC,sBAAsB,GAAtBA;aACAC,kBAAkB,GAAlBA;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;YAEA,MAAM,
|
|
1
|
+
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { EnsureFolderIsEmpty as Abstraction } from \"~/features/folder/EnsureFolderIsEmpty/abstractions.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 folderLevelPermissions: FolderLevelPermissions.Interface,\n private listFoldersUseCase: ListFoldersUseCase.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\n if (result.isFail()) {\n console.error(result.error.message);\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 // Let's also check if there are folders / content that are not visible because of folder permissions.\n if (!this.folderLevelPermissions.canUseFolderLevelPermissions()) {\n // If folder level permissions are not enabled, we can skip this check. This is because\n // in that case, all folders and content are visible to the user.\n return Result.ok();\n }\n\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, FolderLevelPermissions, ListFoldersUseCase]\n});\n"],"names":["EnsureFolderIsEmptyImpl","identityContext","folderLevelPermissions","listFoldersUseCase","type","id","hasContentCallback","hasFoldersCallback","result","console","folders","hasFolders","hasContent","Promise","Result","FolderNotEmptyError","hasInvisibleFolders","hasInvisibleContent","FolderNotAuthorizedError","EnsureFolderIsEmpty","Abstraction","IdentityContext","FolderLevelPermissions","ListFoldersUseCase"],"mappings":";;;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,sBAAwD,EACxDC,kBAAgD,CAC1D;aAHUF,eAAe,GAAfA;aACAC,sBAAsB,GAAtBA;aACAC,kBAAkB,GAAlBA;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;YAEA,IAAIG,OAAO,MAAM,IAAI;gBACjBC,QAAQ,KAAK,CAACD,OAAO,KAAK,CAAC,OAAO;gBAClC,OAAO;YACX;YAEA,MAAM,EAAEE,OAAO,EAAE,GAAGF,OAAO,KAAK;YAEhC,OAAOE,QAAQ,MAAM,GAAG;QAC5B;QAEA,MAAM,CAACC,YAAYC,WAAW,GAAG,MAAMC,QAAQ,GAAG,CAAC;YAC/CN;YACAD;SACH;QAED,IAAIK,cAAcC,YACd,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAI3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,4BAA4B,IAGzD,OAAOD,OAAO,EAAE;QAGpB,MAAM,CAACE,qBAAqBC,oBAAoB,GAC5C,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC;YAC5C,MAAM,CAACN,YAAYC,WAAW,GAAG,M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