@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.
- package/createAcoContext.js +2 -0
- package/createAcoContext.js.map +1 -1
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js +55 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js +38 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.d.ts +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js +9 -5
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/canAccessEntryFolder.d.ts +21 -0
- package/features/cms/decorators/canAccessEntryFolder.js +25 -0
- package/features/cms/decorators/canAccessEntryFolder.js.map +1 -0
- package/features/cms/feature.js +20 -0
- package/features/cms/feature.js.map +1 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js +4 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js.map +1 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js +3 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js +20 -2
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +1 -5
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
- package/features/folder/FolderTypePermissions/FolderTypeAccess.d.ts +11 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js +28 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js.map +1 -0
- package/features/folder/FolderTypePermissions/abstractions.d.ts +23 -0
- package/features/folder/FolderTypePermissions/abstractions.js +6 -0
- package/features/folder/FolderTypePermissions/abstractions.js.map +1 -0
- package/features/folder/FolderTypePermissions/decorators.d.ts +67 -0
- package/features/folder/FolderTypePermissions/decorators.js +128 -0
- package/features/folder/FolderTypePermissions/decorators.js.map +1 -0
- package/features/folder/FolderTypePermissions/feature.d.ts +4 -0
- package/features/folder/FolderTypePermissions/feature.js +18 -0
- package/features/folder/FolderTypePermissions/feature.js.map +1 -0
- package/features/folder/FolderTypePermissions/index.d.ts +2 -0
- package/features/folder/FolderTypePermissions/index.js +2 -0
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +8 -2
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
- package/features/folder/GetFolderHierarchy/abstractions.d.ts +3 -1
- package/features/folder/GetFolderHierarchy/abstractions.js.map +1 -1
- package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +5 -0
- package/features/folder/UpdateFolder/UpdateFolderRepository.js +33 -5
- package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +21 -5
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/shared/validatePermissionsInput.d.ts +7 -0
- package/features/folder/shared/validatePermissionsInput.js +12 -0
- package/features/folder/shared/validatePermissionsInput.js.map +1 -0
- package/filter/filter.so.js +12 -5
- package/filter/filter.so.js.map +1 -1
- package/filter/filter.types.js.map +1 -1
- package/folder/folder.gql.js +4 -0
- package/folder/folder.gql.js.map +1 -1
- package/folder/validation.d.ts +8 -0
- package/folder/validation.js +7 -0
- package/folder/validation.js.map +1 -0
- package/package.json +23 -22
- package/types.js.map +1 -1
|
@@ -9,6 +9,7 @@ declare class UpdateEntryWithFlpDecoratorImpl implements UpdateEntryUseCase.Inte
|
|
|
9
9
|
private decoratee;
|
|
10
10
|
constructor(folderLevelPermissions: FolderLevelPermissions.Interface, getRevisionById: GetRevisionByIdUseCase.Interface, decoratee: UpdateEntryUseCase.Interface);
|
|
11
11
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string, input: UpdateCmsEntryInput<T>, options?: UpdateCmsEntryOptionsInput): Promise<Result<CmsEntry<T>, UpdateEntryUseCase.Error>>;
|
|
12
|
+
private canWriteToFolder;
|
|
12
13
|
}
|
|
13
14
|
export declare const UpdateEntryWithFlpDecorator: typeof UpdateEntryWithFlpDecoratorImpl;
|
|
14
15
|
export {};
|
|
@@ -15,15 +15,19 @@ class UpdateEntryWithFlpDecoratorImpl {
|
|
|
15
15
|
const entryResult = await this.getRevisionById.execute(model, id);
|
|
16
16
|
if (entryResult.isFail()) return this.decoratee.execute(model, id, input, options);
|
|
17
17
|
const entry = entryResult.value;
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
18
|
+
const currentFolderId = entry?.location?.folderId || ROOT_FOLDER;
|
|
19
|
+
if (!await this.canWriteToFolder(currentFolderId)) return Result.fail(new EntryNotAuthorizedError());
|
|
20
|
+
const targetFolderId = input.wbyAco_location?.folderId;
|
|
21
|
+
if (targetFolderId && targetFolderId !== currentFolderId && !await this.canWriteToFolder(targetFolderId)) return Result.fail(new EntryNotAuthorizedError());
|
|
22
|
+
return this.decoratee.execute(model, id, input, options);
|
|
23
|
+
}
|
|
24
|
+
async canWriteToFolder(folderId) {
|
|
25
|
+
if (folderId === ROOT_FOLDER) return true;
|
|
20
26
|
const permissions = await this.folderLevelPermissions.getFolderLevelPermissions(folderId);
|
|
21
|
-
|
|
27
|
+
return this.folderLevelPermissions.canAccessFolderContent({
|
|
22
28
|
permissions,
|
|
23
29
|
rwd: "w"
|
|
24
30
|
});
|
|
25
|
-
if (!canAccessFolder) return Result.fail(new EntryNotAuthorizedError());
|
|
26
|
-
return this.decoratee.execute(model, id, input, options);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
const UpdateEntryWithFlpDecorator = createDecorator({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/cms/decorators/UpdateEntryWithFlpDecorator.js","sources":["../../../../src/features/cms/decorators/UpdateEntryWithFlpDecorator.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\n\nclass UpdateEntryWithFlpDecoratorImpl implements UpdateEntryUseCase.Interface {\n constructor(\n private folderLevelPermissions: FolderLevelPermissions.Interface,\n private getRevisionById: GetRevisionByIdUseCase.Interface,\n private decoratee: UpdateEntryUseCase.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n input: UpdateCmsEntryInput<T>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<Result<CmsEntry<T>, UpdateEntryUseCase.Error>> {\n if (!this.folderLevelPermissions.canUseFolderLevelPermissions()) {\n return this.decoratee.execute(model, id, input, options);\n }\n\n const entryResult = await this.getRevisionById.execute(model, id);\n if (entryResult.isFail()) {\n return this.decoratee.execute(model, id, input, options);\n }\n\n const entry = entryResult.value;\n const
|
|
1
|
+
{"version":3,"file":"features/cms/decorators/UpdateEntryWithFlpDecorator.js","sources":["../../../../src/features/cms/decorators/UpdateEntryWithFlpDecorator.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\n\nclass UpdateEntryWithFlpDecoratorImpl implements UpdateEntryUseCase.Interface {\n constructor(\n private folderLevelPermissions: FolderLevelPermissions.Interface,\n private getRevisionById: GetRevisionByIdUseCase.Interface,\n private decoratee: UpdateEntryUseCase.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n input: UpdateCmsEntryInput<T>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<Result<CmsEntry<T>, UpdateEntryUseCase.Error>> {\n if (!this.folderLevelPermissions.canUseFolderLevelPermissions()) {\n return this.decoratee.execute(model, id, input, options);\n }\n\n const entryResult = await this.getRevisionById.execute(model, id);\n if (entryResult.isFail()) {\n return this.decoratee.execute(model, id, input, options);\n }\n\n const entry = entryResult.value;\n const currentFolderId = entry?.location?.folderId || ROOT_FOLDER;\n\n if (!(await this.canWriteToFolder(currentFolderId))) {\n return Result.fail(new EntryNotAuthorizedError());\n }\n\n // Updating the location moves the entry: the destination folder must allow it too.\n const targetFolderId = input.wbyAco_location?.folderId;\n if (\n targetFolderId &&\n targetFolderId !== currentFolderId &&\n !(await this.canWriteToFolder(targetFolderId))\n ) {\n return Result.fail(new EntryNotAuthorizedError());\n }\n\n return this.decoratee.execute<T>(model, id, input, options);\n }\n\n private async canWriteToFolder(folderId: string): Promise<boolean> {\n if (folderId === ROOT_FOLDER) {\n return true;\n }\n\n const permissions = await this.folderLevelPermissions.getFolderLevelPermissions(folderId);\n return this.folderLevelPermissions.canAccessFolderContent({ permissions, rwd: \"w\" });\n }\n}\n\nexport const UpdateEntryWithFlpDecorator = createDecorator({\n abstraction: UpdateEntryUseCase,\n decorator: UpdateEntryWithFlpDecoratorImpl,\n dependencies: [FolderLevelPermissions, GetRevisionByIdUseCase]\n});\n"],"names":["UpdateEntryWithFlpDecoratorImpl","folderLevelPermissions","getRevisionById","decoratee","model","id","input","options","entryResult","entry","currentFolderId","ROOT_FOLDER","Result","EntryNotAuthorizedError","targetFolderId","folderId","permissions","UpdateEntryWithFlpDecorator","createDecorator","UpdateEntryUseCase","FolderLevelPermissions","GetRevisionByIdUseCase"],"mappings":";;;;;;AAcA,MAAMA;IACF,YACYC,sBAAwD,EACxDC,eAAiD,EACjDC,SAAuC,CACjD;aAHUF,sBAAsB,GAAtBA;aACAC,eAAe,GAAfA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,EAAU,EACVC,KAA6B,EAC7BC,OAAoC,EACkB;QACtD,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,4BAA4B,IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH,OAAOC,IAAIC,OAAOC;QAGpD,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ,OAAOC;QAC9D,IAAIG,YAAY,MAAM,IAClB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACJ,OAAOC,IAAIC,OAAOC;QAGpD,MAAME,QAAQD,YAAY,KAAK;QAC/B,MAAME,kBAAkBD,OAAO,UAAU,YAAYE;QAErD,IAAI,CAAE,MAAM,IAAI,CAAC,gBAAgB,CAACD,kBAC9B,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,iBAAiBR,MAAM,eAAe,EAAE;QAC9C,IACIQ,kBACAA,mBAAmBJ,mBACnB,CAAE,MAAM,IAAI,CAAC,gBAAgB,CAACI,iBAE9B,OAAOF,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAIT,OAAOC,IAAIC,OAAOC;IACvD;IAEA,MAAc,iBAAiBQ,QAAgB,EAAoB;QAC/D,IAAIA,aAAaJ,aACb,OAAO;QAGX,MAAMK,cAAc,MAAM,IAAI,CAAC,sBAAsB,CAAC,yBAAyB,CAACD;QAChF,OAAO,IAAI,CAAC,sBAAsB,CAAC,sBAAsB,CAAC;YAAEC;YAAa,KAAK;QAAI;IACtF;AACJ;AAEO,MAAMC,8BAA8BC,gBAAgB;IACvD,aAAaC;IACb,WAAWnB;IACX,cAAc;QAACoB;QAAwBC;KAAuB;AAClE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UpdateRevisionDescriptionUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateRevisionDescription/abstractions.js";
|
|
2
|
+
import { GetRevisionByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js";
|
|
3
|
+
import type { CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
import { FolderLevelPermissions } from "../../../features/flp/FolderLevelPermissions/index.js";
|
|
5
|
+
/** Security: changing the revision description requires write access to the entry's folder. */
|
|
6
|
+
declare class UpdateRevisionDescriptionWithFlpDecoratorImpl implements UpdateRevisionDescriptionUseCase.Interface {
|
|
7
|
+
private folderLevelPermissions;
|
|
8
|
+
private getRevisionById;
|
|
9
|
+
private decoratee;
|
|
10
|
+
constructor(folderLevelPermissions: FolderLevelPermissions.Interface, getRevisionById: GetRevisionByIdUseCase.Interface, decoratee: UpdateRevisionDescriptionUseCase.Interface);
|
|
11
|
+
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string, revisionDescription: string | undefined): UpdateRevisionDescriptionUseCase.Return<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare const UpdateRevisionDescriptionWithFlpDecorator: typeof UpdateRevisionDescriptionWithFlpDecoratorImpl;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Result, createDecorator } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateRevisionDescriptionUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateRevisionDescription/abstractions.js";
|
|
3
|
+
import { GetRevisionByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js";
|
|
4
|
+
import { FolderLevelPermissions } from "../../flp/FolderLevelPermissions/index.js";
|
|
5
|
+
import { checkRevisionFolderWriteAccess } from "./canAccessEntryFolder.js";
|
|
6
|
+
class UpdateRevisionDescriptionWithFlpDecoratorImpl {
|
|
7
|
+
constructor(folderLevelPermissions, getRevisionById, decoratee){
|
|
8
|
+
this.folderLevelPermissions = folderLevelPermissions;
|
|
9
|
+
this.getRevisionById = getRevisionById;
|
|
10
|
+
this.decoratee = decoratee;
|
|
11
|
+
}
|
|
12
|
+
async execute(model, id, revisionDescription) {
|
|
13
|
+
if (this.folderLevelPermissions.canUseFolderLevelPermissions()) {
|
|
14
|
+
const error = await checkRevisionFolderWriteAccess(this.folderLevelPermissions, this.getRevisionById, model, id);
|
|
15
|
+
if (error) return Result.fail(error);
|
|
16
|
+
}
|
|
17
|
+
return this.decoratee.execute(model, id, revisionDescription);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const UpdateRevisionDescriptionWithFlpDecorator = createDecorator({
|
|
21
|
+
abstraction: UpdateRevisionDescriptionUseCase,
|
|
22
|
+
decorator: UpdateRevisionDescriptionWithFlpDecoratorImpl,
|
|
23
|
+
dependencies: [
|
|
24
|
+
FolderLevelPermissions,
|
|
25
|
+
GetRevisionByIdUseCase
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
export { UpdateRevisionDescriptionWithFlpDecorator };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=UpdateRevisionDescriptionWithFlpDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js","sources":["../../../../src/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport { UpdateRevisionDescriptionUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateRevisionDescription/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js\";\nimport type { CmsEntryValues, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { checkRevisionFolderWriteAccess } from \"./canAccessEntryFolder.js\";\n\n/** Security: changing the revision description requires write access to the entry's folder. */\nclass UpdateRevisionDescriptionWithFlpDecoratorImpl\n implements UpdateRevisionDescriptionUseCase.Interface\n{\n constructor(\n private folderLevelPermissions: FolderLevelPermissions.Interface,\n private getRevisionById: GetRevisionByIdUseCase.Interface,\n private decoratee: UpdateRevisionDescriptionUseCase.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n revisionDescription: string | undefined\n ): UpdateRevisionDescriptionUseCase.Return<T> {\n if (this.folderLevelPermissions.canUseFolderLevelPermissions()) {\n const error = await checkRevisionFolderWriteAccess(\n this.folderLevelPermissions,\n this.getRevisionById,\n model,\n id\n );\n if (error) {\n return Result.fail(error);\n }\n }\n\n return this.decoratee.execute<T>(model, id, revisionDescription);\n }\n}\n\nexport const UpdateRevisionDescriptionWithFlpDecorator = createDecorator({\n abstraction: UpdateRevisionDescriptionUseCase,\n decorator: UpdateRevisionDescriptionWithFlpDecoratorImpl,\n dependencies: [FolderLevelPermissions, GetRevisionByIdUseCase]\n});\n"],"names":["UpdateRevisionDescriptionWithFlpDecoratorImpl","folderLevelPermissions","getRevisionById","decoratee","model","id","revisionDescription","error","checkRevisionFolderWriteAccess","Result","UpdateRevisionDescriptionWithFlpDecorator","createDecorator","UpdateRevisionDescriptionUseCase","FolderLevelPermissions","GetRevisionByIdUseCase"],"mappings":";;;;;AAQA,MAAMA;IAGF,YACYC,sBAAwD,EACxDC,eAAiD,EACjDC,SAAqD,CAC/D;aAHUF,sBAAsB,GAAtBA;aACAC,eAAe,GAAfA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,EAAU,EACVC,mBAAuC,EACG;QAC1C,IAAI,IAAI,CAAC,sBAAsB,CAAC,4BAA4B,IAAI;YAC5D,MAAMC,QAAQ,MAAMC,+BAChB,IAAI,CAAC,sBAAsB,EAC3B,IAAI,CAAC,eAAe,EACpBJ,OACAC;YAEJ,IAAIE,OACA,OAAOE,OAAO,IAAI,CAACF;QAE3B;QAEA,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAIH,OAAOC,IAAIC;IAChD;AACJ;AAEO,MAAMI,4CAA4CC,gBAAgB;IACrE,aAAaC;IACb,WAAWZ;IACX,cAAc;QAACa;QAAwBC;KAAuB;AAClE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { GetRevisionByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js";
|
|
3
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
4
|
+
import type { FolderLevelPermissions } from "../../../features/flp/FolderLevelPermissions/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Checks folder level permissions for the content of the given folder.
|
|
7
|
+
* Entries without a folder, or in the root folder, are not restricted.
|
|
8
|
+
*/
|
|
9
|
+
export declare const canAccessEntryFolder: (folderLevelPermissions: FolderLevelPermissions.Interface, folderId: string | null | undefined, rwd: "r" | "w" | "d") => Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Removes entries located in folders the identity cannot read.
|
|
12
|
+
*/
|
|
13
|
+
export declare const filterEntriesByFolderAccess: <T extends Pick<CmsEntry, "location">>(folderLevelPermissions: FolderLevelPermissions.Interface, entries: T[]) => Promise<T[]>;
|
|
14
|
+
export declare const isNotAuthorizedError: (error: {
|
|
15
|
+
code?: string;
|
|
16
|
+
}) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Loads a revision and checks write access to its folder. Returns an error when access is
|
|
19
|
+
* denied; `null` when the operation may continue (a missing revision is left to the decoratee).
|
|
20
|
+
*/
|
|
21
|
+
export declare const checkRevisionFolderWriteAccess: (folderLevelPermissions: FolderLevelPermissions.Interface, getRevisionById: GetRevisionByIdUseCase.Interface, model: CmsModel, id: string) => Promise<EntryNotAuthorizedError | null>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
2
|
+
import { ROOT_FOLDER } from "../../../constants.js";
|
|
3
|
+
const canAccessEntryFolder = async (folderLevelPermissions, folderId, rwd)=>{
|
|
4
|
+
if (!folderId || folderId === ROOT_FOLDER) return true;
|
|
5
|
+
const permissions = await folderLevelPermissions.getFolderLevelPermissions(folderId);
|
|
6
|
+
return folderLevelPermissions.canAccessFolderContent({
|
|
7
|
+
permissions,
|
|
8
|
+
rwd
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const filterEntriesByFolderAccess = async (folderLevelPermissions, entries)=>{
|
|
12
|
+
const permitted = await Promise.all(entries.map((entry)=>canAccessEntryFolder(folderLevelPermissions, entry.location?.folderId, "r")));
|
|
13
|
+
return entries.filter((_, index)=>permitted[index]);
|
|
14
|
+
};
|
|
15
|
+
const isNotAuthorizedError = (error)=>"Cms/Entry/NotAuthorized" === error.code;
|
|
16
|
+
const checkRevisionFolderWriteAccess = async (folderLevelPermissions, getRevisionById, model, id)=>{
|
|
17
|
+
const entryResult = await getRevisionById.execute(model, id);
|
|
18
|
+
if (entryResult.isFail()) return isNotAuthorizedError(entryResult.error) ? new EntryNotAuthorizedError() : null;
|
|
19
|
+
const folderId = entryResult.value.location?.folderId;
|
|
20
|
+
if (!await canAccessEntryFolder(folderLevelPermissions, folderId, "w")) return new EntryNotAuthorizedError();
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
export { canAccessEntryFolder, checkRevisionFolderWriteAccess, filterEntriesByFolderAccess, isNotAuthorizedError };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=canAccessEntryFolder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/cms/decorators/canAccessEntryFolder.js","sources":["../../../../src/features/cms/decorators/canAccessEntryFolder.ts"],"sourcesContent":["import type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { GetRevisionByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetRevisionById/abstractions.js\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport type { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\n\n/**\n * Checks folder level permissions for the content of the given folder.\n * Entries without a folder, or in the root folder, are not restricted.\n */\nexport const canAccessEntryFolder = async (\n folderLevelPermissions: FolderLevelPermissions.Interface,\n folderId: string | null | undefined,\n rwd: \"r\" | \"w\" | \"d\"\n): Promise<boolean> => {\n if (!folderId || folderId === ROOT_FOLDER) {\n return true;\n }\n\n const permissions = await folderLevelPermissions.getFolderLevelPermissions(folderId);\n return folderLevelPermissions.canAccessFolderContent({ permissions, rwd });\n};\n\n/**\n * Removes entries located in folders the identity cannot read.\n */\nexport const filterEntriesByFolderAccess = async <T extends Pick<CmsEntry, \"location\">>(\n folderLevelPermissions: FolderLevelPermissions.Interface,\n entries: T[]\n): Promise<T[]> => {\n const permitted = await Promise.all(\n entries.map(entry =>\n canAccessEntryFolder(folderLevelPermissions, entry.location?.folderId, \"r\")\n )\n );\n return entries.filter((_, index) => permitted[index]);\n};\n\nexport const isNotAuthorizedError = (error: { code?: string }): boolean => {\n return error.code === \"Cms/Entry/NotAuthorized\";\n};\n\n/**\n * Loads a revision and checks write access to its folder. Returns an error when access is\n * denied; `null` when the operation may continue (a missing revision is left to the decoratee).\n */\nexport const checkRevisionFolderWriteAccess = async (\n folderLevelPermissions: FolderLevelPermissions.Interface,\n getRevisionById: GetRevisionByIdUseCase.Interface,\n model: CmsModel,\n id: string\n): Promise<EntryNotAuthorizedError | null> => {\n const entryResult = await getRevisionById.execute(model, id);\n if (entryResult.isFail()) {\n return isNotAuthorizedError(entryResult.error) ? new EntryNotAuthorizedError() : null;\n }\n\n const folderId = entryResult.value.location?.folderId;\n if (!(await canAccessEntryFolder(folderLevelPermissions, folderId, \"w\"))) {\n return new EntryNotAuthorizedError();\n }\n\n return null;\n};\n"],"names":["canAccessEntryFolder","folderLevelPermissions","folderId","rwd","ROOT_FOLDER","permissions","filterEntriesByFolderAccess","entries","permitted","Promise","entry","_","index","isNotAuthorizedError","error","checkRevisionFolderWriteAccess","getRevisionById","model","id","entryResult","EntryNotAuthorizedError"],"mappings":";;AAUO,MAAMA,uBAAuB,OAChCC,wBACAC,UACAC;IAEA,IAAI,CAACD,YAAYA,aAAaE,aAC1B,OAAO;IAGX,MAAMC,cAAc,MAAMJ,uBAAuB,yBAAyB,CAACC;IAC3E,OAAOD,uBAAuB,sBAAsB,CAAC;QAAEI;QAAaF;IAAI;AAC5E;AAKO,MAAMG,8BAA8B,OACvCL,wBACAM;IAEA,MAAMC,YAAY,MAAMC,QAAQ,GAAG,CAC/BF,QAAQ,GAAG,CAACG,CAAAA,QACRV,qBAAqBC,wBAAwBS,MAAM,QAAQ,EAAE,UAAU;IAG/E,OAAOH,QAAQ,MAAM,CAAC,CAACI,GAAGC,QAAUJ,SAAS,CAACI,MAAM;AACxD;AAEO,MAAMC,uBAAuB,CAACC,QAC1BA,AAAe,8BAAfA,MAAM,IAAI;AAOd,MAAMC,iCAAiC,OAC1Cd,wBACAe,iBACAC,OACAC;IAEA,MAAMC,cAAc,MAAMH,gBAAgB,OAAO,CAACC,OAAOC;IACzD,IAAIC,YAAY,MAAM,IAClB,OAAON,qBAAqBM,YAAY,KAAK,IAAI,IAAIC,4BAA4B;IAGrF,MAAMlB,WAAWiB,YAAY,KAAK,CAAC,QAAQ,EAAE;IAC7C,IAAI,CAAE,MAAMnB,qBAAqBC,wBAAwBC,UAAU,MAC/D,OAAO,IAAIkB;IAGf,OAAO;AACX"}
|
package/features/cms/feature.js
CHANGED
|
@@ -13,6 +13,16 @@ import { ListLatestEntriesWithFlpDecorator } from "./decorators/ListLatestEntrie
|
|
|
13
13
|
import { ListPublishedEntriesWithFlpDecorator } from "./decorators/ListPublishedEntriesWithFlpDecorator.js";
|
|
14
14
|
import { ListDeletedEntriesWithFlpDecorator } from "./decorators/ListDeletedEntriesWithFlpDecorator.js";
|
|
15
15
|
import { ListEntriesWithFlpDecorator } from "./decorators/ListEntriesWithFlpDecorator.js";
|
|
16
|
+
import { GetRevisionByIdWithFlpDecorator } from "./decorators/GetRevisionByIdWithFlpDecorator.js";
|
|
17
|
+
import { GetLatestRevisionByEntryIdWithFlpDecorator } from "./decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js";
|
|
18
|
+
import { GetEntriesByIdsWithFlpDecorator } from "./decorators/GetEntriesByIdsWithFlpDecorator.js";
|
|
19
|
+
import { GetRevisionsByEntryIdWithFlpDecorator } from "./decorators/GetRevisionsByEntryIdWithFlpDecorator.js";
|
|
20
|
+
import { GetUniqueFieldValuesWithFlpDecorator } from "./decorators/GetUniqueFieldValuesWithFlpDecorator.js";
|
|
21
|
+
import { PublishEntryWithFlpDecorator } from "./decorators/PublishEntryWithFlpDecorator.js";
|
|
22
|
+
import { UnpublishEntryWithFlpDecorator } from "./decorators/UnpublishEntryWithFlpDecorator.js";
|
|
23
|
+
import { RepublishEntryWithFlpDecorator } from "./decorators/RepublishEntryWithFlpDecorator.js";
|
|
24
|
+
import { RestoreEntryFromBinWithFlpDecorator } from "./decorators/RestoreEntryFromBinWithFlpDecorator.js";
|
|
25
|
+
import { UpdateRevisionDescriptionWithFlpDecorator } from "./decorators/UpdateRevisionDescriptionWithFlpDecorator.js";
|
|
16
26
|
const CmsFlpFeature = createFeature({
|
|
17
27
|
name: "Aco/CmsFlp",
|
|
18
28
|
register (container) {
|
|
@@ -22,10 +32,20 @@ const CmsFlpFeature = createFeature({
|
|
|
22
32
|
container.registerDecorator(DeleteEntryWithFlpDecorator);
|
|
23
33
|
container.registerDecorator(DeleteEntryRevisionWithFlpDecorator);
|
|
24
34
|
container.registerDecorator(MoveEntryWithFlpDecorator);
|
|
35
|
+
container.registerDecorator(PublishEntryWithFlpDecorator);
|
|
36
|
+
container.registerDecorator(UnpublishEntryWithFlpDecorator);
|
|
37
|
+
container.registerDecorator(RepublishEntryWithFlpDecorator);
|
|
38
|
+
container.registerDecorator(RestoreEntryFromBinWithFlpDecorator);
|
|
39
|
+
container.registerDecorator(UpdateRevisionDescriptionWithFlpDecorator);
|
|
25
40
|
container.registerDecorator(GetEntryWithFlpDecorator);
|
|
26
41
|
container.registerDecorator(GetEntryByIdWithFlpDecorator);
|
|
42
|
+
container.registerDecorator(GetRevisionByIdWithFlpDecorator);
|
|
43
|
+
container.registerDecorator(GetLatestRevisionByEntryIdWithFlpDecorator);
|
|
27
44
|
container.registerDecorator(GetLatestEntriesByIdsWithFlpDecorator);
|
|
28
45
|
container.registerDecorator(GetPublishedEntriesByIdsWithFlpDecorator);
|
|
46
|
+
container.registerDecorator(GetEntriesByIdsWithFlpDecorator);
|
|
47
|
+
container.registerDecorator(GetRevisionsByEntryIdWithFlpDecorator);
|
|
48
|
+
container.registerDecorator(GetUniqueFieldValuesWithFlpDecorator);
|
|
29
49
|
container.registerDecorator(ListEntriesWithFlpDecorator);
|
|
30
50
|
container.registerDecorator(ListLatestEntriesWithFlpDecorator);
|
|
31
51
|
container.registerDecorator(ListPublishedEntriesWithFlpDecorator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/cms/feature.js","sources":["../../../src/features/cms/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateEntryWithFlpDecorator } from \"./decorators/CreateEntryWithFlpDecorator.js\";\nimport { CreateEntryRevisionFromWithFlpDecorator } from \"./decorators/CreateEntryRevisionFromWithFlpDecorator.js\";\nimport { UpdateEntryWithFlpDecorator } from \"./decorators/UpdateEntryWithFlpDecorator.js\";\nimport { DeleteEntryWithFlpDecorator } from \"./decorators/DeleteEntryWithFlpDecorator.js\";\nimport { DeleteEntryRevisionWithFlpDecorator } from \"./decorators/DeleteEntryRevisionWithFlpDecorator.js\";\nimport { MoveEntryWithFlpDecorator } from \"./decorators/MoveEntryWithFlpDecorator.js\";\nimport { GetEntryWithFlpDecorator } from \"./decorators/GetEntryWithFlpDecorator.js\";\nimport { GetEntryByIdWithFlpDecorator } from \"./decorators/GetEntryByIdWithFlpDecorator.js\";\nimport { GetLatestEntriesByIdsWithFlpDecorator } from \"./decorators/GetLatestEntriesByIdsWithFlpDecorator.js\";\nimport { GetPublishedEntriesByIdsWithFlpDecorator } from \"./decorators/GetPublishedEntriesByIdsWithFlpDecorator.js\";\nimport { ListLatestEntriesWithFlpDecorator } from \"./decorators/ListLatestEntriesWithFlpDecorator.js\";\nimport { ListPublishedEntriesWithFlpDecorator } from \"./decorators/ListPublishedEntriesWithFlpDecorator.js\";\nimport { ListDeletedEntriesWithFlpDecorator } from \"./decorators/ListDeletedEntriesWithFlpDecorator.js\";\nimport { ListEntriesWithFlpDecorator } from \"./decorators/ListEntriesWithFlpDecorator.js\";\n\nexport const CmsFlpFeature = createFeature({\n name: \"Aco/CmsFlp\",\n register(container) {\n // Command decorators\n container.registerDecorator(CreateEntryWithFlpDecorator);\n container.registerDecorator(CreateEntryRevisionFromWithFlpDecorator);\n container.registerDecorator(UpdateEntryWithFlpDecorator);\n container.registerDecorator(DeleteEntryWithFlpDecorator);\n container.registerDecorator(DeleteEntryRevisionWithFlpDecorator);\n container.registerDecorator(MoveEntryWithFlpDecorator);\n\n // Query decorators - single entry\n container.registerDecorator(GetEntryWithFlpDecorator);\n container.registerDecorator(GetEntryByIdWithFlpDecorator);\n\n // Query decorators - multiple entries\n container.registerDecorator(GetLatestEntriesByIdsWithFlpDecorator);\n container.registerDecorator(GetPublishedEntriesByIdsWithFlpDecorator);\n\n // Query decorators - list entries\n container.registerDecorator(ListEntriesWithFlpDecorator);\n container.registerDecorator(ListLatestEntriesWithFlpDecorator);\n container.registerDecorator(ListPublishedEntriesWithFlpDecorator);\n container.registerDecorator(ListDeletedEntriesWithFlpDecorator);\n }\n});\n"],"names":["CmsFlpFeature","createFeature","container","CreateEntryWithFlpDecorator","CreateEntryRevisionFromWithFlpDecorator","UpdateEntryWithFlpDecorator","DeleteEntryWithFlpDecorator","DeleteEntryRevisionWithFlpDecorator","MoveEntryWithFlpDecorator","GetEntryWithFlpDecorator","GetEntryByIdWithFlpDecorator","GetLatestEntriesByIdsWithFlpDecorator","GetPublishedEntriesByIdsWithFlpDecorator","ListEntriesWithFlpDecorator","ListLatestEntriesWithFlpDecorator","ListPublishedEntriesWithFlpDecorator","ListDeletedEntriesWithFlpDecorator"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/cms/feature.js","sources":["../../../src/features/cms/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateEntryWithFlpDecorator } from \"./decorators/CreateEntryWithFlpDecorator.js\";\nimport { CreateEntryRevisionFromWithFlpDecorator } from \"./decorators/CreateEntryRevisionFromWithFlpDecorator.js\";\nimport { UpdateEntryWithFlpDecorator } from \"./decorators/UpdateEntryWithFlpDecorator.js\";\nimport { DeleteEntryWithFlpDecorator } from \"./decorators/DeleteEntryWithFlpDecorator.js\";\nimport { DeleteEntryRevisionWithFlpDecorator } from \"./decorators/DeleteEntryRevisionWithFlpDecorator.js\";\nimport { MoveEntryWithFlpDecorator } from \"./decorators/MoveEntryWithFlpDecorator.js\";\nimport { GetEntryWithFlpDecorator } from \"./decorators/GetEntryWithFlpDecorator.js\";\nimport { GetEntryByIdWithFlpDecorator } from \"./decorators/GetEntryByIdWithFlpDecorator.js\";\nimport { GetLatestEntriesByIdsWithFlpDecorator } from \"./decorators/GetLatestEntriesByIdsWithFlpDecorator.js\";\nimport { GetPublishedEntriesByIdsWithFlpDecorator } from \"./decorators/GetPublishedEntriesByIdsWithFlpDecorator.js\";\nimport { ListLatestEntriesWithFlpDecorator } from \"./decorators/ListLatestEntriesWithFlpDecorator.js\";\nimport { ListPublishedEntriesWithFlpDecorator } from \"./decorators/ListPublishedEntriesWithFlpDecorator.js\";\nimport { ListDeletedEntriesWithFlpDecorator } from \"./decorators/ListDeletedEntriesWithFlpDecorator.js\";\nimport { ListEntriesWithFlpDecorator } from \"./decorators/ListEntriesWithFlpDecorator.js\";\nimport { GetRevisionByIdWithFlpDecorator } from \"./decorators/GetRevisionByIdWithFlpDecorator.js\";\nimport { GetLatestRevisionByEntryIdWithFlpDecorator } from \"./decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js\";\nimport { GetEntriesByIdsWithFlpDecorator } from \"./decorators/GetEntriesByIdsWithFlpDecorator.js\";\nimport { GetRevisionsByEntryIdWithFlpDecorator } from \"./decorators/GetRevisionsByEntryIdWithFlpDecorator.js\";\nimport { GetUniqueFieldValuesWithFlpDecorator } from \"./decorators/GetUniqueFieldValuesWithFlpDecorator.js\";\nimport { PublishEntryWithFlpDecorator } from \"./decorators/PublishEntryWithFlpDecorator.js\";\nimport { UnpublishEntryWithFlpDecorator } from \"./decorators/UnpublishEntryWithFlpDecorator.js\";\nimport { RepublishEntryWithFlpDecorator } from \"./decorators/RepublishEntryWithFlpDecorator.js\";\nimport { RestoreEntryFromBinWithFlpDecorator } from \"./decorators/RestoreEntryFromBinWithFlpDecorator.js\";\nimport { UpdateRevisionDescriptionWithFlpDecorator } from \"./decorators/UpdateRevisionDescriptionWithFlpDecorator.js\";\n\nexport const CmsFlpFeature = createFeature({\n name: \"Aco/CmsFlp\",\n register(container) {\n // Command decorators\n container.registerDecorator(CreateEntryWithFlpDecorator);\n container.registerDecorator(CreateEntryRevisionFromWithFlpDecorator);\n container.registerDecorator(UpdateEntryWithFlpDecorator);\n container.registerDecorator(DeleteEntryWithFlpDecorator);\n container.registerDecorator(DeleteEntryRevisionWithFlpDecorator);\n container.registerDecorator(MoveEntryWithFlpDecorator);\n container.registerDecorator(PublishEntryWithFlpDecorator);\n container.registerDecorator(UnpublishEntryWithFlpDecorator);\n container.registerDecorator(RepublishEntryWithFlpDecorator);\n container.registerDecorator(RestoreEntryFromBinWithFlpDecorator);\n container.registerDecorator(UpdateRevisionDescriptionWithFlpDecorator);\n\n // Query decorators - single entry\n container.registerDecorator(GetEntryWithFlpDecorator);\n container.registerDecorator(GetEntryByIdWithFlpDecorator);\n // Also covers use cases that load the entry through it (e.g. ValidateEntry, DuplicateEntry).\n container.registerDecorator(GetRevisionByIdWithFlpDecorator);\n container.registerDecorator(GetLatestRevisionByEntryIdWithFlpDecorator);\n\n // Query decorators - multiple entries\n container.registerDecorator(GetLatestEntriesByIdsWithFlpDecorator);\n container.registerDecorator(GetPublishedEntriesByIdsWithFlpDecorator);\n container.registerDecorator(GetEntriesByIdsWithFlpDecorator);\n container.registerDecorator(GetRevisionsByEntryIdWithFlpDecorator);\n container.registerDecorator(GetUniqueFieldValuesWithFlpDecorator);\n\n // Query decorators - list entries\n container.registerDecorator(ListEntriesWithFlpDecorator);\n container.registerDecorator(ListLatestEntriesWithFlpDecorator);\n container.registerDecorator(ListPublishedEntriesWithFlpDecorator);\n container.registerDecorator(ListDeletedEntriesWithFlpDecorator);\n }\n});\n"],"names":["CmsFlpFeature","createFeature","container","CreateEntryWithFlpDecorator","CreateEntryRevisionFromWithFlpDecorator","UpdateEntryWithFlpDecorator","DeleteEntryWithFlpDecorator","DeleteEntryRevisionWithFlpDecorator","MoveEntryWithFlpDecorator","PublishEntryWithFlpDecorator","UnpublishEntryWithFlpDecorator","RepublishEntryWithFlpDecorator","RestoreEntryFromBinWithFlpDecorator","UpdateRevisionDescriptionWithFlpDecorator","GetEntryWithFlpDecorator","GetEntryByIdWithFlpDecorator","GetRevisionByIdWithFlpDecorator","GetLatestRevisionByEntryIdWithFlpDecorator","GetLatestEntriesByIdsWithFlpDecorator","GetPublishedEntriesByIdsWithFlpDecorator","GetEntriesByIdsWithFlpDecorator","GetRevisionsByEntryIdWithFlpDecorator","GetUniqueFieldValuesWithFlpDecorator","ListEntriesWithFlpDecorator","ListLatestEntriesWithFlpDecorator","ListPublishedEntriesWithFlpDecorator","ListDeletedEntriesWithFlpDecorator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,iBAAiB,CAACC;QAC5BD,UAAU,iBAAiB,CAACE;QAC5BF,UAAU,iBAAiB,CAACG;QAC5BH,UAAU,iBAAiB,CAACI;QAC5BJ,UAAU,iBAAiB,CAACK;QAC5BL,UAAU,iBAAiB,CAACM;QAC5BN,UAAU,iBAAiB,CAACO;QAC5BP,UAAU,iBAAiB,CAACQ;QAC5BR,UAAU,iBAAiB,CAACS;QAC5BT,UAAU,iBAAiB,CAACU;QAC5BV,UAAU,iBAAiB,CAACW;QAG5BX,UAAU,iBAAiB,CAACY;QAC5BZ,UAAU,iBAAiB,CAACa;QAE5Bb,UAAU,iBAAiB,CAACc;QAC5Bd,UAAU,iBAAiB,CAACe;QAG5Bf,UAAU,iBAAiB,CAACgB;QAC5BhB,UAAU,iBAAiB,CAACiB;QAC5BjB,UAAU,iBAAiB,CAACkB;QAC5BlB,UAAU,iBAAiB,CAACmB;QAC5BnB,UAAU,iBAAiB,CAACoB;QAG5BpB,UAAU,iBAAiB,CAACqB;QAC5BrB,UAAU,iBAAiB,CAACsB;QAC5BtB,UAAU,iBAAiB,CAACuB;QAC5BvB,UAAU,iBAAiB,CAACwB;IAChC;AACJ"}
|
|
@@ -9,6 +9,10 @@ class CreateFlpOnFolderCreatedHandlerImpl {
|
|
|
9
9
|
}
|
|
10
10
|
async handle(event) {
|
|
11
11
|
const { folder } = event.payload;
|
|
12
|
+
try {
|
|
13
|
+
await this.createFlpUseCase.execute(folder);
|
|
14
|
+
return;
|
|
15
|
+
} catch {}
|
|
12
16
|
try {
|
|
13
17
|
if (this.tasks) await this.tasks.trigger({
|
|
14
18
|
definition: CREATE_FLP_TASK_ID,
|
|
@@ -16,7 +20,6 @@ class CreateFlpOnFolderCreatedHandlerImpl {
|
|
|
16
20
|
folder
|
|
17
21
|
}
|
|
18
22
|
});
|
|
19
|
-
else await this.createFlpUseCase.execute(folder);
|
|
20
23
|
} catch {}
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js","sources":["../../../../src/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.ts"],"sourcesContent":["import { CreateFlpUseCase } from \"../CreateFlp/abstractions.js\";\nimport { FolderAfterCreateEventHandler } from \"~/features/folder/CreateFolder/abstractions.js\";\nimport type { FolderAfterCreateEvent } from \"~/features/folder/CreateFolder/events.js\";\nimport type { ICreateFlpTaskInput } from \"~/types.js\";\nimport { CREATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\n\nclass CreateFlpOnFolderCreatedHandlerImpl implements FolderAfterCreateEventHandler.Interface {\n constructor(\n private createFlpUseCase: CreateFlpUseCase.Interface,\n private tasks?: TaskService.Interface\n ) {}\n\n async handle(event: FolderAfterCreateEvent): Promise<void> {\n const { folder } = event.payload;\n\n try {\n if (this.tasks) {\n await this.tasks.trigger<ICreateFlpTaskInput>({\n definition: CREATE_FLP_TASK_ID,\n input: { folder }\n });\n }
|
|
1
|
+
{"version":3,"file":"features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js","sources":["../../../../src/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.ts"],"sourcesContent":["import { CreateFlpUseCase } from \"../CreateFlp/abstractions.js\";\nimport { FolderAfterCreateEventHandler } from \"~/features/folder/CreateFolder/abstractions.js\";\nimport type { FolderAfterCreateEvent } from \"~/features/folder/CreateFolder/events.js\";\nimport type { ICreateFlpTaskInput } from \"~/types.js\";\nimport { CREATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\n\nclass CreateFlpOnFolderCreatedHandlerImpl implements FolderAfterCreateEventHandler.Interface {\n constructor(\n private createFlpUseCase: CreateFlpUseCase.Interface,\n private tasks?: TaskService.Interface\n ) {}\n\n async handle(event: FolderAfterCreateEvent): Promise<void> {\n const { folder } = event.payload;\n\n /* Create the FLP record right away. Until it exists, the folder's permissions load as\n empty, which means \"public\": anyone with access to the app could read the folder\n or change its permissions. It's a single write, so there's no need for a task. */\n try {\n await this.createFlpUseCase.execute(folder);\n return;\n } catch {\n // Fall back to the background task, which retries outside of this request.\n }\n\n try {\n if (this.tasks) {\n await this.tasks.trigger<ICreateFlpTaskInput>({\n definition: CREATE_FLP_TASK_ID,\n input: { folder }\n });\n }\n } catch {\n // Ignore errors\n }\n }\n}\n\nexport const CreateFlpOnFolderCreatedHandler = FolderAfterCreateEventHandler.createImplementation({\n implementation: CreateFlpOnFolderCreatedHandlerImpl,\n dependencies: [CreateFlpUseCase, [TaskService, { optional: true }]]\n});\n"],"names":["CreateFlpOnFolderCreatedHandlerImpl","createFlpUseCase","tasks","event","folder","CREATE_FLP_TASK_ID","CreateFlpOnFolderCreatedHandler","FolderAfterCreateEventHandler","CreateFlpUseCase","TaskService"],"mappings":";;;;AAOA,MAAMA;IACF,YACYC,gBAA4C,EAC5CC,KAA6B,CACvC;aAFUD,gBAAgB,GAAhBA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,OAAOC,KAA6B,EAAiB;QACvD,MAAM,EAAEC,MAAM,EAAE,GAAGD,MAAM,OAAO;QAKhC,IAAI;YACA,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAACC;YACpC;QACJ,EAAE,OAAM,CAER;QAEA,IAAI;YACA,IAAI,IAAI,CAAC,KAAK,EACV,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAsB;gBAC1C,YAAYC;gBACZ,OAAO;oBAAED;gBAAO;YACpB;QAER,EAAE,OAAM,CAER;IACJ;AACJ;AAEO,MAAME,kCAAkCC,8BAA8B,oBAAoB,CAAC;IAC9F,gBAAgBP;IAChB,cAAc;QAACQ;QAAkB;YAACC;YAAa;gBAAE,UAAU;YAAK;SAAE;KAAC;AACvE"}
|
|
@@ -23,6 +23,7 @@ class CreateFolderRepositoryImpl {
|
|
|
23
23
|
});
|
|
24
24
|
if (checkResult.isFail()) return Result.fail(checkResult.error);
|
|
25
25
|
const pathResult = await this.createFolderPath({
|
|
26
|
+
type: data.type,
|
|
26
27
|
slug: data.slug,
|
|
27
28
|
parentId: data.parentId
|
|
28
29
|
});
|
|
@@ -63,11 +64,12 @@ class CreateFolderRepositoryImpl {
|
|
|
63
64
|
return Result.ok();
|
|
64
65
|
}
|
|
65
66
|
async createFolderPath(params) {
|
|
66
|
-
const { slug, parentId } = params;
|
|
67
|
+
const { type, slug, parentId } = params;
|
|
67
68
|
if (!parentId) return Result.ok(Path.create(slug));
|
|
68
69
|
const parentResult = await this.getEntryById.execute(this.folderModel, EntryId.from(parentId).toString());
|
|
69
70
|
if (parentResult.isFail()) return Result.fail(new FolderPersistenceError(new Error("Parent folder not found. Unable to create the folder path")));
|
|
70
71
|
const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);
|
|
72
|
+
if (parentFolder.type !== type) return Result.fail(new FolderValidationError("Parent folder must be of the same type as the folder."));
|
|
71
73
|
return Result.ok(Path.create(slug, parentFolder.path));
|
|
72
74
|
}
|
|
73
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/CreateFolder/CreateFolderRepository.js","sources":["../../../../src/features/folder/CreateFolder/CreateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFolderRepository as RepositoryAbstraction,\n type ICreateFolderRepository\n} from \"./abstractions.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, CreateFolderParams, Folder } 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 CreateFolderRepositoryImpl implements ICreateFolderRepository {\n constructor(\n private createEntry: CreateEntryUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(data: CreateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n // Check if folder already exists\n const checkResult = await this.checkExistingFolder({\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create folder path\n const pathResult = await this.createFolderPath({\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n // Create the entry\n const result = await this.createEntry.execute<CmsEntryFolder>(this.folderModel, {\n values: {\n ...data,\n parentId: data.parentId || null,\n path: pathResult.value\n }\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/ValidationError\") {\n return Result.fail(new FolderValidationError(result.error.message));\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(folder);\n }\n\n private async checkExistingFolder(params: {\n type: string;\n slug: string;\n parentId?: string | null;\n excludeId?: string;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const { type, slug, parentId, excludeId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(this.folderModel, {\n where: {\n latest: true,\n values: {\n type,\n slug,\n parentId\n },\n ...(excludeId ? { entryId_not: excludeId } : {})\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 CreateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateFolderRepositoryImpl,\n dependencies: [CreateEntryUseCase, ListLatestEntriesUseCase, GetEntryByIdUseCase, FolderModel]\n});\n"],"names":["CreateFolderRepositoryImpl","createEntry","listLatestEntries","getEntryById","folderModel","data","checkResult","Result","pathResult","result","FolderValidationError","FolderPersistenceError","folder","EntryToFolderMapper","params","type","slug","parentId","excludeId","entries","Path","parentResult","EntryId","Error","parentFolder","CreateFolderRepository","RepositoryAbstraction","CreateEntryUseCase","ListLatestEntriesUseCase","GetEntryByIdUseCase","FolderModel"],"mappings":";;;;;;;;;;AAeA,MAAMA;IACF,YACYC,WAAyC,EACzCC,iBAAqD,EACrDC,YAA2C,EAC3CC,WAAkC,CAC5C;aAJUH,WAAW,GAAXA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,IAAwB,EAAwD;QAE1F,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC/C,MAAMD,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIC,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAIxC,MAAME,aAAa,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC3C,MAAMH,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIG,WAAW,MAAM,IACjB,OAAOD,OAAO,IAAI,CAACC,WAAW,KAAK;QAIvC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAiB,IAAI,CAAC,WAAW,EAAE;YAC5E,QAAQ;gBACJ,GAAGJ,IAAI;gBACP,UAAUA,KAAK,QAAQ,IAAI;gBAC3B,MAAMG,WAAW,KAAK;YAC1B;QACJ;QAEA,IAAIC,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,gCAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD,OAAO,KAAK,CAAC,OAAO;YAErE,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAC9D;QAEA,MAAMG,SAASC,oBAAoB,QAAQ,CAACJ,OAAO,KAAK;QACxD,OAAOF,OAAO,EAAE,CAACK;IACrB;IAEA,MAAc,oBAAoBE,MAKjC,EAAsD;QACnD,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGJ;QAE5C,MAAML,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAiB,IAAI,CAAC,WAAW,EAAE;YAClF,OAAO;gBACH,QAAQ;gBACR,QAAQ;oBACJM;oBACAC;oBACAC;gBACJ;gBACA,GAAIC,YAAY;oBAAE,aAAaA;gBAAU,IAAI,CAAC,CAAC;YACnD;YACA,OAAO;QACX;QAEA,IAAIT,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAM,EAAEU,OAAO,EAAE,GAAGV,OAAO,KAAK;QAEhC,IAAIU,QAAQ,MAAM,GAAG,GACjB,OAAOZ,OAAO,IAAI,CACd,IAAIG,sBACA,CAAC,kBAAkB,EAAEM,KAAK,+BAA+B,CAAC;QAKtE,OAAOT,OAAO,EAAE;IACpB;IAEA,MAAc,iBAAiBO,
|
|
1
|
+
{"version":3,"file":"features/folder/CreateFolder/CreateFolderRepository.js","sources":["../../../../src/features/folder/CreateFolder/CreateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFolderRepository as RepositoryAbstraction,\n type ICreateFolderRepository\n} from \"./abstractions.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, CreateFolderParams, Folder } 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 CreateFolderRepositoryImpl implements ICreateFolderRepository {\n constructor(\n private createEntry: CreateEntryUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(data: CreateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n // Check if folder already exists\n const checkResult = await this.checkExistingFolder({\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create folder path\n const pathResult = await this.createFolderPath({\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n // Create the entry\n const result = await this.createEntry.execute<CmsEntryFolder>(this.folderModel, {\n values: {\n ...data,\n parentId: data.parentId || null,\n path: pathResult.value\n }\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/ValidationError\") {\n return Result.fail(new FolderValidationError(result.error.message));\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(folder);\n }\n\n private async checkExistingFolder(params: {\n type: string;\n slug: string;\n parentId?: string | null;\n excludeId?: string;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const { type, slug, parentId, excludeId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(this.folderModel, {\n where: {\n latest: true,\n values: {\n type,\n slug,\n parentId\n },\n ...(excludeId ? { entryId_not: excludeId } : {})\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 type: string;\n slug: string;\n parentId?: string | null;\n }): Promise<Result<string, RepositoryAbstraction.Error>> {\n const { type, 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\n // Security: a folder cannot be planted under a folder of another type (another app).\n if (parentFolder.type !== type) {\n return Result.fail(\n new FolderValidationError(\"Parent folder must be of the same type as the folder.\")\n );\n }\n\n return Result.ok(Path.create(slug, parentFolder.path));\n }\n}\n\nexport const CreateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateFolderRepositoryImpl,\n dependencies: [CreateEntryUseCase, ListLatestEntriesUseCase, GetEntryByIdUseCase, FolderModel]\n});\n"],"names":["CreateFolderRepositoryImpl","createEntry","listLatestEntries","getEntryById","folderModel","data","checkResult","Result","pathResult","result","FolderValidationError","FolderPersistenceError","folder","EntryToFolderMapper","params","type","slug","parentId","excludeId","entries","Path","parentResult","EntryId","Error","parentFolder","CreateFolderRepository","RepositoryAbstraction","CreateEntryUseCase","ListLatestEntriesUseCase","GetEntryByIdUseCase","FolderModel"],"mappings":";;;;;;;;;;AAeA,MAAMA;IACF,YACYC,WAAyC,EACzCC,iBAAqD,EACrDC,YAA2C,EAC3CC,WAAkC,CAC5C;aAJUH,WAAW,GAAXA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,IAAwB,EAAwD;QAE1F,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC/C,MAAMD,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIC,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAIxC,MAAME,aAAa,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC3C,MAAMH,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIG,WAAW,MAAM,IACjB,OAAOD,OAAO,IAAI,CAACC,WAAW,KAAK;QAIvC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAiB,IAAI,CAAC,WAAW,EAAE;YAC5E,QAAQ;gBACJ,GAAGJ,IAAI;gBACP,UAAUA,KAAK,QAAQ,IAAI;gBAC3B,MAAMG,WAAW,KAAK;YAC1B;QACJ;QAEA,IAAIC,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,gCAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD,OAAO,KAAK,CAAC,OAAO;YAErE,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAC9D;QAEA,MAAMG,SAASC,oBAAoB,QAAQ,CAACJ,OAAO,KAAK;QACxD,OAAOF,OAAO,EAAE,CAACK;IACrB;IAEA,MAAc,oBAAoBE,MAKjC,EAAsD;QACnD,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGJ;QAE5C,MAAML,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAiB,IAAI,CAAC,WAAW,EAAE;YAClF,OAAO;gBACH,QAAQ;gBACR,QAAQ;oBACJM;oBACAC;oBACAC;gBACJ;gBACA,GAAIC,YAAY;oBAAE,aAAaA;gBAAU,IAAI,CAAC,CAAC;YACnD;YACA,OAAO;QACX;QAEA,IAAIT,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAM,EAAEU,OAAO,EAAE,GAAGV,OAAO,KAAK;QAEhC,IAAIU,QAAQ,MAAM,GAAG,GACjB,OAAOZ,OAAO,IAAI,CACd,IAAIG,sBACA,CAAC,kBAAkB,EAAEM,KAAK,+BAA+B,CAAC;QAKtE,OAAOT,OAAO,EAAE;IACpB;IAEA,MAAc,iBAAiBO,MAI9B,EAAwD;QACrD,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGH;QAEjC,IAAI,CAACG,UACD,OAAOV,OAAO,EAAE,CAACa,KAAK,MAAM,CAACJ;QAGjC,MAAMK,eAAe,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAChD,IAAI,CAAC,WAAW,EAChBC,QAAQ,IAAI,CAACL,UAAU,QAAQ;QAGnC,IAAII,aAAa,MAAM,IACnB,OAAOd,OAAO,IAAI,CACd,IAAII,uBACA,IAAIY,MAAM;QAKtB,MAAMC,eAAeX,oBAAoB,QAAQ,CAACQ,aAAa,KAAK;QAGpE,IAAIG,aAAa,IAAI,KAAKT,MACtB,OAAOR,OAAO,IAAI,CACd,IAAIG,sBAAsB;QAIlC,OAAOH,OAAO,EAAE,CAACa,KAAK,MAAM,CAACJ,MAAMQ,aAAa,IAAI;IACxD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgB1B;IAChB,cAAc;QAAC2B;QAAoBC;QAA0BC;QAAqBC;KAAY;AAClG"}
|
|
@@ -5,7 +5,7 @@ declare class CreateFolderWithFolderLevelPermissionsImpl implements CreateFolder
|
|
|
5
5
|
private folderLevelPermissions;
|
|
6
6
|
private readonly decoretee;
|
|
7
7
|
constructor(folderLevelPermissions: FolderLevelPermissions.Interface, decoretee: CreateFolderUseCase.Interface);
|
|
8
|
-
execute(
|
|
8
|
+
execute(input: CreateFolderParams): CreateFolderUseCase.Return;
|
|
9
9
|
}
|
|
10
10
|
export declare const CreateFolderWithFolderLevelPermissions: typeof CreateFolderWithFolderLevelPermissionsImpl;
|
|
11
11
|
export {};
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { FolderLevelPermissions } from "../../../flp/FolderLevelPermissions/index.js";
|
|
2
2
|
import { CreateFolderUseCase } from "../abstractions.js";
|
|
3
3
|
import { Result, createDecorator } from "@webiny/feature/api";
|
|
4
|
-
import { FolderNotAuthorizedError } from "../../../../domain/folder/errors.js";
|
|
4
|
+
import { FolderNotAuthorizedError, FolderValidationError } from "../../../../domain/folder/errors.js";
|
|
5
|
+
import { validatePermissionsInput } from "../../shared/validatePermissionsInput.js";
|
|
5
6
|
class CreateFolderWithFolderLevelPermissionsImpl {
|
|
6
7
|
constructor(folderLevelPermissions, decoretee){
|
|
7
8
|
this.folderLevelPermissions = folderLevelPermissions;
|
|
8
9
|
this.decoretee = decoretee;
|
|
9
10
|
}
|
|
10
|
-
async execute(
|
|
11
|
+
async execute(input) {
|
|
12
|
+
const params = {
|
|
13
|
+
...input
|
|
14
|
+
};
|
|
15
|
+
if (null === params.permissions) delete params.permissions;
|
|
16
|
+
const ownPermissions = params.permissions ?? [];
|
|
17
|
+
if (ownPermissions.length > 0) {
|
|
18
|
+
const validationError = validatePermissionsInput(ownPermissions);
|
|
19
|
+
if (validationError) return Result.fail(validationError);
|
|
20
|
+
}
|
|
11
21
|
let canCreateFolder;
|
|
12
22
|
if (params.parentId) {
|
|
13
23
|
const permissions = await this.folderLevelPermissions.getFolderLevelPermissions(params.parentId);
|
|
@@ -15,6 +25,14 @@ class CreateFolderWithFolderLevelPermissionsImpl {
|
|
|
15
25
|
permissions,
|
|
16
26
|
rwd: "w"
|
|
17
27
|
});
|
|
28
|
+
if (canCreateFolder && ownPermissions.length > 0 && this.folderLevelPermissions.canUseFolderLevelPermissions() && !await this.folderLevelPermissions.canManageFolderPermissions({
|
|
29
|
+
id: params.parentId,
|
|
30
|
+
parentId: "",
|
|
31
|
+
slug: "",
|
|
32
|
+
path: "",
|
|
33
|
+
type: params.type,
|
|
34
|
+
permissions
|
|
35
|
+
})) return Result.fail(new FolderValidationError("Not allowed to set the folder permissions."));
|
|
18
36
|
} else canCreateFolder = this.folderLevelPermissions.canCreateFolderInRoot();
|
|
19
37
|
if (!canCreateFolder) return Result.fail(new FolderNotAuthorizedError());
|
|
20
38
|
const result = await this.decoretee.execute(params);
|
package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { CreateFolderUseCase } from \"../abstractions.js\";\nimport type { CreateFolderParams } from \"~/folder/folder.types.js\";\nimport { createDecorator, Result } from \"@webiny/feature/api\";\nimport { FolderNotAuthorizedError } from \"~/domain/folder/errors.js\";\n\nclass CreateFolderWithFolderLevelPermissionsImpl implements CreateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: CreateFolderUseCase.Interface;\n\n constructor(\n folderLevelPermissions: FolderLevelPermissions.Interface,\n decoretee: CreateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.decoretee = decoretee;\n }\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { CreateFolderUseCase } from \"../abstractions.js\";\nimport type { CreateFolderParams } from \"~/folder/folder.types.js\";\nimport { createDecorator, Result } from \"@webiny/feature/api\";\nimport { FolderNotAuthorizedError, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport type { FolderPermission } from \"~/flp/flp.types.js\";\nimport { validatePermissionsInput } from \"~/features/folder/shared/validatePermissionsInput.js\";\n\nclass CreateFolderWithFolderLevelPermissionsImpl implements CreateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: CreateFolderUseCase.Interface;\n\n constructor(\n folderLevelPermissions: FolderLevelPermissions.Interface,\n decoretee: CreateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.decoretee = decoretee;\n }\n\n async execute(input: CreateFolderParams): CreateFolderUseCase.Return {\n // GraphQL input accepts `permissions` (and `null`); it is not part of the typed params.\n const params: CreateFolderParams & { permissions?: FolderPermission[] | null } = {\n ...input\n };\n if (params.permissions === null) {\n delete params.permissions;\n }\n const ownPermissions = params.permissions ?? [];\n\n // Security: validate permissions like on update.\n if (ownPermissions.length > 0) {\n const validationError = validatePermissionsInput(ownPermissions);\n if (validationError) {\n return Result.fail(validationError);\n }\n }\n\n let canCreateFolder: boolean;\n if (params.parentId) {\n const permissions = await this.folderLevelPermissions.getFolderLevelPermissions(\n params.parentId\n );\n canCreateFolder = await this.folderLevelPermissions.canAccessFolder({\n permissions,\n rwd: \"w\"\n });\n\n /* Security: own permissions on a subfolder override the inherited ones (e.g. lock out\n the parent's owners), so setting them requires the \"owner\" level on the parent,\n the same as changing permissions of an existing folder. Root folders inherit\n nothing, so the creator may set any permissions on a folder they just created. */\n if (\n canCreateFolder &&\n ownPermissions.length > 0 &&\n this.folderLevelPermissions.canUseFolderLevelPermissions() &&\n !(await this.folderLevelPermissions.canManageFolderPermissions({\n id: params.parentId,\n parentId: \"\",\n slug: \"\",\n path: \"\",\n type: params.type,\n permissions\n }))\n ) {\n return Result.fail(\n new FolderValidationError(`Not allowed to set the folder permissions.`)\n );\n }\n } else {\n canCreateFolder = this.folderLevelPermissions.canCreateFolderInRoot();\n }\n\n if (!canCreateFolder) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n\n const result = await this.decoretee.execute(params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const folder = result.value;\n\n // Let's set default permissions based on the current user.\n const permissionsWithDefaults = await this.folderLevelPermissions.getDefaultPermissions(\n folder?.permissions ?? []\n );\n\n return Result.ok({\n ...folder,\n permissions: permissionsWithDefaults\n });\n }\n}\n\nexport const CreateFolderWithFolderLevelPermissions = createDecorator({\n abstraction: CreateFolderUseCase,\n decorator: CreateFolderWithFolderLevelPermissionsImpl,\n dependencies: [FolderLevelPermissions]\n});\n"],"names":["CreateFolderWithFolderLevelPermissionsImpl","folderLevelPermissions","decoretee","input","params","ownPermissions","validationError","validatePermissionsInput","Result","canCreateFolder","permissions","FolderValidationError","FolderNotAuthorizedError","result","folder","permissionsWithDefaults","CreateFolderWithFolderLevelPermissions","createDecorator","CreateFolderUseCase","FolderLevelPermissions"],"mappings":";;;;;AAQA,MAAMA;IAIF,YACIC,sBAAwD,EACxDC,SAAwC,CAC1C;QACE,IAAI,CAAC,sBAAsB,GAAGD;QAC9B,IAAI,CAAC,SAAS,GAAGC;IACrB;IAEA,MAAM,QAAQC,KAAyB,EAA8B;QAEjE,MAAMC,SAA2E;YAC7E,GAAGD,KAAK;QACZ;QACA,IAAIC,AAAuB,SAAvBA,OAAO,WAAW,EAClB,OAAOA,OAAO,WAAW;QAE7B,MAAMC,iBAAiBD,OAAO,WAAW,IAAI,EAAE;QAG/C,IAAIC,eAAe,MAAM,GAAG,GAAG;YAC3B,MAAMC,kBAAkBC,yBAAyBF;YACjD,IAAIC,iBACA,OAAOE,OAAO,IAAI,CAACF;QAE3B;QAEA,IAAIG;QACJ,IAAIL,OAAO,QAAQ,EAAE;YACjB,MAAMM,cAAc,MAAM,IAAI,CAAC,sBAAsB,CAAC,yBAAyB,CAC3EN,OAAO,QAAQ;YAEnBK,kBAAkB,MAAM,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC;gBAChEC;gBACA,KAAK;YACT;YAMA,IACID,mBACAJ,eAAe,MAAM,GAAG,KACxB,IAAI,CAAC,sBAAsB,CAAC,4BAA4B,MACxD,CAAE,MAAM,IAAI,CAAC,sBAAsB,CAAC,0BAA0B,CAAC;gBAC3D,IAAID,OAAO,QAAQ;gBACnB,UAAU;gBACV,MAAM;gBACN,MAAM;gBACN,MAAMA,OAAO,IAAI;gBACjBM;YACJ,IAEA,OAAOF,OAAO,IAAI,CACd,IAAIG,sBAAsB;QAGtC,OACIF,kBAAkB,IAAI,CAAC,sBAAsB,CAAC,qBAAqB;QAGvE,IAAI,CAACA,iBACD,OAAOD,OAAO,IAAI,CAAC,IAAII;QAG3B,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACT;QAE5C,IAAIS,OAAO,MAAM,IACb,OAAOL,OAAO,IAAI,CAACK,OAAO,KAAK;QAGnC,MAAMC,SAASD,OAAO,KAAK;QAG3B,MAAME,0BAA0B,MAAM,IAAI,CAAC,sBAAsB,CAAC,qBAAqB,CACnFD,QAAQ,eAAe,EAAE;QAG7B,OAAON,OAAO,EAAE,CAAC;YACb,GAAGM,MAAM;YACT,aAAaC;QACjB;IACJ;AACJ;AAEO,MAAMC,yCAAyCC,gBAAgB;IAClE,aAAaC;IACb,WAAWlB;IACX,cAAc;QAACmB;KAAuB;AAC1C"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { FolderLevelPermissions } from "../../../features/flp/FolderLevelPermissions/index.js";
|
|
2
1
|
import { ListFoldersUseCase } from "../../../features/folder/ListFolders/index.js";
|
|
3
2
|
import { EnsureFolderIsEmpty as Abstraction } from "../../../features/folder/EnsureFolderIsEmpty/abstractions.js";
|
|
4
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
5
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
5
|
declare class EnsureFolderIsEmptyImpl implements Abstraction.Interface {
|
|
7
6
|
private identityContext;
|
|
8
|
-
private folderLevelPermissions;
|
|
9
7
|
private listFoldersUseCase;
|
|
10
8
|
private logger;
|
|
11
|
-
constructor(identityContext: IdentityContext.Interface,
|
|
9
|
+
constructor(identityContext: IdentityContext.Interface, listFoldersUseCase: ListFoldersUseCase.Interface, logger: Logger.Interface);
|
|
12
10
|
execute(type: string, id: string, hasContentCallback: Abstraction.HasContentCallback): Abstraction.Return;
|
|
13
11
|
}
|
|
14
12
|
export declare const EnsureFolderIsEmpty: typeof EnsureFolderIsEmptyImpl & {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FolderLevelPermissions } from "../../flp/FolderLevelPermissions/index.js";
|
|
2
1
|
import { ListFoldersUseCase } from "../ListFolders/index.js";
|
|
3
2
|
import { EnsureFolderIsEmpty } from "./abstractions.js";
|
|
4
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
@@ -6,9 +5,8 @@ import { IdentityContext } from "@webiny/api-core/features/security/IdentityCont
|
|
|
6
5
|
import { FolderNotAuthorizedError, FolderNotEmptyError } from "../../../domain/folder/errors.js";
|
|
7
6
|
import { Result } from "@webiny/feature/api";
|
|
8
7
|
class EnsureFolderIsEmptyImpl {
|
|
9
|
-
constructor(identityContext,
|
|
8
|
+
constructor(identityContext, listFoldersUseCase, logger){
|
|
10
9
|
this.identityContext = identityContext;
|
|
11
|
-
this.folderLevelPermissions = folderLevelPermissions;
|
|
12
10
|
this.listFoldersUseCase = listFoldersUseCase;
|
|
13
11
|
this.logger = logger;
|
|
14
12
|
}
|
|
@@ -33,7 +31,6 @@ class EnsureFolderIsEmptyImpl {
|
|
|
33
31
|
hasContentCallback()
|
|
34
32
|
]);
|
|
35
33
|
if (hasFolders || hasContent) return Result.fail(new FolderNotEmptyError());
|
|
36
|
-
if (!this.folderLevelPermissions.canUseFolderLevelPermissions()) return Result.ok();
|
|
37
34
|
const [hasInvisibleFolders, hasInvisibleContent] = await this.identityContext.withoutAuthorization(async ()=>{
|
|
38
35
|
const [hasFolders, hasContent] = await Promise.all([
|
|
39
36
|
hasFoldersCallback(),
|
|
@@ -52,7 +49,6 @@ const EnsureFolderIsEmpty_EnsureFolderIsEmpty = EnsureFolderIsEmpty.createImplem
|
|
|
52
49
|
implementation: EnsureFolderIsEmptyImpl,
|
|
53
50
|
dependencies: [
|
|
54
51
|
IdentityContext,
|
|
55
|
-
FolderLevelPermissions,
|
|
56
52
|
ListFoldersUseCase,
|
|
57
53
|
Logger
|
|
58
54
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js","sources":["../../../../src/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.ts"],"sourcesContent":["import { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { EnsureFolderIsEmpty as Abstraction } from \"~/features/folder/EnsureFolderIsEmpty/abstractions.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { FolderNotAuthorizedError, FolderNotEmptyError } from \"~/domain/folder/errors.js\";\nimport { Result } from \"@webiny/feature/api\";\n\nclass EnsureFolderIsEmptyImpl implements Abstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private listFoldersUseCase: ListFoldersUseCase.Interface,\n private logger: Logger.Interface\n ) {}\n\n async execute(\n type: string,\n id: string,\n hasContentCallback: Abstraction.HasContentCallback\n ): Abstraction.Return {\n const hasFoldersCallback = async () => {\n const result = await this.listFoldersUseCase.execute({\n where: {\n type,\n parentId: id\n },\n limit: 1\n });\n if (result.isFail()) {\n this.logger.error(result.error);\n // Report the folder as non-empty so a failed lookup cannot green-light a delete.\n return true;\n }\n\n const { folders } = result.value;\n\n return folders.length > 0;\n };\n\n const [hasFolders, hasContent] = await Promise.all([\n hasFoldersCallback(),\n hasContentCallback()\n ]);\n\n if (hasFolders || hasContent) {\n return Result.fail(new FolderNotEmptyError());\n }\n\n /* Also check for folders / content the identity cannot see. Security: run this even when\n folder level permissions are not used, because other restrictions (e.g. \"own entries\n only\") also hide content, and the folder must not be deleted from under it. */\n const [hasInvisibleFolders, hasInvisibleContent] =\n await this.identityContext.withoutAuthorization(async () => {\n const [hasFolders, hasContent] = await Promise.all([\n hasFoldersCallback(),\n hasContentCallback()\n ]);\n return [hasFolders, hasContent];\n });\n\n // In case there are invisible folders or content, we'll throw a different error.\n // This is to prevent users from deleting folders that contain content they can't see.\n if (hasInvisibleFolders || hasInvisibleContent) {\n return Result.fail(new FolderNotAuthorizedError());\n }\n\n return Result.ok();\n }\n}\n\nexport const EnsureFolderIsEmpty = Abstraction.createImplementation({\n implementation: EnsureFolderIsEmptyImpl,\n dependencies: [IdentityContext, ListFoldersUseCase, Logger]\n});\n"],"names":["EnsureFolderIsEmptyImpl","identityContext","listFoldersUseCase","logger","type","id","hasContentCallback","hasFoldersCallback","result","folders","hasFolders","hasContent","Promise","Result","FolderNotEmptyError","hasInvisibleFolders","hasInvisibleContent","FolderNotAuthorizedError","EnsureFolderIsEmpty","Abstraction","IdentityContext","ListFoldersUseCase","Logger"],"mappings":";;;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,kBAAgD,EAChDC,MAAwB,CAClC;aAHUF,eAAe,GAAfA;aACAC,kBAAkB,GAAlBA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,QACFC,IAAY,EACZC,EAAU,EACVC,kBAAkD,EAChC;QAClB,MAAMC,qBAAqB;YACvB,MAAMC,SAAS,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBACjD,OAAO;oBACHJ;oBACA,UAAUC;gBACd;gBACA,OAAO;YACX;YACA,IAAIG,OAAO,MAAM,IAAI;gBACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAACA,OAAO,KAAK;gBAE9B,OAAO;YACX;YAEA,MAAM,EAAEC,OAAO,EAAE,GAAGD,OAAO,KAAK;YAEhC,OAAOC,QAAQ,MAAM,GAAG;QAC5B;QAEA,MAAM,CAACC,YAAYC,WAAW,GAAG,MAAMC,QAAQ,GAAG,CAAC;YAC/CL;YACAD;SACH;QAED,IAAII,cAAcC,YACd,OAAOE,OAAO,IAAI,CAAC,IAAIC;QAM3B,MAAM,CAACC,qBAAqBC,oBAAoB,GAC5C,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC;YAC5C,MAAM,CAACN,YAAYC,WAAW,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBAC/CL;gBACAD;aACH;YACD,OAAO;gBAACI;gBAAYC;aAAW;QACnC;QAIJ,IAAII,uBAAuBC,qBACvB,OAAOH,OAAO,IAAI,CAAC,IAAII;QAG3B,OAAOJ,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMK,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgBnB;IAChB,cAAc;QAACoB;QAAiBC;QAAoBC;KAAO;AAC/D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FolderTypeAccess as Abstraction, FolderTypePermissions } from "./abstractions.js";
|
|
2
|
+
declare class FolderTypeAccessImpl implements Abstraction.Interface {
|
|
3
|
+
private permissions;
|
|
4
|
+
constructor(permissions: FolderTypePermissions.Interface[]);
|
|
5
|
+
canRead(type: string): Promise<boolean>;
|
|
6
|
+
canWrite(type: string): Promise<boolean>;
|
|
7
|
+
}
|
|
8
|
+
export declare const FolderTypeAccess: typeof FolderTypeAccessImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFolderTypeAccess>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FolderTypeAccess, FolderTypePermissions } from "./abstractions.js";
|
|
2
|
+
class FolderTypeAccessImpl {
|
|
3
|
+
constructor(permissions){
|
|
4
|
+
this.permissions = permissions;
|
|
5
|
+
}
|
|
6
|
+
async canRead(type) {
|
|
7
|
+
const handler = this.permissions.find((p)=>p.canHandle(type));
|
|
8
|
+
return handler ? handler.canRead(type) : true;
|
|
9
|
+
}
|
|
10
|
+
async canWrite(type) {
|
|
11
|
+
const handler = this.permissions.find((p)=>p.canHandle(type));
|
|
12
|
+
return handler ? handler.canWrite(type) : true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const FolderTypeAccess_FolderTypeAccess = FolderTypeAccess.createImplementation({
|
|
16
|
+
implementation: FolderTypeAccessImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
[
|
|
19
|
+
FolderTypePermissions,
|
|
20
|
+
{
|
|
21
|
+
multiple: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { FolderTypeAccess_FolderTypeAccess as FolderTypeAccess };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=FolderTypeAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/FolderTypeAccess.js","sources":["../../../../src/features/folder/FolderTypePermissions/FolderTypeAccess.ts"],"sourcesContent":["import { FolderTypeAccess as Abstraction, FolderTypePermissions } from \"./abstractions.js\";\n\nclass FolderTypeAccessImpl implements Abstraction.Interface {\n constructor(private permissions: FolderTypePermissions.Interface[]) {}\n\n async canRead(type: string): Promise<boolean> {\n const handler = this.permissions.find(p => p.canHandle(type));\n return handler ? handler.canRead(type) : true;\n }\n\n async canWrite(type: string): Promise<boolean> {\n const handler = this.permissions.find(p => p.canHandle(type));\n return handler ? handler.canWrite(type) : true;\n }\n}\n\nexport const FolderTypeAccess = Abstraction.createImplementation({\n implementation: FolderTypeAccessImpl,\n dependencies: [[FolderTypePermissions, { multiple: true }]]\n});\n"],"names":["FolderTypeAccessImpl","permissions","type","handler","p","FolderTypeAccess","Abstraction","FolderTypePermissions"],"mappings":";AAEA,MAAMA;IACF,YAAoBC,WAA8C,CAAE;aAAhDA,WAAW,GAAXA;IAAiD;IAErE,MAAM,QAAQC,IAAY,EAAoB;QAC1C,MAAMC,UAAU,IAAI,CAAC,WAAW,CAAC,IAAI,CAACC,CAAAA,IAAKA,EAAE,SAAS,CAACF;QACvD,OAAOC,UAAUA,QAAQ,OAAO,CAACD,QAAQ;IAC7C;IAEA,MAAM,SAASA,IAAY,EAAoB;QAC3C,MAAMC,UAAU,IAAI,CAAC,WAAW,CAAC,IAAI,CAACC,CAAAA,IAAKA,EAAE,SAAS,CAACF;QACvD,OAAOC,UAAUA,QAAQ,QAAQ,CAACD,QAAQ;IAC9C;AACJ;AAEO,MAAMG,oCAAmBC,iBAAAA,oBAAgC,CAAC;IAC7D,gBAAgBN;IAChB,cAAc;QAAC;YAACO;YAAuB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC/D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App permissions for folders of a given type. Each app that uses folders (File Manager,
|
|
3
|
+
* Website Builder, Headless CMS) registers an implementation for its folder types. These checks
|
|
4
|
+
* come on top of folder level permissions. Folder types no app handles are not restricted.
|
|
5
|
+
*/
|
|
6
|
+
export interface IFolderTypePermissions {
|
|
7
|
+
canHandle(type: string): boolean;
|
|
8
|
+
canRead(type: string): Promise<boolean>;
|
|
9
|
+
canWrite(type: string): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
export declare const FolderTypePermissions: import("@webiny/di").Abstraction<IFolderTypePermissions>;
|
|
12
|
+
export declare namespace FolderTypePermissions {
|
|
13
|
+
type Interface = IFolderTypePermissions;
|
|
14
|
+
}
|
|
15
|
+
/** Resolves the implementation for a folder type and runs its checks. */
|
|
16
|
+
export interface IFolderTypeAccess {
|
|
17
|
+
canRead(type: string): Promise<boolean>;
|
|
18
|
+
canWrite(type: string): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
export declare const FolderTypeAccess: import("@webiny/di").Abstraction<IFolderTypeAccess>;
|
|
21
|
+
export declare namespace FolderTypeAccess {
|
|
22
|
+
type Interface = IFolderTypeAccess;
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const FolderTypePermissions = createAbstraction("Aco/FolderTypePermissions");
|
|
3
|
+
const FolderTypeAccess = createAbstraction("Aco/FolderTypeAccess");
|
|
4
|
+
export { FolderTypeAccess, FolderTypePermissions };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/folder/FolderTypePermissions/abstractions.js","sources":["../../../../src/features/folder/FolderTypePermissions/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * App permissions for folders of a given type. Each app that uses folders (File Manager,\n * Website Builder, Headless CMS) registers an implementation for its folder types. These checks\n * come on top of folder level permissions. Folder types no app handles are not restricted.\n */\nexport interface IFolderTypePermissions {\n canHandle(type: string): boolean;\n canRead(type: string): Promise<boolean>;\n canWrite(type: string): Promise<boolean>;\n}\n\nexport const FolderTypePermissions = createAbstraction<IFolderTypePermissions>(\n \"Aco/FolderTypePermissions\"\n);\n\nexport namespace FolderTypePermissions {\n export type Interface = IFolderTypePermissions;\n}\n\n/** Resolves the implementation for a folder type and runs its checks. */\nexport interface IFolderTypeAccess {\n canRead(type: string): Promise<boolean>;\n canWrite(type: string): Promise<boolean>;\n}\n\nexport const FolderTypeAccess = createAbstraction<IFolderTypeAccess>(\"Aco/FolderTypeAccess\");\n\nexport namespace FolderTypeAccess {\n export type Interface = IFolderTypeAccess;\n}\n"],"names":["FolderTypePermissions","createAbstraction","FolderTypeAccess"],"mappings":";AAaO,MAAMA,wBAAwBC,kBACjC;AAaG,MAAMC,mBAAmBD,kBAAqC"}
|