@webiny/api-aco 6.5.2-beta.1 → 6.5.2-beta.3

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.
Files changed (87) hide show
  1. package/createAcoContext.js +2 -0
  2. package/createAcoContext.js.map +1 -1
  3. package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.d.ts +13 -0
  4. package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js +25 -0
  5. package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js.map +1 -0
  6. package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.d.ts +16 -0
  7. package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js +28 -0
  8. package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js.map +1 -0
  9. package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.d.ts +17 -0
  10. package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js +28 -0
  11. package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js.map +1 -0
  12. package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.d.ts +13 -0
  13. package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js +25 -0
  14. package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js.map +1 -0
  15. package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.d.ts +16 -0
  16. package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js +55 -0
  17. package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js.map +1 -0
  18. package/features/cms/decorators/PublishEntryWithFlpDecorator.d.ts +14 -0
  19. package/features/cms/decorators/PublishEntryWithFlpDecorator.js +30 -0
  20. package/features/cms/decorators/PublishEntryWithFlpDecorator.js.map +1 -0
  21. package/features/cms/decorators/RepublishEntryWithFlpDecorator.d.ts +14 -0
  22. package/features/cms/decorators/RepublishEntryWithFlpDecorator.js +30 -0
  23. package/features/cms/decorators/RepublishEntryWithFlpDecorator.js.map +1 -0
  24. package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.d.ts +17 -0
  25. package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js +38 -0
  26. package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js.map +1 -0
  27. package/features/cms/decorators/UnpublishEntryWithFlpDecorator.d.ts +14 -0
  28. package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js +30 -0
  29. package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js.map +1 -0
  30. package/features/cms/decorators/UpdateEntryWithFlpDecorator.d.ts +1 -0
  31. package/features/cms/decorators/UpdateEntryWithFlpDecorator.js +9 -5
  32. package/features/cms/decorators/UpdateEntryWithFlpDecorator.js.map +1 -1
  33. package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.d.ts +14 -0
  34. package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js +30 -0
  35. package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js.map +1 -0
  36. package/features/cms/decorators/canAccessEntryFolder.d.ts +21 -0
  37. package/features/cms/decorators/canAccessEntryFolder.js +25 -0
  38. package/features/cms/decorators/canAccessEntryFolder.js.map +1 -0
  39. package/features/cms/feature.js +20 -0
  40. package/features/cms/feature.js.map +1 -1
  41. package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js +4 -1
  42. package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js.map +1 -1
  43. package/features/folder/CreateFolder/CreateFolderRepository.js +3 -1
  44. package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
  45. package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.d.ts +1 -1
  46. package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js +20 -2
  47. package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js.map +1 -1
  48. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
  49. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +1 -5
  50. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
  51. package/features/folder/FolderTypePermissions/FolderTypeAccess.d.ts +11 -0
  52. package/features/folder/FolderTypePermissions/FolderTypeAccess.js +28 -0
  53. package/features/folder/FolderTypePermissions/FolderTypeAccess.js.map +1 -0
  54. package/features/folder/FolderTypePermissions/abstractions.d.ts +23 -0
  55. package/features/folder/FolderTypePermissions/abstractions.js +6 -0
  56. package/features/folder/FolderTypePermissions/abstractions.js.map +1 -0
  57. package/features/folder/FolderTypePermissions/decorators.d.ts +67 -0
  58. package/features/folder/FolderTypePermissions/decorators.js +128 -0
  59. package/features/folder/FolderTypePermissions/decorators.js.map +1 -0
  60. package/features/folder/FolderTypePermissions/feature.d.ts +4 -0
  61. package/features/folder/FolderTypePermissions/feature.js +18 -0
  62. package/features/folder/FolderTypePermissions/feature.js.map +1 -0
  63. package/features/folder/FolderTypePermissions/index.d.ts +2 -0
  64. package/features/folder/FolderTypePermissions/index.js +2 -0
  65. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +8 -2
  66. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
  67. package/features/folder/GetFolderHierarchy/abstractions.d.ts +3 -1
  68. package/features/folder/GetFolderHierarchy/abstractions.js.map +1 -1
  69. package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +5 -0
  70. package/features/folder/UpdateFolder/UpdateFolderRepository.js +33 -5
  71. package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
  72. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.d.ts +1 -1
  73. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +21 -5
  74. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
  75. package/features/folder/shared/validatePermissionsInput.d.ts +7 -0
  76. package/features/folder/shared/validatePermissionsInput.js +12 -0
  77. package/features/folder/shared/validatePermissionsInput.js.map +1 -0
  78. package/filter/filter.so.js +12 -5
  79. package/filter/filter.so.js.map +1 -1
  80. package/filter/filter.types.js.map +1 -1
  81. package/folder/folder.gql.js +4 -0
  82. package/folder/folder.gql.js.map +1 -1
  83. package/folder/validation.d.ts +8 -0
  84. package/folder/validation.js +7 -0
  85. package/folder/validation.js.map +1 -0
  86. package/package.json +23 -22
  87. package/types.js.map +1 -1
@@ -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":";;;;;;;;;AAgBA,MAAMA;IACF,YACYC,MAAkC,EAClCC,SAAuC,CACjD;aAFUD,MAAM,GAANA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,MAAyB,EAA6B;QAEhE,IAAI,CAAE,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAACA,OAAO,KAAK,CAAC,IAAI,GAC7C,OAAOC,OAAO,EAAE,CAAC;YACb,SAAS,EAAE;YACX,MAAM;gBAAE,QAAQ;gBAAM,cAAc;gBAAO,YAAY;YAAE;QAC7D;QAEJ,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;IAClC;AACJ;AAEA,MAAME;IACF,YACYJ,MAAkC,EAClCC,SAA8C,CACxD;aAFUD,MAAM,GAANA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,MAAgC,EAAoC;QAE9E,IAAI,CAAE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AAO,KAAK,CAAC,IAAI,GAC9C,OAAOV,OAAO,IAAI,CAAC,IAAIK;QAE3B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF,IAAIM;IACtC;AACJ;AAEA,MAAME;IACF,YACYd,MAAkC,EAClCW,SAAqC,EACrCV,SAAwC,CAClD;aAHUD,MAAM,GAANA;aACAW,SAAS,GAATA;aACAV,SAAS,GAATA;IACT;IAEH,MAAM,QAAQK,EAAU,EAAE;QACtB,MAAMO,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACP;QAC5C,IAAIO,OAAO,MAAM,IACb,OAAOV,OAAO,IAAI,CAACU,OAAO,KAAK;QAEnC,IAAI,CAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAACA,OAAO,KAAK,CAAC,IAAI,GAC9C,OAAOV,OAAO,IAAI,CAAC,IAAIK;QAE3B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;IAClC;AACJ;AAEO,MAAMS,iCAAiCC,mBAAmB,eAAe,CAAC;IAC7E,WAAWjB;IACX,cAAc;QAACkB;KAAiB;AACpC;AAEO,MAAMC,wCAAwCC,0BAA0B,eAAe,CAAC;IAC3F,WAAWf;IACX,cAAc;QAACa;KAAiB;AACpC;AAEO,MAAMG,+BAA+BC,iBAAiB,eAAe,CAAC;IACzE,WAAWhB;IACX,cAAc;QAACY;KAAiB;AACpC;AAEO,MAAMK,kCAAkCC,oBAAoB,eAAe,CAAC;IAC/E,WAAWd;IACX,cAAc;QAACQ;KAAiB;AACpC;AAEO,MAAMO,kCAAkCC,oBAAoB,eAAe,CAAC;IAC/E,WAAWf;IACX,cAAc;QAACO;QAAkBI;KAAiB;AACtD;AAEO,MAAMK,kCAAkCC,oBAAoB,eAAe,CAAC;IAC/E,WAAWb;IACX,cAAc;QAACG;QAAkBI;KAAiB;AACtD"}
@@ -0,0 +1,4 @@
1
+ export declare const FolderTypePermissionsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export { FolderTypePermissions } from "./abstractions.js";
2
+ export { FolderTypePermissionsFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { FolderTypePermissions } from "./abstractions.js";
2
+ export { FolderTypePermissionsFeature } from "./feature.js";
@@ -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
- while(currentFolder.parentId){
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,QA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C,YAAY,EAAE,GAAGD,mBAAmB,KAAK;QAC1Df,SAAS,IAAI,IAAIgB,aAAa,GAAG,CAACX,CAAAA,QAASC,oBAAoB,QAAQ,CAACD;QAExE,OAAOH,OAAO,EAAE,CAAC;YACbH;YACAC;QACJ;IACJ;IAEA,MAAc,gBACVW,MAAc,EACdZ,OAAiB,EACiC;QAClD,IAAIkB,gBAAgBN;QAEpB,MAAOM,cAAc,QAAQ,CAAE;YAC3B,MAAMC,eAAe,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAChD,IAAI,CAAC,WAAW,EAChBT,QAAQ,IAAI,CAACQ,cAAc,QAAQ,EAAE,QAAQ;YAGjD,IAAIC,aAAa,MAAM,IACnB,OAAOhB,OAAO,IAAI,CAAC,IAAIC,uBAAuBe,aAAa,KAAK;YAGpE,MAAMC,eAAeb,oBAAoB,QAAQ,CAACY,aAAa,KAAK;YACpEnB,QAAQ,IAAI,CAACoB;YACbF,gBAAgBE;QACpB;QAEA,OAAOjB,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMkB,4DAA+BC,6BAAAA,oBAA0C,CAAC;IACnF,gBAAgB3B;IAChB,cAAc;QAAC4B;QAAqBC;QAA0BC;KAAY;AAC9E"}
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":";;;;;;;;;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;QAI9D,IAAIC,OAAO,IAAI,KAAKb,OAAO,IAAI,EAC3B,OAAOI,OA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,KAAK;YAGpE,MAAMC,eAAehB,oBAAoB,QAAQ,CAACe,aAAa,KAAK;YAEpE,IAAIC,aAAa,IAAI,KAAKX,OAAO,IAAI,EACjC;YAEJZ,QAAQ,IAAI,CAACuB;YACbJ,gBAAgBI;QACpB;QAEA,OAAOpB,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMqB,4DAA+BC,6BAAAA,oBAA0C,CAAC;IACnF,gBAAgB9B;IAChB,cAAc;QAAC+B;QAAqBC;QAA0BC;KAAY;AAC9E"}
@@ -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 { FolderNotAuthorizedError, FolderPersistenceError } 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 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 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":";AAyBO,MAAMA,+BAA+BC,kBACxC;AAyBG,MAAMC,4BAA4BD,kBACrC"}
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: data.slug || original.slug,
27
- parentId: void 0 !== data.parentId ? data.parentId : original.parentId
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: data.slug || original.slug,
32
- parentId: void 0 !== data.parentId ? data.parentId : original.parentId
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
- ...data,
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, {
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/UpdateFolder/UpdateFolderRepository.js","sources":["../../../../src/features/folder/UpdateFolder/UpdateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n type IUpdateFolderRepository,\n UpdateFolderRepository as RepositoryAbstraction\n} from \"./abstractions.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, Folder, UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderPersistenceError, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { Path } from \"~/utils/Path.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\nclass UpdateFolderRepositoryImpl implements IUpdateFolderRepository {\n constructor(\n private updateEntry: UpdateEntryUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(\n id: string,\n data: UpdateFolderParams\n ): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n const entryId = EntryId.from(id);\n\n // Get the original folder\n const originalResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString()\n );\n\n if (originalResult.isFail()) {\n return Result.fail(new FolderPersistenceError(originalResult.error));\n }\n\n const original = EntryToFolderMapper.toFolder(originalResult.value);\n\n // Check if folder with new slug already exists\n const checkResult = await this.checkExistingFolder({\n id,\n type: original.type,\n slug: data.slug || original.slug,\n parentId: data.parentId !== undefined ? data.parentId : original.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create new path if slug or parentId changed\n const pathResult = await this.createFolderPath({\n slug: data.slug || original.slug,\n parentId: data.parentId !== undefined ? data.parentId : original.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n const result = await this.updateEntry.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString(),\n {\n values: {\n ...data,\n path: pathResult.value\n }\n }\n );\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const updatedFolder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(updatedFolder);\n }\n\n private async checkExistingFolder(params: {\n id: string;\n type: string;\n slug: string;\n parentId?: string | null;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const { id, type, slug, parentId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(this.folderModel, {\n where: {\n latest: true,\n entryId_not: id,\n values: {\n type,\n slug,\n parentId\n }\n },\n limit: 1\n });\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const { entries } = result.value;\n\n if (entries.length > 0) {\n return Result.fail(\n new FolderValidationError(\n `Folder with slug \"${slug}\" already exists at this level.`\n )\n );\n }\n\n return Result.ok();\n }\n\n private async createFolderPath(params: {\n slug: string;\n parentId?: string | null;\n }): Promise<Result<string, RepositoryAbstraction.Error>> {\n const { slug, parentId } = params;\n\n if (!parentId) {\n return Result.ok(Path.create(slug));\n }\n\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(\n new FolderPersistenceError(\n new Error(\"Parent folder not found. Unable to create the folder path\")\n )\n );\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n return Result.ok(Path.create(slug, parentFolder.path));\n }\n}\n\nexport const UpdateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateFolderRepositoryImpl,\n dependencies: [UpdateEntryUseCase, GetEntryByIdUseCase, ListLatestEntriesUseCase, FolderModel]\n});\n"],"names":["UpdateFolderRepositoryImpl","updateEntry","getEntryById","listLatestEntries","folderModel","id","data","entryId","EntryId","originalResult","Result","FolderPersistenceError","original","EntryToFolderMapper","checkResult","undefined","pathResult","result","updatedFolder","params","type","slug","parentId","entries","FolderValidationError","Path","parentResult","Error","parentFolder","Up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,MAAM;QAKtB,MAAMC,eAAef,oBAAoB,QAAQ,CAACa,aAAa,KAAK;QACpE,OAAOhB,OAAO,EAAE,CAACe,KAAK,MAAM,CAACJ,MAAMO,aAAa,IAAI;IACxD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgB9B;IAChB,cAAc;QAAC+B;QAAoBC;QAAqBC;QAA0BC;KAAY;AAClG"}
1
+ {"version":3,"file":"features/folder/UpdateFolder/UpdateFolderRepository.js","sources":["../../../../src/features/folder/UpdateFolder/UpdateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n type IUpdateFolderRepository,\n UpdateFolderRepository as RepositoryAbstraction\n} from \"./abstractions.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, Folder, UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderPersistenceError, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { Path } from \"~/utils/Path.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\nclass UpdateFolderRepositoryImpl implements IUpdateFolderRepository {\n constructor(\n private updateEntry: UpdateEntryUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(\n id: string,\n data: UpdateFolderParams\n ): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n const entryId = EntryId.from(id);\n\n // Get the original folder\n const originalResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString()\n );\n\n if (originalResult.isFail()) {\n return Result.fail(new FolderPersistenceError(originalResult.error));\n }\n\n const original = EntryToFolderMapper.toFolder(originalResult.value);\n\n // Security: `type` and `path` are never taken from the input. The GraphQL input accepts\n // them, but changing them would move the folder into another app or corrupt the tree.\n const input: UpdateFolderParams & Partial<Pick<Folder, \"type\" | \"path\">> = { ...data };\n delete input.type;\n delete input.path;\n\n if (input.parentId && input.parentId !== original.parentId) {\n const parentResult = await this.validateNewParent(original, input.parentId);\n if (parentResult.isFail()) {\n return Result.fail(parentResult.error);\n }\n }\n\n // Check if folder with new slug already exists\n const checkResult = await this.checkExistingFolder({\n id,\n type: original.type,\n slug: input.slug || original.slug,\n parentId: input.parentId !== undefined ? input.parentId : original.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create new path if slug or parentId changed\n const pathResult = await this.createFolderPath({\n slug: input.slug || original.slug,\n parentId: input.parentId !== undefined ? input.parentId : original.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n const result = await this.updateEntry.execute<CmsEntryFolder>(\n this.folderModel,\n entryId.toString(),\n {\n values: {\n ...input,\n path: pathResult.value\n }\n }\n );\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const updatedFolder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(updatedFolder);\n }\n\n /**\n * Security: the new parent must be a folder of the same type, and must not be the folder\n * itself or one of its descendants (that would create a cycle in the tree).\n */\n private async validateNewParent(\n folder: Folder,\n parentId: string\n ): Promise<Result<void, RepositoryAbstraction.Error>> {\n if (parentId === folder.id) {\n return Result.fail(new FolderValidationError(\"A folder cannot be its own parent.\"));\n }\n\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(parentId).toString()\n );\n if (parentResult.isFail()) {\n return Result.fail(new FolderValidationError(\"Parent folder not found.\"));\n }\n\n const parent = EntryToFolderMapper.toFolder(parentResult.value);\n if (parent.type !== folder.type) {\n return Result.fail(\n new FolderValidationError(\"Parent folder must be of the same type as the folder.\")\n );\n }\n\n // Walk up from the new parent: reaching the folder itself means a cycle.\n const visited = new Set<string>([parent.id]);\n let ancestorId = parent.parentId;\n while (ancestorId && !visited.has(ancestorId)) {\n if (ancestorId === folder.id) {\n return Result.fail(\n new FolderValidationError(\n \"A folder cannot be moved into one of its own subfolders.\"\n )\n );\n }\n visited.add(ancestorId);\n\n const ancestorResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(ancestorId).toString()\n );\n if (ancestorResult.isFail()) {\n break;\n }\n ancestorId = ancestorResult.value.values.parentId ?? null;\n }\n\n return Result.ok();\n }\n\n private async checkExistingFolder(params: {\n id: string;\n type: string;\n slug: string;\n parentId?: string | null;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const { id, type, slug, parentId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(this.folderModel, {\n where: {\n latest: true,\n entryId_not: id,\n values: {\n type,\n slug,\n parentId\n }\n },\n limit: 1\n });\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const { entries } = result.value;\n\n if (entries.length > 0) {\n return Result.fail(\n new FolderValidationError(\n `Folder with slug \"${slug}\" already exists at this level.`\n )\n );\n }\n\n return Result.ok();\n }\n\n private async createFolderPath(params: {\n slug: string;\n parentId?: string | null;\n }): Promise<Result<string, RepositoryAbstraction.Error>> {\n const { slug, parentId } = params;\n\n if (!parentId) {\n return Result.ok(Path.create(slug));\n }\n\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(\n new FolderPersistenceError(\n new Error(\"Parent folder not found. Unable to create the folder path\")\n )\n );\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n return Result.ok(Path.create(slug, parentFolder.path));\n }\n}\n\nexport const UpdateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateFolderRepositoryImpl,\n dependencies: [UpdateEntryUseCase, GetEntryByIdUseCase, ListLatestEntriesUseCase, FolderModel]\n});\n"],"names":["UpdateFolderRepositoryImpl","updateEntry","getEntryById","listLatestEntries","folderModel","id","data","entryId","EntryId","originalResult","Result","FolderPersistenceError","original","EntryToFolderMapper","input","parentResult","checkResult","undefined","pathResult","result","updatedFolder","folder","parentId","FolderValidationError","parent","visited","Set","ancestorId","ancestorResult","params","type","slug","entries","Path","Error","parentFolder","UpdateFolderRepository","RepositoryAbstraction","UpdateEntryUseCase","GetEntryByIdUseCase","ListLatestEntriesUseCase","FolderModel"],"mappings":";;;;;;;;;;AAeA,MAAMA;IACF,YACYC,WAAyC,EACzCC,YAA2C,EAC3CC,iBAAqD,EACrDC,WAAkC,CAC5C;aAJUH,WAAW,GAAXA;aACAC,YAAY,GAAZA;aACAC,iBAAiB,GAAjBA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,EAAU,EACVC,IAAwB,EAC4B;QACpD,MAAMC,UAAUC,QAAQ,IAAI,CAACH;QAG7B,MAAMI,iBAAiB,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAClD,IAAI,CAAC,WAAW,EAChBF,QAAQ,QAAQ;QAGpB,IAAIE,eAAe,MAAM,IACrB,OAAOC,OAAO,IAAI,CAAC,IAAIC,uBAAuBF,eAAe,KAAK;QAGtE,MAAMG,WAAWC,oBAAoB,QAAQ,CAACJ,eAAe,KAAK;QAIlE,MAAMK,QAAqE;YAAE,GAAGR,IAAI;QAAC;QACrF,OAAOQ,MAAM,IAAI;QACjB,OAAOA,MAAM,IAAI;QAEjB,IAAIA,MAAM,QAAQ,IAAIA,MAAM,QAAQ,KAAKF,SAAS,QAAQ,EAAE;YACxD,MAAMG,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAACH,UAAUE,MAAM,QAAQ;YAC1E,IAAIC,aAAa,MAAM,IACnB,OAAOL,OAA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+B,CAAC;QAKtE,OAAOrB,OAAO,EAAE;IACpB;IAEA,MAAc,iBAAiBmB,MAG9B,EAAwD;QACrD,MAAM,EAAEE,IAAI,EAAET,QAAQ,EAAE,GAAGO;QAE3B,IAAI,CAACP,UACD,OAAOZ,OAAO,EAAE,CAACuB,KAAK,MAAM,CAACF;QAGjC,MAAMhB,eAAe,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAChD,IAAI,CAAC,WAAW,EAChBP,QAAQ,IAAI,CAACc,UAAU,QAAQ;QAGnC,IAAIP,aAAa,MAAM,IACnB,OAAOL,OAAO,IAAI,CACd,IAAIC,uBACA,IAAIuB,MAAM;QAKtB,MAAMC,eAAetB,oBAAoB,QAAQ,CAACE,aAAa,KAAK;QACpE,OAAOL,OAAO,EAAE,CAACuB,KAAK,MAAM,CAACF,MAAMI,aAAa,IAAI;IACxD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgBrC;IAChB,cAAc;QAACsC;QAAoBC;QAAqBC;QAA0BC;KAAY;AAClG"}
@@ -7,7 +7,7 @@ declare class UpdateFolderWithFolderLevelPermissionsImpl implements UpdateFolder
7
7
  private folderLevelPermissions;
8
8
  private readonly decoretee;
9
9
  constructor(getFolder: GetFolderUseCase.Interface, folderLevelPermissions: FolderLevelPermissions.Interface, decoretee: UpdateFolderUseCase.Interface);
10
- execute(id: string, params: UpdateFolderParams): UpdateFolderUseCase.Return;
10
+ execute(id: string, input: UpdateFolderParams): UpdateFolderUseCase.Return;
11
11
  }
12
12
  export declare const UpdateFolderWithFolderLevelPermissions: typeof UpdateFolderWithFolderLevelPermissionsImpl;
13
13
  export {};
@@ -3,13 +3,22 @@ import { FolderLevelPermissions } from "../../../flp/FolderLevelPermissions/inde
3
3
  import { UpdateFolderUseCase } from "../abstractions.js";
4
4
  import { GetFolderUseCase } from "../../GetFolder/index.js";
5
5
  import { FolderCannotMoveToNewParent, FolderValidationError } from "../../../../domain/folder/errors.js";
6
+ import { validatePermissionsInput } from "../../shared/validatePermissionsInput.js";
7
+ const permissionsChanged = (original, updated)=>{
8
+ const normalize = (permissions)=>permissions.map((permission)=>`${permission.target}=${permission.level}`).sort().join(",");
9
+ return normalize(original.filter((permission)=>!permission.inheritedFrom)) !== normalize(updated);
10
+ };
6
11
  class UpdateFolderWithFolderLevelPermissionsImpl {
7
12
  constructor(getFolder, folderLevelPermissions, decoretee){
8
13
  this.getFolder = getFolder;
9
14
  this.folderLevelPermissions = folderLevelPermissions;
10
15
  this.decoretee = decoretee;
11
16
  }
12
- async execute(id, params) {
17
+ async execute(id, input) {
18
+ const params = null === input.permissions ? {
19
+ ...input,
20
+ permissions: []
21
+ } : input;
13
22
  const originalResult = await this.getFolder.execute(id);
14
23
  if (originalResult.isFail()) return Result.fail(originalResult.error);
15
24
  const original = originalResult.value;
@@ -18,16 +27,23 @@ class UpdateFolderWithFolderLevelPermissionsImpl {
18
27
  permissions: originalPermissions,
19
28
  rwd: "w"
20
29
  });
30
+ if (Array.isArray(params.permissions) && permissionsChanged(originalPermissions, params.permissions) && !await this.folderLevelPermissions.canManageFolderPermissions({
31
+ id: original.id,
32
+ parentId: original.parentId ?? "",
33
+ slug: original.slug,
34
+ path: original.path,
35
+ type: original.type,
36
+ permissions: originalPermissions
37
+ })) return Result.fail(new FolderValidationError("Not allowed to change the folder permissions."));
21
38
  const permissions = await this.folderLevelPermissions.getDefaultPermissions(params.permissions ?? []);
22
39
  const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({
23
40
  permissions,
24
41
  rwd: "w"
25
42
  });
26
43
  if (!stillHasAccess) return Result.fail(new FolderValidationError("Cannot continue because you would loose access to this folder."));
27
- if (Array.isArray(params.permissions)) for (const permission of params.permissions){
28
- const targetIsValid = permission.target.startsWith("admin:") || permission.target.startsWith("team:");
29
- if (!targetIsValid) return Result.fail(new FolderValidationError(`Permission target "${permission.target}" is not valid.`));
30
- if (permission.inheritedFrom) return Result.fail(new FolderValidationError('Permission "inheritedFrom" cannot be set manually.'));
44
+ if (Array.isArray(params.permissions)) {
45
+ const validationError = validatePermissionsInput(params.permissions);
46
+ if (validationError) return Result.fail(validationError);
31
47
  }
32
48
  if (params.parentId && params.parentId !== original.parentId) {
33
49
  const parentPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(params.parentId);
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport type { UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { UpdateFolderUseCase } from \"../abstractions.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { FolderCannotMoveToNewParent, FolderValidationError } from \"~/domain/folder/errors.js\";\n\nclass UpdateFolderWithFolderLevelPermissionsImpl implements UpdateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: UpdateFolderUseCase.Interface;\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n folderLevelPermissions: FolderLevelPermissions.Interface,\n decoretee: UpdateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.decoretee = decoretee;\n }\n\n async execute(id: string, params: UpdateFolderParams): UpdateFolderUseCase.Return {\n const originalResult = await this.getFolder.execute(id);\n\n if (originalResult.isFail()) {\n return Result.fail(originalResult.error);\n }\n\n const original = originalResult.value;\n\n const originalPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(id);\n\n // Let's ensure current identity's permission allows the update operation.\n await this.folderLevelPermissions.ensureCanAccessFolder({\n permissions: originalPermissions,\n rwd: \"w\"\n });\n\n const permissions = await this.folderLevelPermissions.getDefaultPermissions(\n params.permissions ?? []\n );\n\n // Check if the user still has access to the folder with the provided permissions.\n const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({\n permissions,\n rwd: \"w\"\n });\n\n if (!stillHasAccess) {\n return Result.fail(\n new FolderValidationError(\n `Cannot continue because you would loose access to this folder.`\n )\n );\n }\n\n // Validate data.\n if (Array.isArray(params.permissions)) {\n for (const permission of params.permissions) {\n const targetIsValid =\n permission.target.startsWith(\"admin:\") || permission.target.startsWith(\"team:\");\n if (!targetIsValid) {\n return Result.fail(\n new FolderValidationError(\n `Permission target \"${permission.target}\" is not valid.`\n )\n );\n }\n\n if (permission.inheritedFrom) {\n return Result.fail(\n new FolderValidationError(\n `Permission \"inheritedFrom\" cannot be set manually.`\n )\n );\n }\n }\n }\n\n // Parent change is not allowed if the user doesn't have access to the new parent.\n if (params.parentId && params.parentId !== original.parentId) {\n // Getting the parent folder permissions will throw an error if the user doesn't have access.\n const parentPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(\n params.parentId\n );\n\n const canAccessFolder = await this.folderLevelPermissions.canAccessFolder({\n permissions: parentPermissions,\n rwd: \"w\"\n });\n\n if (!canAccessFolder) {\n return Result.fail(new FolderCannotMoveToNewParent());\n }\n }\n\n const result = await this.decoretee.execute(id, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok({\n ...result.value,\n permissions\n });\n }\n}\n\nexport const UpdateFolderWithFolderLevelPermissions = createDecorator({\n abstraction: UpdateFolderUseCase,\n decorator: UpdateFolderWithFolderLevelPermissionsImpl,\n dependencies: [GetFolderUseCase, FolderLevelPermissions]\n});\n"],"names":["UpdateFolderWithFolderLevelPermissionsImpl","getFolder","folderLevelPermissions","decoretee","id","params","originalResult","Result","original","originalPermissions","permissions","stillHasAccess","FolderValidationError","Array","permission","targetIsValid","parentPermissions","canAccessFolder","FolderCannotMoveToNewParent","result","UpdateFolderWithFolderLevelPermissions","createDecorator","UpdateFolderUseCase","GetFolderUseCase","FolderLevelPermissions"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACYC,SAAqC,EA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C,yBAAyB,CACjFX,OAAO,QAAQ;YAGnB,MAAMY,kBAAkB,MAAM,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC;gBACtE,aAAaD;gBACb,KAAK;YACT;YAEA,IAAI,CAACC,iBACD,OAAOV,OAAO,IAAI,CAAC,IAAIW;QAE/B;QAEA,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACf,IAAIC;QAEhD,IAAIc,OAAO,MAAM,IACb,OAAOZ,OAAO,IAAI,CAACY,OAAO,KAAK;QAGnC,OAAOZ,OAAO,EAAE,CAAC;YACb,GAAGY,OAAO,KAAK;YACfT;QACJ;IACJ;AACJ;AAEO,MAAMU,yCAAyCC,gBAAgB;IAClE,aAAaC;IACb,WAAWtB;IACX,cAAc;QAACuB;QAAkBC;KAAuB;AAC5D"}
1
+ {"version":3,"file":"features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport type { UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport type { FolderPermission } from \"~/types.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { UpdateFolderUseCase } from \"../abstractions.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { FolderCannotMoveToNewParent, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { validatePermissionsInput } from \"~/features/folder/shared/validatePermissionsInput.js\";\n\n/**\n * Compares the folder's own (non-inherited) permissions. The admin app sends the current\n * permissions with every update, e.g. a rename.\n */\nconst permissionsChanged = (\n original: FolderPermission[],\n updated: Pick<FolderPermission, \"target\" | \"level\">[]\n) => {\n const normalize = (permissions: Pick<FolderPermission, \"target\" | \"level\">[]) => {\n return permissions\n .map(permission => `${permission.target}=${permission.level}`)\n .sort()\n .join(\",\");\n };\n return (\n normalize(original.filter(permission => !permission.inheritedFrom)) !== normalize(updated)\n );\n};\n\nclass UpdateFolderWithFolderLevelPermissionsImpl implements UpdateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: UpdateFolderUseCase.Interface;\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n folderLevelPermissions: FolderLevelPermissions.Interface,\n decoretee: UpdateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.decoretee = decoretee;\n }\n\n async execute(id: string, input: UpdateFolderParams): UpdateFolderUseCase.Return {\n /* GraphQL accepts `permissions: null`. Treat it as \"no own permissions\" so it goes\n through the same owner check as an empty list, instead of skipping the check and\n wiping the folder's permissions. */\n const params: UpdateFolderParams =\n input.permissions === null ? { ...input, permissions: [] } : input;\n\n const originalResult = await this.getFolder.execute(id);\n\n if (originalResult.isFail()) {\n return Result.fail(originalResult.error);\n }\n\n const original = originalResult.value;\n\n const originalPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(id);\n\n // Let's ensure current identity's permission allows the update operation.\n await this.folderLevelPermissions.ensureCanAccessFolder({\n permissions: originalPermissions,\n rwd: \"w\"\n });\n\n // Changing who has access to the folder requires the \"owner\" level.\n if (\n Array.isArray(params.permissions) &&\n permissionsChanged(originalPermissions, params.permissions) &&\n !(await this.folderLevelPermissions.canManageFolderPermissions({\n id: original.id,\n parentId: original.parentId ?? \"\",\n slug: original.slug,\n path: original.path,\n type: original.type,\n permissions: originalPermissions\n }))\n ) {\n return Result.fail(\n new FolderValidationError(`Not allowed to change the folder permissions.`)\n );\n }\n\n const permissions = await this.folderLevelPermissions.getDefaultPermissions(\n params.permissions ?? []\n );\n\n // Check if the user still has access to the folder with the provided permissions.\n const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({\n permissions,\n rwd: \"w\"\n });\n\n if (!stillHasAccess) {\n return Result.fail(\n new FolderValidationError(\n `Cannot continue because you would loose access to this folder.`\n )\n );\n }\n\n // Validate data.\n if (Array.isArray(params.permissions)) {\n const validationError = validatePermissionsInput(params.permissions);\n if (validationError) {\n return Result.fail(validationError);\n }\n }\n\n // Parent change is not allowed if the user doesn't have access to the new parent.\n if (params.parentId && params.parentId !== original.parentId) {\n // Getting the parent folder permissions will throw an error if the user doesn't have access.\n const parentPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(\n params.parentId\n );\n\n const canAccessFolder = await this.folderLevelPermissions.canAccessFolder({\n permissions: parentPermissions,\n rwd: \"w\"\n });\n\n if (!canAccessFolder) {\n return Result.fail(new FolderCannotMoveToNewParent());\n }\n }\n\n const result = await this.decoretee.execute(id, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok({\n ...result.value,\n permissions\n });\n }\n}\n\nexport const UpdateFolderWithFolderLevelPermissions = createDecorator({\n abstraction: UpdateFolderUseCase,\n decorator: UpdateFolderWithFolderLevelPermissionsImpl,\n dependencies: [GetFolderUseCase, FolderLevelPermissions]\n});\n"],"names":["permissionsChanged","original","updated","normalize","permissions","permission","UpdateFolderWithFolderLevelPermissionsImpl","getFolder","folderLevelPermissions","decoretee","id","input","params","originalResult","Result","originalPermissions","Array","FolderValidationError","stillHasAccess","validationError","validatePermissionsInput","parentPermissions","canAccessFolder","FolderCannotMoveToNewParent","result","UpdateFolderWithFolderLevelPermissions","createDecorator","UpdateFolderUseCase","GetFolderUseCase","FolderLevelPermissions"],"mappings":";;;;;;AAaA,MAAMA,qBAAqB,CACvBC,UACAC;IAEA,MAAMC,YAAY,CAACC,cACRA,YACF,GAAG,CAACC,CAAAA,aAAc,GAAGA,WAAW,MAAM,CAAC,CAAC,EAAEA,WAAW,KAAK,EAAE,EAC5D,IAAI,GACJ,IAAI,CAAC;IAEd,OACIF,UAAUF,SAAS,MAAM,CAACI,CAAAA,aAAc,CAACA,WAAW,aAAa,OAAOF,UAAUD;AAE1F;AAEA,MAAMI;IAIF,YACYC,SAAqC,EAC7CC,sBAAwD,EACxDC,SAAwC,CAC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