@webiny/api-aco 6.5.2-beta.0 → 6.5.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createAcoContext.js +2 -0
- package/createAcoContext.js.map +1 -1
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetEntriesByIdsWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetLatestRevisionByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js +28 -0
- package/features/cms/decorators/GetRevisionByIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.d.ts +13 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js +25 -0
- package/features/cms/decorators/GetRevisionsByEntryIdWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.d.ts +16 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js +55 -0
- package/features/cms/decorators/GetUniqueFieldValuesWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/PublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/RepublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.d.ts +17 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js +38 -0
- package/features/cms/decorators/RestoreEntryFromBinWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UnpublishEntryWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.d.ts +1 -0
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js +9 -5
- package/features/cms/decorators/UpdateEntryWithFlpDecorator.js.map +1 -1
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.d.ts +14 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js +30 -0
- package/features/cms/decorators/UpdateRevisionDescriptionWithFlpDecorator.js.map +1 -0
- package/features/cms/decorators/canAccessEntryFolder.d.ts +21 -0
- package/features/cms/decorators/canAccessEntryFolder.js +25 -0
- package/features/cms/decorators/canAccessEntryFolder.js.map +1 -0
- package/features/cms/feature.js +20 -0
- package/features/cms/feature.js.map +1 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js +4 -1
- package/features/flp/CreateFlpOnFolderCreated/CreateFlpOnFolderCreatedHandler.js.map +1 -1
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +1 -1
- package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
- package/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js +2 -1
- package/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js.map +1 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js +3 -1
- package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js +20 -2
- package/features/folder/CreateFolder/decorators/CreateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +1 -5
- package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
- package/features/folder/FolderTypePermissions/FolderTypeAccess.d.ts +11 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js +28 -0
- package/features/folder/FolderTypePermissions/FolderTypeAccess.js.map +1 -0
- package/features/folder/FolderTypePermissions/abstractions.d.ts +23 -0
- package/features/folder/FolderTypePermissions/abstractions.js +6 -0
- package/features/folder/FolderTypePermissions/abstractions.js.map +1 -0
- package/features/folder/FolderTypePermissions/decorators.d.ts +67 -0
- package/features/folder/FolderTypePermissions/decorators.js +128 -0
- package/features/folder/FolderTypePermissions/decorators.js.map +1 -0
- package/features/folder/FolderTypePermissions/feature.d.ts +4 -0
- package/features/folder/FolderTypePermissions/feature.js +18 -0
- package/features/folder/FolderTypePermissions/feature.js.map +1 -0
- package/features/folder/FolderTypePermissions/index.d.ts +2 -0
- package/features/folder/FolderTypePermissions/index.js +2 -0
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +8 -2
- package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
- package/features/folder/GetFolderHierarchy/abstractions.d.ts +3 -1
- package/features/folder/GetFolderHierarchy/abstractions.js.map +1 -1
- package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +5 -0
- package/features/folder/UpdateFolder/UpdateFolderRepository.js +33 -5
- package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.d.ts +1 -1
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +21 -5
- package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
- package/features/folder/shared/validatePermissionsInput.d.ts +7 -0
- package/features/folder/shared/validatePermissionsInput.js +12 -0
- package/features/folder/shared/validatePermissionsInput.js.map +1 -0
- package/filter/filter.so.js +12 -5
- package/filter/filter.so.js.map +1 -1
- package/package.json +21 -21
|
@@ -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"}
|
|
@@ -18,7 +18,7 @@ class FolderLevelPermissionsImpl {
|
|
|
18
18
|
canUseFolderLevelPermissions(enabled) {
|
|
19
19
|
if (false === enabled) return false;
|
|
20
20
|
const identity = this.identityContext.getIdentity();
|
|
21
|
-
if (
|
|
21
|
+
if (identity.isAnonymous()) return false;
|
|
22
22
|
if ("admin" !== identity.type) return false;
|
|
23
23
|
return this.wcpContext.canUseFolderLevelPermissions();
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/FolderLevelPermissions/FolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/FolderLevelPermissions.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { WcpContext } from \"@webiny/api-core/features/wcp/WcpContext/index.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport {\n CanAccessFolder,\n CanAccessFolderContent,\n type CanAccessFolderContentParams,\n type CanAccessFolderParams,\n CanCreateFolderInRoot,\n CheckNotInheritedPermissions,\n GetDefaultPermissions,\n GetDefaultPermissionsWithTeams\n} from \"./useCases/index.js\";\nimport { FolderLevelPermissions as FolderLevelPermissionsAbstraction } from \"./abstractions.js\";\nimport type { FolderLevelPermission, FolderPermission, ListFlpsParams } from \"~/types.js\";\nimport { ListFlpsUseCase } from \"~/features/flp/ListFlps/index.js\";\nimport { GetFlpUseCase } from \"~/features/flp/GetFlp/index.js\";\n\nclass FolderLevelPermissionsImpl implements FolderLevelPermissionsAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private wcpContext: WcpContext.Interface,\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n private getFlpUseCase: GetFlpUseCase.Interface,\n private listFlpsUseCase: ListFlpsUseCase.Interface\n ) {}\n\n public canUseFolderLevelPermissions(enabled?: boolean): boolean {\n if (enabled === false) {\n return false;\n }\n\n const identity = this.identityContext.getIdentity();\n\n // FLPs only work with authenticated identities (logged-in users).\n if (!identity) {\n return false;\n }\n\n // At the moment, we only want FLP to be used with identities of type \"admin\".\n // This temporarily addresses the issue of API keys not being able to access content, because\n // FLPs doesn't work with them. Once we start adding FLPs to API keys, we can remove this check.\n if (identity.type !== \"admin\") {\n return false;\n }\n\n return this.wcpContext.canUseFolderLevelPermissions();\n }\n\n public canUseTeams(): boolean {\n return this.wcpContext.canUseTeams();\n }\n\n public canCreateFolderInRoot(): boolean {\n const canCreateFolderInRootUseCase = new CanCreateFolderInRoot();\n return canCreateFolderInRootUseCase.execute();\n }\n\n public permissionsIncludeNonInheritedPermissions(permissions: FolderPermission[]): boolean {\n const checkNotInheritedPermissionsUseCase = new CheckNotInheritedPermissions();\n return checkNotInheritedPermissionsUseCase.execute(permissions);\n }\n\n public async canAccessFolder(params: CanAccessFolderParams): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n const canAccessFolderUseCase = new CanAccessFolder(this.identityContext);\n return await canAccessFolderUseCase.execute(params);\n }\n\n public async canAccessFolderContent(params: CanAccessFolderContentParams): Promise<boolean> {\n const canUseFlp = this.canUseFolderLevelPermissions();\n const authEnabled = this.identityContext.isAuthorizationEnabled();\n\n if (!canUseFlp || !authEnabled) {\n return true;\n }\n\n const canAccessFolderContentUseCase = new CanAccessFolderContent(this.identityContext);\n return await canAccessFolderContentUseCase.execute(params);\n }\n\n public async ensureCanAccessFolder(params: CanAccessFolderParams): Promise<void> {\n const result = await this.canAccessFolder(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async ensureCanAccessFolderContent(params: CanAccessFolderContentParams): Promise<void> {\n const result = await this.canAccessFolderContent(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async canManageFolderContent(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolderContent({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderStructure(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolder({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderPermissions(flp: FolderLevelPermission): Promise<boolean> {\n if (!this.canUseFolderLevelPermissions()) {\n return false;\n }\n\n if (!this.identityContext.isAuthorizationEnabled()) {\n return true;\n }\n\n return await this.canAccessFolder({\n permissions: flp.permissions,\n rwd: \"w\",\n managePermissions: true\n });\n }\n\n public getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n const getDefaultPermissionsUseCase = new GetDefaultPermissions(this.identityContext);\n\n if (this.canUseTeams()) {\n const getDefaultPermissionsWithTeams = new GetDefaultPermissionsWithTeams(\n this.identityContext,\n this.listUserTeamsUseCase,\n getDefaultPermissionsUseCase\n );\n\n return getDefaultPermissionsWithTeams.execute(permissions);\n }\n\n return getDefaultPermissionsUseCase.execute(permissions);\n }\n\n public async listFolderLevelPermissions(params: ListFlpsParams): Promise<\n Array<{\n id: string;\n permissions: FolderPermission[];\n }>\n > {\n const flps = await this.listFlpsUseCase.execute(params);\n\n return Promise.all(\n flps.map(async flp => ({\n id: flp.id,\n permissions: await this.getDefaultPermissions(flp.permissions)\n }))\n );\n }\n\n public async getFolderLevelPermissions(id: string): Promise<FolderPermission[]> {\n const flp = await this.getFlpUseCase.execute(id);\n return await this.getDefaultPermissions(flp?.permissions ?? []);\n }\n}\n\nexport const FolderLevelPermissions = createImplementation({\n abstraction: FolderLevelPermissionsAbstraction,\n implementation: FolderLevelPermissionsImpl,\n dependencies: [\n IdentityContext,\n WcpContext,\n ListUserTeamsUseCase,\n GetFlpUseCase,\n ListFlpsUseCase\n ]\n});\n"],"names":["FolderLevelPermissionsImpl","identityContext","wcpContext","listUserTeamsUseCase","getFlpUseCase","listFlpsUseCase","enabled","identity","canCreateFolderInRootUseCase","CanCreateFolderInRoot","permissions","checkNotInheritedPermissionsUseCase","CheckNotInheritedPermissions","params","canAccessFolderUseCase","CanAccessFolder","canUseFlp","authEnabled","canAccessFolderContentUseCase","CanAccessFolderContent","result","NotAuthorizedError","flp","getDefaultPermissionsUseCase","GetDefaultPermissions","getDefaultPermissionsWithTeams","GetDefaultPermissionsWithTeams","flps","Promise","id","FolderLevelPermissions","createImplementation","FolderLevelPermissionsAbstraction","IdentityContext","WcpContext","ListUserTeamsUseCase","GetFlpUseCase","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A6B,OAAO,CAACb;IAChD;IAEA,MAAa,2BAA2BG,MAAsB,EAK5D;QACE,MAAMc,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACd;QAEhD,OAAOe,QAAQ,GAAG,CACdD,KAAK,GAAG,CAAC,OAAML,MAAQ;gBACnB,IAAIA,IAAI,EAAE;gBACV,aAAa,MAAM,IAAI,CAAC,qBAAqB,CAACA,IAAI,WAAW;YACjE;IAER;IAEA,MAAa,0BAA0BO,EAAU,EAA+B;QAC5E,MAAMP,MAAM,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACO;QAC7C,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAACP,KAAK,eAAe,EAAE;IAClE;AACJ;AAEO,MAAMQ,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBhC;IAChB,cAAc;QACViC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"features/flp/FolderLevelPermissions/FolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/FolderLevelPermissions.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { WcpContext } from \"@webiny/api-core/features/wcp/WcpContext/index.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport {\n CanAccessFolder,\n CanAccessFolderContent,\n type CanAccessFolderContentParams,\n type CanAccessFolderParams,\n CanCreateFolderInRoot,\n CheckNotInheritedPermissions,\n GetDefaultPermissions,\n GetDefaultPermissionsWithTeams\n} from \"./useCases/index.js\";\nimport { FolderLevelPermissions as FolderLevelPermissionsAbstraction } from \"./abstractions.js\";\nimport type { FolderLevelPermission, FolderPermission, ListFlpsParams } from \"~/types.js\";\nimport { ListFlpsUseCase } from \"~/features/flp/ListFlps/index.js\";\nimport { GetFlpUseCase } from \"~/features/flp/GetFlp/index.js\";\n\nclass FolderLevelPermissionsImpl implements FolderLevelPermissionsAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private wcpContext: WcpContext.Interface,\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n private getFlpUseCase: GetFlpUseCase.Interface,\n private listFlpsUseCase: ListFlpsUseCase.Interface\n ) {}\n\n public canUseFolderLevelPermissions(enabled?: boolean): boolean {\n if (enabled === false) {\n return false;\n }\n\n const identity = this.identityContext.getIdentity();\n\n // FLPs only work with authenticated identities (logged-in users).\n if (identity.isAnonymous()) {\n return false;\n }\n\n // At the moment, we only want FLP to be used with identities of type \"admin\".\n // This temporarily addresses the issue of API keys not being able to access content, because\n // FLPs doesn't work with them. Once we start adding FLPs to API keys, we can remove this check.\n if (identity.type !== \"admin\") {\n return false;\n }\n\n return this.wcpContext.canUseFolderLevelPermissions();\n }\n\n public canUseTeams(): boolean {\n return this.wcpContext.canUseTeams();\n }\n\n public canCreateFolderInRoot(): boolean {\n const canCreateFolderInRootUseCase = new CanCreateFolderInRoot();\n return canCreateFolderInRootUseCase.execute();\n }\n\n public permissionsIncludeNonInheritedPermissions(permissions: FolderPermission[]): boolean {\n const checkNotInheritedPermissionsUseCase = new CheckNotInheritedPermissions();\n return checkNotInheritedPermissionsUseCase.execute(permissions);\n }\n\n public async canAccessFolder(params: CanAccessFolderParams): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n const canAccessFolderUseCase = new CanAccessFolder(this.identityContext);\n return await canAccessFolderUseCase.execute(params);\n }\n\n public async canAccessFolderContent(params: CanAccessFolderContentParams): Promise<boolean> {\n const canUseFlp = this.canUseFolderLevelPermissions();\n const authEnabled = this.identityContext.isAuthorizationEnabled();\n\n if (!canUseFlp || !authEnabled) {\n return true;\n }\n\n const canAccessFolderContentUseCase = new CanAccessFolderContent(this.identityContext);\n return await canAccessFolderContentUseCase.execute(params);\n }\n\n public async ensureCanAccessFolder(params: CanAccessFolderParams): Promise<void> {\n const result = await this.canAccessFolder(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async ensureCanAccessFolderContent(params: CanAccessFolderContentParams): Promise<void> {\n const result = await this.canAccessFolderContent(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async canManageFolderContent(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolderContent({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderStructure(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolder({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderPermissions(flp: FolderLevelPermission): Promise<boolean> {\n if (!this.canUseFolderLevelPermissions()) {\n return false;\n }\n\n if (!this.identityContext.isAuthorizationEnabled()) {\n return true;\n }\n\n return await this.canAccessFolder({\n permissions: flp.permissions,\n rwd: \"w\",\n managePermissions: true\n });\n }\n\n public getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n const getDefaultPermissionsUseCase = new GetDefaultPermissions(this.identityContext);\n\n if (this.canUseTeams()) {\n const getDefaultPermissionsWithTeams = new GetDefaultPermissionsWithTeams(\n this.identityContext,\n this.listUserTeamsUseCase,\n getDefaultPermissionsUseCase\n );\n\n return getDefaultPermissionsWithTeams.execute(permissions);\n }\n\n return getDefaultPermissionsUseCase.execute(permissions);\n }\n\n public async listFolderLevelPermissions(params: ListFlpsParams): Promise<\n Array<{\n id: string;\n permissions: FolderPermission[];\n }>\n > {\n const flps = await this.listFlpsUseCase.execute(params);\n\n return Promise.all(\n flps.map(async flp => ({\n id: flp.id,\n permissions: await this.getDefaultPermissions(flp.permissions)\n }))\n );\n }\n\n public async getFolderLevelPermissions(id: string): Promise<FolderPermission[]> {\n const flp = await this.getFlpUseCase.execute(id);\n return await this.getDefaultPermissions(flp?.permissions ?? []);\n }\n}\n\nexport const FolderLevelPermissions = createImplementation({\n abstraction: FolderLevelPermissionsAbstraction,\n implementation: FolderLevelPermissionsImpl,\n dependencies: [\n IdentityContext,\n WcpContext,\n ListUserTeamsUseCase,\n GetFlpUseCase,\n ListFlpsUseCase\n ]\n});\n"],"names":["FolderLevelPermissionsImpl","identityContext","wcpContext","listUserTeamsUseCase","getFlpUseCase","listFlpsUseCase","enabled","identity","canCreateFolderInRootUseCase","CanCreateFolderInRoot","permissions","checkNotInheritedPermissionsUseCase","CheckNotInheritedPermissions","params","canAccessFolderUseCase","CanAccessFolder","canUseFlp","authEnabled","canAccessFolderContentUseCase","CanAccessFolderContent","result","NotAuthorizedError","flp","getDefaultPermissionsUseCase","GetDefaultPermissions","getDefaultPermissionsWithTeams","GetDefaultPermissionsWithTeams","flps","Promise","id","FolderLevelPermissions","createImplementation","FolderLevelPermissionsAbstraction","IdentityContext","WcpContext","ListUserTeamsUseCase","GetFlpUseCase","ListFlpsUseCase"],"mappings":";;;;;;;;;AAoBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,UAAgC,EAChCC,oBAAoD,EACpDC,aAAsC,EACtCC,eAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEI,6BAA6BC,OAAiB,EAAW;QAC5D,IAAIA,AAAY,UAAZA,SACA,OAAO;QAGX,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,IACpB,OAAO;QAMX,IAAIA,AAAkB,YAAlBA,SAAS,IAAI,EACb,OAAO;QAGX,OAAO,IAAI,CAAC,UAAU,CAAC,4BAA4B;IACvD;IAEO,cAAuB;QAC1B,OAAO,IAA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AChB,cAAc;QACViC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -6,12 +6,13 @@ class GetDefaultPermissionsWithTeams {
|
|
|
6
6
|
}
|
|
7
7
|
async execute(originalPermissions) {
|
|
8
8
|
const identity = this.identityContext.getIdentity();
|
|
9
|
+
if (identity.isAnonymous()) return await this.decoretee.execute(originalPermissions);
|
|
9
10
|
const listTeamsResult = await this.listUserTeamsUseCase.execute(identity.id);
|
|
10
11
|
const identityTeams = listTeamsResult.isOk() ? listTeamsResult.value : [];
|
|
11
12
|
const permissions = [
|
|
12
13
|
...originalPermissions
|
|
13
14
|
];
|
|
14
|
-
if (
|
|
15
|
+
if (identityTeams.length) for (const identityTeam of identityTeams){
|
|
15
16
|
const teamPermission = permissions.find((p)=>p.target === `team:${identityTeam.slug}`);
|
|
16
17
|
if (teamPermission) permissions.push({
|
|
17
18
|
target: `admin:${identity.id}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js","sources":["../../../../../../src/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.ts"],"sourcesContent":["import type { IGetDefaultPermissions } from \"./IGetDefaultPermissions.js\";\nimport type { FolderPermission } from \"~/flp/flp.types.js\";\nimport type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport type { Team } from \"@webiny/api-core/types/security.js\";\n\nexport class GetDefaultPermissionsWithTeams implements IGetDefaultPermissions {\n private identityContext: IdentityContext.Interface;\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface;\n private decoretee: IGetDefaultPermissions;\n\n constructor(\n identityContext: IdentityContext.Interface,\n listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n decoretee: IGetDefaultPermissions\n ) {\n this.identityContext = identityContext;\n this.listUserTeamsUseCase = listUserTeamsUseCase;\n this.decoretee = decoretee;\n }\n\n async execute(originalPermissions: FolderPermission[]) {\n /**\n * Retrieves the list of teams the current identity belongs to and checks if any of these teams\n * have permissions for the folder. If a team has permissions, the current identity is granted\n * the same permissions, inheriting them from the team.\n */\n const identity = this.identityContext.getIdentity();\n\n // Get teams for current identity\n const listTeamsResult = await this.listUserTeamsUseCase.execute(identity.id);\n const identityTeams: Team[] = listTeamsResult.isOk() ? listTeamsResult.value : [];\n\n const permissions = [...originalPermissions]; // Clone the original permissions to avoid mutation.\n\n if (
|
|
1
|
+
{"version":3,"file":"features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js","sources":["../../../../../../src/features/flp/FolderLevelPermissions/useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.ts"],"sourcesContent":["import type { IGetDefaultPermissions } from \"./IGetDefaultPermissions.js\";\nimport type { FolderPermission } from \"~/flp/flp.types.js\";\nimport type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport type { Team } from \"@webiny/api-core/types/security.js\";\n\nexport class GetDefaultPermissionsWithTeams implements IGetDefaultPermissions {\n private identityContext: IdentityContext.Interface;\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface;\n private decoretee: IGetDefaultPermissions;\n\n constructor(\n identityContext: IdentityContext.Interface,\n listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n decoretee: IGetDefaultPermissions\n ) {\n this.identityContext = identityContext;\n this.listUserTeamsUseCase = listUserTeamsUseCase;\n this.decoretee = decoretee;\n }\n\n async execute(originalPermissions: FolderPermission[]) {\n /**\n * Retrieves the list of teams the current identity belongs to and checks if any of these teams\n * have permissions for the folder. If a team has permissions, the current identity is granted\n * the same permissions, inheriting them from the team.\n */\n const identity = this.identityContext.getIdentity();\n\n // Anonymous identities belong to no teams.\n if (identity.isAnonymous()) {\n return await this.decoretee.execute(originalPermissions);\n }\n\n // Get teams for current identity\n const listTeamsResult = await this.listUserTeamsUseCase.execute(identity.id);\n const identityTeams: Team[] = listTeamsResult.isOk() ? listTeamsResult.value : [];\n\n const permissions = [...originalPermissions]; // Clone the original permissions to avoid mutation.\n\n if (identityTeams.length) {\n for (const identityTeam of identityTeams) {\n // Check if the team has permissions for the folder.\n const teamPermission = permissions.find(\n p => p.target === `team:${identityTeam.slug}`\n );\n\n if (teamPermission) {\n // Grant the current identity the same permissions as the team, marking them as inherited.\n permissions.push({\n target: `admin:${identity.id}`,\n level: teamPermission.level,\n inheritedFrom: \"team:\" + identityTeam.slug\n });\n }\n }\n }\n\n return await this.decoretee.execute(permissions);\n }\n}\n"],"names":["GetDefaultPermissionsWithTeams","identityContext","listUserTeamsUseCase","decoretee","originalPermissions","identity","listTeamsResult","identityTeams","permissions","identityTeam","teamPermission","p"],"mappings":"AAMO,MAAMA;IAKT,YACIC,eAA0C,EAC1CC,oBAAoD,EACpDC,SAAiC,CACnC;QACE,IAAI,CAAC,eAAe,GAAGF;QACvB,IAAI,CAAC,oBAAoB,GAAGC;QAC5B,IAAI,CAAC,SAAS,GAAGC;IACrB;IAEA,MAAM,QAAQC,mBAAuC,EAAE;QAMnD,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,IACpB,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QAIxC,MAAME,kBAAkB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACD,SAAS,EAAE;QAC3E,MAAME,gBAAwBD,gBAAgB,IAAI,KAAKA,gBAAgB,KAAK,GAAG,EAAE;QAEjF,MAAME,cAAc;eAAIJ;SAAoB;QAE5C,IAAIG,cAAc,MAAM,EACpB,KAAK,MAAME,gBAAgBF,cAAe;YAEtC,MAAMG,iBAAiBF,YAAY,IAAI,CACnCG,CAAAA,IAAKA,EAAE,MAAM,KAAK,CAAC,KAAK,EAAEF,aAAa,IAAI,EAAE;YAGjD,IAAIC,gBAEAF,YAAY,IAAI,CAAC;gBACb,QAAQ,CAAC,MAAM,EAAEH,SAAS,EAAE,EAAE;gBAC9B,OAAOK,eAAe,KAAK;gBAC3B,eAAe,UAAUD,aAAa,IAAI;YAC9C;QAER;QAGJ,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;IACxC;AACJ"}
|
|
@@ -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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M;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,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I,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
|
]
|