@webiny/api-headless-cms-bulk-actions 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0
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/HcmsBulkActionsFeature.d.ts +7 -0
- package/HcmsBulkActionsFeature.js +32 -0
- package/HcmsBulkActionsFeature.js.map +1 -0
- package/abstractions/IUseCase.js +0 -3
- package/abstractions/index.js +0 -3
- package/domain/BulkActionName.js +9 -15
- package/domain/BulkActionName.js.map +1 -1
- package/exports/api/cms/entry.d.ts +1 -0
- package/exports/api/cms/entry.js +1 -0
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.d.ts +1 -1
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js +23 -20
- package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js.map +1 -1
- package/features/DeleteEntriesBulkAction/feature.d.ts +4 -1
- package/features/DeleteEntriesBulkAction/feature.js +6 -5
- package/features/DeleteEntriesBulkAction/feature.js.map +1 -1
- package/features/EntriesBulkAction/abstractions.d.ts +7 -7
- package/features/EntriesBulkAction/abstractions.js +3 -2
- package/features/EntriesBulkAction/abstractions.js.map +1 -1
- package/features/EntriesBulkAction/createBulkActionTasks.d.ts +67 -2
- package/features/EntriesBulkAction/createBulkActionTasks.js +157 -125
- package/features/EntriesBulkAction/createBulkActionTasks.js.map +1 -1
- package/features/EntriesBulkAction/internals/ChildTasksCleanup.d.ts +9 -6
- package/features/EntriesBulkAction/internals/ChildTasksCleanup.js +37 -65
- package/features/EntriesBulkAction/internals/ChildTasksCleanup.js.map +1 -1
- package/features/EntriesBulkAction/internals/CreateTasksByModel.d.ts +5 -4
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js +69 -99
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTask.d.ts +4 -2
- package/features/EntriesBulkAction/internals/ProcessTask.js +39 -68
- package/features/EntriesBulkAction/internals/ProcessTask.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTaskResult.js +20 -19
- package/features/EntriesBulkAction/internals/ProcessTaskResult.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.d.ts +3 -3
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js +40 -51
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js.map +1 -1
- package/features/EntriesBulkAction/internals/TaskCache.d.ts +7 -5
- package/features/EntriesBulkAction/internals/TaskCache.js +36 -64
- package/features/EntriesBulkAction/internals/TaskCache.js.map +1 -1
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.d.ts +1 -1
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js +20 -21
- package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js.map +1 -1
- package/features/MoveToFolderBulkAction/feature.d.ts +4 -1
- package/features/MoveToFolderBulkAction/feature.js +6 -5
- package/features/MoveToFolderBulkAction/feature.js.map +1 -1
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.d.ts +1 -1
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js +23 -20
- package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js.map +1 -1
- package/features/MoveToTrashBulkAction/feature.d.ts +4 -1
- package/features/MoveToTrashBulkAction/feature.js +6 -5
- package/features/MoveToTrashBulkAction/feature.js.map +1 -1
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.d.ts +1 -1
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js +27 -29
- package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js.map +1 -1
- package/features/PublishEntriesBulkAction/feature.d.ts +4 -1
- package/features/PublishEntriesBulkAction/feature.js +6 -5
- package/features/PublishEntriesBulkAction/feature.js.map +1 -1
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.d.ts +1 -1
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js +21 -18
- package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js.map +1 -1
- package/features/RestoreEntriesBulkAction/feature.d.ts +4 -1
- package/features/RestoreEntriesBulkAction/feature.js +6 -5
- package/features/RestoreEntriesBulkAction/feature.js.map +1 -1
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.d.ts +1 -1
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js +20 -19
- package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js.map +1 -1
- package/features/UnpublishEntriesBulkAction/feature.d.ts +4 -1
- package/features/UnpublishEntriesBulkAction/feature.js +6 -5
- package/features/UnpublishEntriesBulkAction/feature.js.map +1 -1
- package/graphql/BulkActionsGraphQLSchema.d.ts +12 -0
- package/graphql/BulkActionsGraphQLSchema.js +124 -0
- package/graphql/BulkActionsGraphQLSchema.js.map +1 -0
- package/graphql/bulkActionAccess.d.ts +22 -0
- package/graphql/bulkActionAccess.js +94 -0
- package/graphql/bulkActionAccess.js.map +1 -0
- package/graphql/createBulkActionGraphQL.js +50 -53
- package/graphql/createBulkActionGraphQL.js.map +1 -1
- package/graphql/createDefaultGraphQL.d.ts +7 -2
- package/graphql/createDefaultGraphQL.js +37 -38
- package/graphql/createDefaultGraphQL.js.map +1 -1
- package/index.d.ts +2 -7
- package/index.js +1 -50
- package/package.json +28 -21
- package/tasks/{EmptyTrashBinTaskDefinition.d.ts → EmptyTrashBinTask.d.ts} +10 -4
- package/tasks/EmptyTrashBinTask.js +120 -0
- package/tasks/EmptyTrashBinTask.js.map +1 -0
- package/types.d.ts +4 -2
- package/types.js +7 -18
- package/types.js.map +1 -1
- package/abstractions/IUseCase.js.map +0 -1
- package/abstractions/index.js.map +0 -1
- package/features/BulkActionContext/abstractions.d.ts +0 -5
- package/features/BulkActionContext/abstractions.js +0 -6
- package/features/BulkActionContext/abstractions.js.map +0 -1
- package/features/BulkActionContext/index.d.ts +0 -1
- package/features/BulkActionContext/index.js +0 -3
- package/features/BulkActionContext/index.js.map +0 -1
- package/handlers/eventBridgeEventHandler.d.ts +0 -1
- package/handlers/eventBridgeEventHandler.js +0 -46
- package/handlers/eventBridgeEventHandler.js.map +0 -1
- package/handlers/index.d.ts +0 -1
- package/handlers/index.js +0 -7
- package/handlers/index.js.map +0 -1
- package/handlers/setupEventsTenant.d.ts +0 -1
- package/handlers/setupEventsTenant.js +0 -12
- package/handlers/setupEventsTenant.js.map +0 -1
- package/index.js.map +0 -1
- package/tasks/EmptyTrashBinTaskDefinition.js +0 -124
- package/tasks/EmptyTrashBinTaskDefinition.js.map +0 -1
- package/tasks/createEmptyTrashBinsTask.d.ts +0 -1
- package/tasks/createEmptyTrashBinsTask.js +0 -9
- package/tasks/createEmptyTrashBinsTask.js.map +0 -1
- package/tasks/index.d.ts +0 -1
- package/tasks/index.js +0 -3
- package/tasks/index.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { RestoreEntriesBulkAction } from "./RestoreEntriesBulkAction.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const RestoreEntriesBulkActionFeature = createFeature({
|
|
4
|
+
name: "HeadlessCms/BulkAction/RestoreEntries",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(RestoreEntriesBulkAction);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { RestoreEntriesBulkActionFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/RestoreEntriesBulkAction/feature.js","sources":["../../../src/features/RestoreEntriesBulkAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RestoreEntriesBulkAction } from \"./RestoreEntriesBulkAction.js\";\n\nexport const RestoreEntriesBulkActionFeature = createFeature({\n name: \"HeadlessCms/BulkAction/RestoreEntries\",\n register(container) {\n container.register(RestoreEntriesBulkAction);\n }\n});\n"],"names":["RestoreEntriesBulkActionFeature","createFeature","container","RestoreEntriesBulkAction"],"mappings":";;AAGO,MAAMA,kCAAkCC,cAAc;IACzD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -10,6 +10,6 @@ declare class UnpublishEntriesBulkActionImpl implements EntriesBulkAction.Interf
|
|
|
10
10
|
processData(model: EntriesBulkAction.Model, params: EntriesBulkAction.ProcessParams): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
export declare const UnpublishEntriesBulkAction: typeof UnpublishEntriesBulkActionImpl & {
|
|
13
|
-
__abstraction: import("@webiny/di").Abstraction<import("~/features/EntriesBulkAction/abstractions.js").IEntriesBulkAction
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/features/EntriesBulkAction/abstractions.js").IEntriesBulkAction<Record<string, any>>>;
|
|
14
14
|
};
|
|
15
15
|
export {};
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { ListPublishedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
2
2
|
import { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/index.js";
|
|
3
|
-
import { parseIdentifier } from "@webiny/utils";
|
|
4
3
|
import { EntriesBulkAction } from "../EntriesBulkAction/abstractions.js";
|
|
5
4
|
class UnpublishEntriesBulkActionImpl {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
await this.unpublishEntry.execute(model, entryId);
|
|
20
|
-
}
|
|
5
|
+
constructor(listPublishedEntries, unpublishEntry){
|
|
6
|
+
this.listPublishedEntries = listPublishedEntries;
|
|
7
|
+
this.unpublishEntry = unpublishEntry;
|
|
8
|
+
this.name = "unpublish";
|
|
9
|
+
}
|
|
10
|
+
async loadData(model, params) {
|
|
11
|
+
const entriesResult = await this.listPublishedEntries.execute(model, params);
|
|
12
|
+
if (entriesResult.isFail()) throw entriesResult.error;
|
|
13
|
+
return entriesResult.value;
|
|
14
|
+
}
|
|
15
|
+
async processData(model, params) {
|
|
16
|
+
await this.unpublishEntry.execute(model, params.id);
|
|
17
|
+
}
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const UnpublishEntriesBulkAction = EntriesBulkAction.createImplementation({
|
|
20
|
+
implementation: UnpublishEntriesBulkActionImpl,
|
|
21
|
+
dependencies: [
|
|
22
|
+
ListPublishedEntriesUseCase,
|
|
23
|
+
UnpublishEntryUseCase
|
|
24
|
+
]
|
|
25
25
|
});
|
|
26
|
+
export { UnpublishEntriesBulkAction };
|
|
26
27
|
|
|
27
28
|
//# sourceMappingURL=UnpublishEntriesBulkAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js","sources":["../../../src/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.ts"],"sourcesContent":["import { ListPublishedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\n\nclass UnpublishEntriesBulkActionImpl implements EntriesBulkAction.Interface {\n readonly name = \"unpublish\";\n\n constructor(\n private listPublishedEntries: ListPublishedEntriesUseCase.Interface,\n private unpublishEntry: UnpublishEntryUseCase.Interface\n ) {}\n\n async loadData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.LoadDataParams\n ): Promise<EntriesBulkAction.LoadDataResult> {\n const entriesResult = await this.listPublishedEntries.execute(model, params);\n if (entriesResult.isFail()) {\n throw entriesResult.error;\n }\n\n return entriesResult.value;\n }\n\n async processData(\n model: EntriesBulkAction.Model,\n params: EntriesBulkAction.ProcessParams\n ): Promise<void> {\n await this.unpublishEntry.execute(model, params.id);\n }\n}\n\nexport const UnpublishEntriesBulkAction = EntriesBulkAction.createImplementation({\n implementation: UnpublishEntriesBulkActionImpl,\n dependencies: [ListPublishedEntriesUseCase, UnpublishEntryUseCase]\n});\n"],"names":["UnpublishEntriesBulkActionImpl","listPublishedEntries","unpublishEntry","model","params","entriesResult","UnpublishEntriesBulkAction","EntriesBulkAction","ListPublishedEntriesUseCase","UnpublishEntryUseCase"],"mappings":";;;AAIA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,cAA+C,CACzD;aAFUD,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aAJH,IAAI,GAAG;IAKb;IAEH,MAAM,SACFC,KAA8B,EAC9BC,MAAwC,EACC;QACzC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACF,OAAOC;QACrE,IAAIC,cAAc,MAAM,IACpB,MAAMA,cAAc,KAAK;QAG7B,OAAOA,cAAc,KAAK;IAC9B;IAEA,MAAM,YACFF,KAA8B,EAC9BC,MAAuC,EAC1B;QACb,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACD,OAAOC,OAAO,EAAE;IACtD;AACJ;AAEO,MAAME,6BAA6BC,kBAAkB,oBAAoB,CAAC;IAC7E,gBAAgBP;IAChB,cAAc;QAACQ;QAA6BC;KAAsB;AACtE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { UnpublishEntriesBulkAction } from "./UnpublishEntriesBulkAction.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const UnpublishEntriesBulkActionFeature = createFeature({
|
|
4
|
+
name: "HeadlessCms/BulkAction/UnpublishEntries",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(UnpublishEntriesBulkAction);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { UnpublishEntriesBulkActionFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnpublishEntriesBulkAction/feature.js","sources":["../../../src/features/UnpublishEntriesBulkAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UnpublishEntriesBulkAction } from \"./UnpublishEntriesBulkAction.js\";\n\nexport const UnpublishEntriesBulkActionFeature = createFeature({\n name: \"HeadlessCms/BulkAction/UnpublishEntries\",\n register(container) {\n container.register(UnpublishEntriesBulkAction);\n }\n});\n"],"names":["UnpublishEntriesBulkActionFeature","createFeature","container","UnpublishEntriesBulkAction"],"mappings":";;AAGO,MAAMA,oCAAoCC,cAAc;IAC3D,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
import { CmsGraphQLSchemaPlugin, CmsGraphQLSchemaFactory } from "@webiny/api-headless-cms";
|
|
3
|
+
import type { HcmsBulkActionsContext } from "../types.js";
|
|
4
|
+
declare class BulkActionsGraphQLSchemaImpl implements CmsGraphQLSchemaFactory.Interface {
|
|
5
|
+
private readonly container;
|
|
6
|
+
constructor(container: Container);
|
|
7
|
+
execute(): Promise<CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[]>;
|
|
8
|
+
}
|
|
9
|
+
export declare const BulkActionsGraphQLSchema: typeof BulkActionsGraphQLSchemaImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-headless-cms").ICmsGraphQLSchemaFactory>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { CmsGraphQLSchemaFactory, CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
|
|
2
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
|
+
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
4
|
+
import { ErrorResponse, Response } from "@webiny/api-graphql";
|
|
5
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
6
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
8
|
+
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
9
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
10
|
+
import { TriggerTaskUseCase } from "@webiny/background-tasks/api";
|
|
11
|
+
import { EntriesBulkAction } from "../features/EntriesBulkAction/abstractions.js";
|
|
12
|
+
import { BulkActionName } from "../domain/BulkActionName.js";
|
|
13
|
+
import { BULK_ACTION_LIST_TASK_ID } from "../features/EntriesBulkAction/createBulkActionTasks.js";
|
|
14
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
15
|
+
import { canMoveToFolder, getRequiredAccess, restrictWhere } from "./bulkActionAccess.js";
|
|
16
|
+
class BulkActionsGraphQLSchemaImpl {
|
|
17
|
+
constructor(container){
|
|
18
|
+
this.container = container;
|
|
19
|
+
}
|
|
20
|
+
async execute() {
|
|
21
|
+
const context = {
|
|
22
|
+
container: this.container
|
|
23
|
+
};
|
|
24
|
+
const tenantCtx = this.container.resolve(TenantContext);
|
|
25
|
+
const tenant = tenantCtx.getTenant();
|
|
26
|
+
if (!await isHeadlessCmsReady(context)) return [];
|
|
27
|
+
const identityCtx = this.container.resolve(IdentityContext);
|
|
28
|
+
const modelsResult = await identityCtx.withoutAuthorization(async ()=>this.container.resolve(ListModelsUseCase).execute());
|
|
29
|
+
if (modelsResult.isFail()) return [];
|
|
30
|
+
const allModels = modelsResult.value.filter((model)=>{
|
|
31
|
+
if (model.isPrivate) return false;
|
|
32
|
+
const tags = Array.isArray(model.tags) ? model.tags : [];
|
|
33
|
+
return !tags.includes(CMS_MODEL_SINGLETON_TAG);
|
|
34
|
+
});
|
|
35
|
+
const bulkActions = this.container.resolveAll(EntriesBulkAction);
|
|
36
|
+
const plugins = [];
|
|
37
|
+
const defaultPlugin = new CmsGraphQLSchemaPlugin({
|
|
38
|
+
typeDefs: `
|
|
39
|
+
type BulkActionResponseData {
|
|
40
|
+
id: String
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type BulkActionResponse {
|
|
44
|
+
data: BulkActionResponseData
|
|
45
|
+
error: CmsError
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
});
|
|
49
|
+
defaultPlugin.name = "headless-cms.graphql.schema.bulkAction.default";
|
|
50
|
+
plugins.push(defaultPlugin);
|
|
51
|
+
for (const model of allModels){
|
|
52
|
+
const applicableActions = bulkActions.filter((action)=>{
|
|
53
|
+
if (action.modelIds?.length) return action.modelIds.includes(model.modelId);
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
const enumValues = applicableActions.map((action)=>BulkActionName.from(action.name)).join("\n ");
|
|
57
|
+
const modelPlugin = new CmsGraphQLSchemaPlugin({
|
|
58
|
+
typeDefs: `
|
|
59
|
+
enum BulkAction${model.singularApiName}Name {
|
|
60
|
+
_empty
|
|
61
|
+
${enumValues}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
extend type Mutation {
|
|
65
|
+
bulkAction${model.singularApiName}(
|
|
66
|
+
action: BulkAction${model.singularApiName}Name!
|
|
67
|
+
where: ${model.singularApiName}ListWhereInput
|
|
68
|
+
search: String
|
|
69
|
+
data: JSON
|
|
70
|
+
): BulkActionResponse
|
|
71
|
+
}
|
|
72
|
+
`,
|
|
73
|
+
resolvers: {
|
|
74
|
+
Mutation: {
|
|
75
|
+
[`bulkAction${model.singularApiName}`]: async (_, args, context)=>{
|
|
76
|
+
const canAccess = await context.container.resolve(AccessControl).canAccessEntry({
|
|
77
|
+
model,
|
|
78
|
+
...getRequiredAccess(args.action)
|
|
79
|
+
});
|
|
80
|
+
if (!canAccess) return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));
|
|
81
|
+
if (args.action === BulkActionName.from("moveToFolder")) {
|
|
82
|
+
const folderId = args.data?.folderId;
|
|
83
|
+
if (!folderId) return new ErrorResponse({
|
|
84
|
+
code: "VALIDATION_FAILED",
|
|
85
|
+
message: 'Missing "data.folderId" in the input.'
|
|
86
|
+
});
|
|
87
|
+
if (!await canMoveToFolder(context, folderId)) return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));
|
|
88
|
+
}
|
|
89
|
+
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
90
|
+
const where = await restrictWhere(context, model, args.action, args.where);
|
|
91
|
+
const response = await context.container.resolve(TriggerTaskUseCase).execute({
|
|
92
|
+
definition: BULK_ACTION_LIST_TASK_ID,
|
|
93
|
+
input: {
|
|
94
|
+
actionName: args.action,
|
|
95
|
+
modelId: model.modelId,
|
|
96
|
+
where,
|
|
97
|
+
search: args.search,
|
|
98
|
+
data: args.data,
|
|
99
|
+
identity
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return new Response({
|
|
103
|
+
id: response.value.id
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id && "manage" === context.container.resolve(HeadlessCmsEndpointConfig).type
|
|
109
|
+
});
|
|
110
|
+
modelPlugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}`;
|
|
111
|
+
plugins.push(modelPlugin);
|
|
112
|
+
}
|
|
113
|
+
return plugins;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const BulkActionsGraphQLSchema = CmsGraphQLSchemaFactory.createImplementation({
|
|
117
|
+
implementation: BulkActionsGraphQLSchemaImpl,
|
|
118
|
+
dependencies: [
|
|
119
|
+
RequestContainer
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
export { BulkActionsGraphQLSchema };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=BulkActionsGraphQLSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/BulkActionsGraphQLSchema.js","sources":["../../src/graphql/BulkActionsGraphQLSchema.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { BULK_ACTION_LIST_TASK_ID } from \"~/features/EntriesBulkAction/createBulkActionTasks.js\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport type { HcmsBulkActionsContext } from \"~/types.js\";\nimport { canMoveToFolder, getRequiredAccess, restrictWhere } from \"./bulkActionAccess.js\";\n\nclass BulkActionsGraphQLSchemaImpl implements CmsGraphQLSchemaFactory.Interface {\n constructor(private readonly container: Container) {}\n\n async execute() {\n const context = { container: this.container } as HcmsBulkActionsContext;\n const tenantCtx = this.container.resolve(TenantContext);\n const tenant = tenantCtx.getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return [];\n }\n\n const identityCtx = this.container.resolve(IdentityContext);\n const modelsResult = await identityCtx.withoutAuthorization(async () => {\n return this.container.resolve(ListModelsUseCase).execute();\n });\n\n if (modelsResult.isFail()) {\n return [];\n }\n\n const allModels = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n return !tags.includes(CMS_MODEL_SINGLETON_TAG);\n });\n\n const bulkActions = this.container.resolveAll(EntriesBulkAction);\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n const defaultPlugin = new CmsGraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type BulkActionResponseData {\n id: String\n }\n\n type BulkActionResponse {\n data: BulkActionResponseData\n error: CmsError\n }\n `\n });\n defaultPlugin.name = \"headless-cms.graphql.schema.bulkAction.default\";\n plugins.push(defaultPlugin);\n\n for (const model of allModels) {\n const applicableActions = bulkActions.filter(action => {\n if (action.modelIds?.length) {\n return action.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const enumValues = applicableActions\n .map(action => BulkActionName.from(action.name))\n .join(\"\\n \");\n\n const modelPlugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n enum BulkAction${model.singularApiName}Name {\n _empty\n ${enumValues}\n }\n\n extend type Mutation {\n bulkAction${model.singularApiName}(\n action: BulkAction${model.singularApiName}Name!\n where: ${model.singularApiName}ListWhereInput\n search: String\n data: JSON\n ): BulkActionResponse\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const canAccess = await context.container\n .resolve(AccessControl)\n .canAccessEntry({ model, ...getRequiredAccess(args.action) });\n if (!canAccess) {\n return new ErrorResponse(EntryNotAuthorizedError.fromModel(model));\n }\n\n if (args.action === BulkActionName.from(\"moveToFolder\")) {\n const folderId = args.data?.folderId;\n if (!folderId) {\n return new ErrorResponse({\n code: \"VALIDATION_FAILED\",\n message: `Missing \"data.folderId\" in the input.`\n });\n }\n if (!(await canMoveToFolder(context, folderId))) {\n return new ErrorResponse(\n EntryNotAuthorizedError.fromModel(model)\n );\n }\n }\n\n const identity = context.container\n .resolve(IdentityContext)\n .getIdentity();\n\n /* The task lists and changes entries without authorization, so its\n query is limited here to the entries the caller may act on. */\n const where = await restrictWhere(\n context,\n model,\n args.action,\n args.where\n );\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: BULK_ACTION_LIST_TASK_ID,\n input: {\n actionName: args.action,\n modelId: model.modelId,\n where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id &&\n // Bulk actions change entries: manage endpoint only.\n context.container.resolve(HeadlessCmsEndpointConfig).type === \"manage\"\n });\n\n modelPlugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}`;\n plugins.push(modelPlugin);\n }\n\n return plugins;\n }\n}\n\nexport const BulkActionsGraphQLSchema = CmsGraphQLSchemaFactory.createImplementation({\n implementation: BulkActionsGraphQLSchemaImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["BulkActionsGraphQLSchemaImpl","container","context","tenantCtx","TenantContext","tenant","isHeadlessCmsReady","identityCtx","IdentityContext","modelsResult","ListModelsUseCase","allModels","model","tags","Array","CMS_MODEL_SINGLETON_TAG","bulkActions","EntriesBulkAction","plugins","defaultPlugin","CmsGraphQLSchemaPlugin","applicableActions","action","enumValues","BulkActionName","modelPlugin","_","args","canAccess","AccessControl","getRequiredAccess","ErrorResponse","EntryNotAuthorizedError","folderId","canMoveToFolder","identity","where","restrictWhere","response","TriggerTaskUseCase","BULK_ACTION_LIST_TASK_ID","Response","HeadlessCmsEndpointConfig","BulkActionsGraphQLSchema","CmsGraphQLSchemaFactory","RequestContainer"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAMA;IACF,YAA6BC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAEpD,MAAM,UAAU;QACZ,MAAMC,UAAU;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC;QAC5C,MAAMC,YAAY,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QACzC,MAAMC,SAASF,UAAU,SAAS;QAElC,IAAI,CAAE,MAAMG,mBAAmBJ,UAC3B,OAAO,EAAE;QAGb,MAAMK,cAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC3C,MAAMC,eAAe,MAAMF,YAAY,oBAAoB,CAAC,UACjD,IAAI,CAAC,SAAS,CAAC,OAAO,CAACG,mBAAmB,OAAO;QAG5D,IAAID,aAAa,MAAM,IACnB,OAAO,EAAE;QAGb,MAAME,YAAYF,aAAa,KAAK,CAAC,MAAM,CAACG,CAAAA;YACxC,IAAIA,MAAM,SAAS,EACf,OAAO;YAEX,MAAMC,OAAOC,MAAM,OAAO,CAACF,MAAM,IAAI,IAAIA,MAAM,IAAI,GAAG,EAAE;YACxD,OAAO,CAACC,KAAK,QAAQ,CAACE;QAC1B;QAEA,MAAMC,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC;QAC9C,MAAMC,UAA4D,EAAE;QAEpE,MAAMC,gBAAgB,IAAIC,uBAAuB;YAC7C,UAAwB,CAAC;;;;;;;;;YASzB,CAAC;QACL;QACAD,cAAc,IAAI,GAAG;QACrBD,QAAQ,IAAI,CAACC;QAEb,KAAK,MAAMP,SAASD,UAAW;YAC3B,MAAMU,oBAAoBL,YAAY,MAAM,CAACM,CAAAA;gBACzC,IAAIA,OAAO,QAAQ,EAAE,QACjB,OAAOA,OAAO,QAAQ,CAAC,QAAQ,CAACV,MAAM,OAAO;gBAEjD,OAAO;YACX;YAEA,MAAMW,aAAaF,kBACd,GAAG,CAACC,CAAAA,SAAUE,eAAe,IAAI,CAACF,OAAO,IAAI,GAC7C,IAAI,CAAC;YAEV,MAAMG,cAAc,IAAIL,uBAA+C;gBACnE,UAAwB,CAAC;mCACN,EAAER,MAAM,eAAe,CAAC;;wBAEnC,EAAEW,WAAW;;;;kCAIH,EAAEX,MAAM,eAAe,CAAC;8CACZ,EAAEA,MAAM,eAAe,CAAC;mCACnC,EAAEA,MAAM,eAAe,CAAC;;;;;gBAK3C,CAAC;gBACD,WAAW;oBACP,UAAU;wBACN,CAAC,CAAC,UAAU,EAAEA,MAAM,eAAe,EAAE,CAAC,EAAE,OAAOc,GAAGC,MAAMzB;4BACpD,MAAM0B,YAAY,MAAM1B,QAAQ,SAAS,CACpC,OAAO,CAAC2B,eACR,cAAc,CAAC;gCAAEjB;gCAAO,GAAGkB,kBAAkBH,KAAK,MAAM,CAAC;4BAAC;4BAC/D,IAAI,CAACC,WACD,OAAO,IAAIG,cAAcC,wBAAwB,SAAS,CAACpB;4BAG/D,IAAIe,KAAK,MAAM,KAAKH,eAAe,IAAI,CAAC,iBAAiB;gCACrD,MAAMS,WAAWN,KAAK,IAAI,EAAE;gCAC5B,IAAI,CAACM,UACD,OAAO,IAAIF,cAAc;oCACrB,MAAM;oCACN,SAAS;gCACb;gCAEJ,IAAI,CAAE,MAAMG,gBAAgBhC,SAAS+B,WACjC,OAAO,IAAIF,cACPC,wBAAwB,SAAS,CAACpB;4BAG9C;4BAEA,MAAMuB,WAAWjC,QAAQ,SAAS,CAC7B,OAAO,CAACM,iBACR,WAAW;4BAIhB,MAAM4B,QAAQ,MAAMC,cAChBnC,SACAU,OACAe,KAAK,MAAM,EACXA,KAAK,KAAK;4BAGd,MAAMW,WAAW,MAAMpC,QAAQ,SAAS,CACnC,OAAO,CAACqC,oBACR,OAAO,CAAC;gCACL,YAAYC;gCACZ,OAAO;oCACH,YAAYb,KAAK,MAAM;oCACvB,SAASf,MAAM,OAAO;oCACtBwB;oCACA,QAAQT,KAAK,MAAM;oCACnB,MAAMA,KAAK,IAAI;oCACfQ;gCACJ;4BACJ;4BAEJ,OAAO,IAAIM,SAAS;gCAChB,IAAIH,SAAS,KAAK,CAAC,EAAE;4BACzB;wBACJ;oBACJ;gBACJ;gBACA,cAAcpC,CAAAA,UACVA,QAAQ,SAAS,CAAC,OAAO,CAACE,eAAe,SAAS,GAAG,EAAE,KAAKC,OAAO,EAAE,IAErEH,AAA8D,aAA9DA,QAAQ,SAAS,CAAC,OAAO,CAACwC,2BAA2B,IAAI;YACjE;YAEAjB,YAAY,IAAI,GAAG,CAAC,uCAAuC,EAAEb,MAAM,OAAO,EAAE;YAC5EM,QAAQ,IAAI,CAACO;QACjB;QAEA,OAAOP;IACX;AACJ;AAEO,MAAMyB,2BAA2BC,wBAAwB,oBAAoB,CAAC;IACjF,gBAAgB5C;IAChB,cAAc;QAAC6C;KAAiB;AACpC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HcmsBulkActionsContext } from "../types.js";
|
|
2
|
+
import type { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* The permission each bulk action requires on the model, matching the single-entry use case it runs.
|
|
5
|
+
* Custom bulk actions require write access.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getRequiredAccess: (action: string) => {
|
|
8
|
+
rwd?: string;
|
|
9
|
+
pw?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Bulk action tasks run without authorization, so the target folder of a move is checked here,
|
|
13
|
+
* with the same folder-level permission check the single-entry move uses.
|
|
14
|
+
*/
|
|
15
|
+
export declare const canMoveToFolder: (context: HcmsBulkActionsContext, folderId: string) => Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Bulk action tasks list and change entries without authorization, so the task query is
|
|
18
|
+
* restricted here to the entries the caller may act on: own entries only, when that is all the
|
|
19
|
+
* caller may change, and no entries from folders the caller can't change.
|
|
20
|
+
* The restrictions are set on the top level of `where`, so the client `where` can only narrow them.
|
|
21
|
+
*/
|
|
22
|
+
export declare const restrictWhere: (context: HcmsBulkActionsContext, model: CmsModel, action: string, initialWhere: CmsEntryListWhere | undefined) => Promise<CmsEntryListWhere>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
2
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
3
|
+
import { FolderLevelPermissions } from "@webiny/api-aco/features/flp/FolderLevelPermissions/index.js";
|
|
4
|
+
import { ROOT_FOLDER } from "@webiny/api-aco/constants.js";
|
|
5
|
+
const getRequiredAccess = (action)=>{
|
|
6
|
+
switch(action){
|
|
7
|
+
case "Delete":
|
|
8
|
+
case "MoveToTrash":
|
|
9
|
+
return {
|
|
10
|
+
rwd: "d"
|
|
11
|
+
};
|
|
12
|
+
case "Publish":
|
|
13
|
+
return {
|
|
14
|
+
pw: "p"
|
|
15
|
+
};
|
|
16
|
+
case "Unpublish":
|
|
17
|
+
return {
|
|
18
|
+
pw: "u"
|
|
19
|
+
};
|
|
20
|
+
default:
|
|
21
|
+
return {
|
|
22
|
+
rwd: "w"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const canMoveToFolder = async (context, folderId)=>{
|
|
27
|
+
if (folderId === ROOT_FOLDER) return true;
|
|
28
|
+
const [flp] = context.container.resolveAll(FolderLevelPermissions);
|
|
29
|
+
if (!flp || !flp.canUseFolderLevelPermissions()) return true;
|
|
30
|
+
const permissions = await flp.getFolderLevelPermissions(folderId);
|
|
31
|
+
return flp.canAccessFolderContent({
|
|
32
|
+
permissions,
|
|
33
|
+
rwd: "w"
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const canActOnlyOnOwnedEntries = async (context, model, action)=>{
|
|
37
|
+
const accessControl = context.container.resolve(AccessControl);
|
|
38
|
+
if (await accessControl.canAccessOnlyOwnedEntries({
|
|
39
|
+
model
|
|
40
|
+
})) return true;
|
|
41
|
+
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
42
|
+
const canActOnOthers = await accessControl.canAccessEntry({
|
|
43
|
+
model,
|
|
44
|
+
entry: {
|
|
45
|
+
entryId: "",
|
|
46
|
+
createdBy: {
|
|
47
|
+
id: `${identity.id}#not-owner`,
|
|
48
|
+
displayName: "",
|
|
49
|
+
type: ""
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
...getRequiredAccess(action)
|
|
53
|
+
});
|
|
54
|
+
return !canActOnOthers;
|
|
55
|
+
};
|
|
56
|
+
const listDeniedFolderIds = async (context, model, action)=>{
|
|
57
|
+
const [flp] = context.container.resolveAll(FolderLevelPermissions);
|
|
58
|
+
if (!flp || !flp.canUseFolderLevelPermissions()) return [];
|
|
59
|
+
const rwd = "d" === getRequiredAccess(action).rwd ? "d" : "w";
|
|
60
|
+
const flps = await flp.listFolderLevelPermissions({
|
|
61
|
+
where: {
|
|
62
|
+
type: `cms:${model.modelId}`,
|
|
63
|
+
path_startsWith: `${ROOT_FOLDER}/`
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const denied = [];
|
|
67
|
+
for (const item of flps)if (!await flp.canAccessFolderContent({
|
|
68
|
+
permissions: item.permissions,
|
|
69
|
+
rwd
|
|
70
|
+
})) denied.push(item.id);
|
|
71
|
+
return denied;
|
|
72
|
+
};
|
|
73
|
+
const restrictWhere = async (context, model, action, initialWhere)=>{
|
|
74
|
+
const where = {
|
|
75
|
+
...initialWhere
|
|
76
|
+
};
|
|
77
|
+
if (await canActOnlyOnOwnedEntries(context, model, action)) where.createdBy = context.container.resolve(IdentityContext).getIdentity().id;
|
|
78
|
+
const deniedFolderIds = await listDeniedFolderIds(context, model, action);
|
|
79
|
+
if (deniedFolderIds.length > 0) {
|
|
80
|
+
const location = where.location ?? where.wbyAco_location ?? {};
|
|
81
|
+
delete where.location;
|
|
82
|
+
where.wbyAco_location = {
|
|
83
|
+
...location,
|
|
84
|
+
folderId_not_in: [
|
|
85
|
+
...location.folderId_not_in ?? [],
|
|
86
|
+
...deniedFolderIds
|
|
87
|
+
]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return where;
|
|
91
|
+
};
|
|
92
|
+
export { canMoveToFolder, getRequiredAccess, restrictWhere };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=bulkActionAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/bulkActionAccess.js","sources":["../../src/graphql/bulkActionAccess.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { FolderLevelPermissions } from \"@webiny/api-aco/features/flp/FolderLevelPermissions/index.js\";\nimport { ROOT_FOLDER } from \"@webiny/api-aco/constants.js\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\n/**\n * The permission each bulk action requires on the model, matching the single-entry use case it runs.\n * Custom bulk actions require write access.\n */\nexport const getRequiredAccess = (action: string): { rwd?: string; pw?: string } => {\n switch (action) {\n case \"Delete\":\n case \"MoveToTrash\":\n return { rwd: \"d\" };\n case \"Publish\":\n return { pw: \"p\" };\n case \"Unpublish\":\n return { pw: \"u\" };\n default:\n return { rwd: \"w\" };\n }\n};\n\n/**\n * Bulk action tasks run without authorization, so the target folder of a move is checked here,\n * with the same folder-level permission check the single-entry move uses.\n */\nexport const canMoveToFolder = async (\n context: HcmsBulkActionsContext,\n folderId: string\n): Promise<boolean> => {\n if (folderId === ROOT_FOLDER) {\n return true;\n }\n\n const [flp] = context.container.resolveAll(FolderLevelPermissions);\n if (!flp || !flp.canUseFolderLevelPermissions()) {\n return true;\n }\n\n const permissions = await flp.getFolderLevelPermissions(folderId);\n return flp.canAccessFolderContent({ permissions, rwd: \"w\" });\n};\n\n/**\n * Whether the caller may run the action only on entries they created. Besides own-only access,\n * this covers several permission sets (e.g. read all entries, delete own), where the action\n * itself is allowed only on own entries: it is checked against an entry the caller doesn't own.\n */\nconst canActOnlyOnOwnedEntries = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string\n): Promise<boolean> => {\n const accessControl = context.container.resolve(AccessControl);\n if (await accessControl.canAccessOnlyOwnedEntries({ model })) {\n return true;\n }\n\n const identity = context.container.resolve(IdentityContext).getIdentity();\n const canActOnOthers = await accessControl.canAccessEntry({\n model,\n entry: {\n entryId: \"\",\n createdBy: {\n id: `${identity.id}#not-owner`,\n displayName: \"\",\n type: \"\"\n }\n },\n ...getRequiredAccess(action)\n });\n return !canActOnOthers;\n};\n\n/**\n * Ids of the model's folders whose content the caller can't change with this action.\n */\nconst listDeniedFolderIds = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string\n): Promise<string[]> => {\n const [flp] = context.container.resolveAll(FolderLevelPermissions);\n if (!flp || !flp.canUseFolderLevelPermissions()) {\n return [];\n }\n\n const rwd = getRequiredAccess(action).rwd === \"d\" ? \"d\" : \"w\";\n\n // Every folder path starts with the root folder.\n const flps = await flp.listFolderLevelPermissions({\n where: { type: `cms:${model.modelId}`, path_startsWith: `${ROOT_FOLDER}/` }\n });\n\n const denied: string[] = [];\n for (const item of flps) {\n if (!(await flp.canAccessFolderContent({ permissions: item.permissions, rwd }))) {\n denied.push(item.id);\n }\n }\n return denied;\n};\n\n/**\n * Bulk action tasks list and change entries without authorization, so the task query is\n * restricted here to the entries the caller may act on: own entries only, when that is all the\n * caller may change, and no entries from folders the caller can't change.\n * The restrictions are set on the top level of `where`, so the client `where` can only narrow them.\n */\nexport const restrictWhere = async (\n context: HcmsBulkActionsContext,\n model: CmsModel,\n action: string,\n initialWhere: CmsEntryListWhere | undefined\n): Promise<CmsEntryListWhere> => {\n const where: CmsEntryListWhere = { ...initialWhere };\n\n if (await canActOnlyOnOwnedEntries(context, model, action)) {\n where.createdBy = context.container.resolve(IdentityContext).getIdentity().id;\n }\n\n const deniedFolderIds = await listDeniedFolderIds(context, model, action);\n if (deniedFolderIds.length > 0) {\n // Listing replaces `wbyAco_location` with `location` when both are set, so use the same one.\n const location = where.location ?? where.wbyAco_location ?? {};\n delete where.location;\n where.wbyAco_location = {\n ...location,\n folderId_not_in: [...(location.folderId_not_in ?? []), ...deniedFolderIds]\n };\n }\n\n return where;\n};\n"],"names":["getRequiredAccess","action","canMoveToFolder","context","folderId","ROOT_FOLDER","flp","FolderLevelPermissions","permissions","canActOnlyOnOwnedEntries","model","accessControl","AccessControl","identity","IdentityContext","canActOnOthers","listDeniedFolderIds","rwd","flps","denied","item","restrictWhere","initialWhere","where","deniedFolderIds","location"],"mappings":";;;;AAWO,MAAMA,oBAAoB,CAACC;IAC9B,OAAQA;QACJ,KAAK;QACL,KAAK;YACD,OAAO;gBAAE,KAAK;YAAI;QACtB,KAAK;YACD,OAAO;gBAAE,IAAI;YAAI;QACrB,KAAK;YACD,OAAO;gBAAE,IAAI;YAAI;QACrB;YACI,OAAO;gBAAE,KAAK;YAAI;IAC1B;AACJ;AAMO,MAAMC,kBAAkB,OAC3BC,SACAC;IAEA,IAAIA,aAAaC,aACb,OAAO;IAGX,MAAM,CAACC,IAAI,GAAGH,QAAQ,SAAS,CAAC,UAAU,CAACI;IAC3C,IAAI,CAACD,OAAO,CAACA,IAAI,4BAA4B,IACzC,OAAO;IAGX,MAAME,cAAc,MAAMF,IAAI,yBAAyB,CAACF;IACxD,OAAOE,IAAI,sBAAsB,CAAC;QAAEE;QAAa,KAAK;IAAI;AAC9D;AAOA,MAAMC,2BAA2B,OAC7BN,SACAO,OACAT;IAEA,MAAMU,gBAAgBR,QAAQ,SAAS,CAAC,OAAO,CAACS;IAChD,IAAI,MAAMD,cAAc,yBAAyB,CAAC;QAAED;IAAM,IACtD,OAAO;IAGX,MAAMG,WAAWV,QAAQ,SAAS,CAAC,OAAO,CAACW,iBAAiB,WAAW;IACvE,MAAMC,iBAAiB,MAAMJ,cAAc,cAAc,CAAC;QACtDD;QACA,OAAO;YACH,SAAS;YACT,WAAW;gBACP,IAAI,GAAGG,SAAS,EAAE,CAAC,UAAU,CAAC;gBAC9B,aAAa;gBACb,MAAM;YACV;QACJ;QACA,GAAGb,kBAAkBC,OAAO;IAChC;IACA,OAAO,CAACc;AACZ;AAKA,MAAMC,sBAAsB,OACxBb,SACAO,OACAT;IAEA,MAAM,CAACK,IAAI,GAAGH,QAAQ,SAAS,CAAC,UAAU,CAACI;IAC3C,IAAI,CAACD,OAAO,CAACA,IAAI,4BAA4B,IACzC,OAAO,EAAE;IAGb,MAAMW,MAAMjB,AAAkC,QAAlCA,kBAAkBC,QAAQ,GAAG,GAAW,MAAM;IAG1D,MAAMiB,OAAO,MAAMZ,IAAI,0BAA0B,CAAC;QAC9C,OAAO;YAAE,MAAM,CAAC,IAAI,EAAEI,MAAM,OAAO,EAAE;YAAE,iBAAiB,GAAGL,YAAY,CAAC,CAAC;QAAC;IAC9E;IAEA,MAAMc,SAAmB,EAAE;IAC3B,KAAK,MAAMC,QAAQF,KACf,IAAI,CAAE,MAAMZ,IAAI,sBAAsB,CAAC;QAAE,aAAac,KAAK,WAAW;QAAEH;IAAI,IACxEE,OAAO,IAAI,CAACC,KAAK,EAAE;IAG3B,OAAOD;AACX;AAQO,MAAME,gBAAgB,OACzBlB,SACAO,OACAT,QACAqB;IAEA,MAAMC,QAA2B;QAAE,GAAGD,YAAY;IAAC;IAEnD,IAAI,MAAMb,yBAAyBN,SAASO,OAAOT,SAC/CsB,MAAM,SAAS,GAAGpB,QAAQ,SAAS,CAAC,OAAO,CAACW,iBAAiB,WAAW,GAAG,EAAE;IAGjF,MAAMU,kBAAkB,MAAMR,oBAAoBb,SAASO,OAAOT;IAClE,IAAIuB,gBAAgB,MAAM,GAAG,GAAG;QAE5B,MAAMC,WAAWF,MAAM,QAAQ,IAAIA,MAAM,eAAe,IAAI,CAAC;QAC7D,OAAOA,MAAM,QAAQ;QACrBA,MAAM,eAAe,GAAG;YACpB,GAAGE,QAAQ;YACX,iBAAiB;mBAAKA,SAAS,eAAe,IAAI,EAAE;mBAAMD;aAAgB;QAC9E;IACJ;IAEA,OAAOD;AACX"}
|
|
@@ -1,64 +1,61 @@
|
|
|
1
|
-
import { CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
|
|
2
|
-
import {
|
|
1
|
+
import { CmsGraphQLSchemaFactory, CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
|
|
2
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
|
+
import { Response } from "@webiny/api-graphql";
|
|
3
4
|
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
4
5
|
import { BulkActionName } from "../domain/BulkActionName.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (bulkAction.modelIds?.length) {
|
|
23
|
-
return bulkAction.modelIds.includes(model.modelId);
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
6
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
9
|
+
import { TriggerTaskUseCase } from "@webiny/background-tasks/api";
|
|
10
|
+
const createBulkActionGraphQL = async (context, bulkAction)=>{
|
|
11
|
+
const tenant = context.container.resolve(TenantContext).getTenant();
|
|
12
|
+
if (!await isHeadlessCmsReady(context)) return;
|
|
13
|
+
const modelsResult = await context.container.resolve(IdentityContext).withoutAuthorization(async ()=>context.container.resolve(ListModelsUseCase).execute());
|
|
14
|
+
if (modelsResult.isFail()) return;
|
|
15
|
+
const models = modelsResult.value.filter((model)=>{
|
|
16
|
+
if (model.isPrivate) return false;
|
|
17
|
+
const tags = Array.isArray(model.tags) ? model.tags : [];
|
|
18
|
+
if (tags.includes(CMS_MODEL_SINGLETON_TAG)) return false;
|
|
19
|
+
if (bulkAction.modelIds?.length) return bulkAction.modelIds.includes(model.modelId);
|
|
20
|
+
return true;
|
|
26
21
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
typeDefs: /* GraphQL */`
|
|
22
|
+
const plugins = [];
|
|
23
|
+
models.forEach((model)=>{
|
|
24
|
+
const plugin = new CmsGraphQLSchemaPlugin({
|
|
25
|
+
typeDefs: `
|
|
32
26
|
extend enum BulkAction${model.singularApiName}Name {
|
|
33
27
|
${BulkActionName.from(bulkAction.name)}
|
|
34
28
|
}
|
|
35
29
|
`,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
30
|
+
resolvers: {
|
|
31
|
+
Mutation: {
|
|
32
|
+
[`bulkAction${model.singularApiName}`]: async (_, args, context)=>{
|
|
33
|
+
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
34
|
+
const response = await context.container.resolve(TriggerTaskUseCase).execute({
|
|
35
|
+
definition: `hcmsBulkList${args.action}Entries`,
|
|
36
|
+
input: {
|
|
37
|
+
modelId: model.modelId,
|
|
38
|
+
where: args.where,
|
|
39
|
+
search: args.search,
|
|
40
|
+
data: args.data,
|
|
41
|
+
identity
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return new Response({
|
|
45
|
+
id: response.value.id
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
isApplicable: (context)=>context.container.resolve(TenantContext).getTenant().id === tenant.id && "manage" === context.container.resolve(HeadlessCmsEndpointConfig).type
|
|
51
|
+
});
|
|
52
|
+
plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;
|
|
53
|
+
plugins.push(plugin);
|
|
54
|
+
});
|
|
55
|
+
context.container.registerInstance(CmsGraphQLSchemaFactory, {
|
|
56
|
+
execute: ()=>plugins
|
|
57
57
|
});
|
|
58
|
-
plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;
|
|
59
|
-
plugins.push(plugin);
|
|
60
|
-
});
|
|
61
|
-
context.plugins.register([...plugins]);
|
|
62
58
|
};
|
|
59
|
+
export { createBulkActionGraphQL };
|
|
63
60
|
|
|
64
61
|
//# sourceMappingURL=createBulkActionGraphQL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/createBulkActionGraphQL.js","sources":["../../src/graphql/createBulkActionGraphQL.ts"],"sourcesContent":["import type { HcmsBulkActionsContext } from \"~/types.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGraphQLSchemaFactory,\n isHeadlessCmsReady\n} from \"@webiny/api-headless-cms\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"@webiny/api-headless-cms/constants.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\n\nexport const createBulkActionGraphQL = async (\n context: HcmsBulkActionsContext,\n bulkAction: EntriesBulkAction.Interface\n) => {\n const tenant = context.container.resolve(TenantContext).getTenant();\n\n if (!(await isHeadlessCmsReady(context))) {\n return;\n }\n\n const modelsResult = await context.container\n .resolve(IdentityContext)\n .withoutAuthorization(async () => {\n return context.container.resolve(ListModelsUseCase).execute();\n });\n if (modelsResult.isFail()) {\n return;\n }\n const models = modelsResult.value.filter(model => {\n if (model.isPrivate) {\n return false;\n }\n const tags = Array.isArray(model.tags) ? model.tags : [];\n if (tags.includes(CMS_MODEL_SINGLETON_TAG)) {\n return false;\n }\n if (bulkAction.modelIds?.length) {\n return bulkAction.modelIds.includes(model.modelId);\n }\n return true;\n });\n\n const plugins: CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>[] = [];\n\n models.forEach(model => {\n const plugin = new CmsGraphQLSchemaPlugin<HcmsBulkActionsContext>({\n typeDefs: /* GraphQL */ `\n extend enum BulkAction${model.singularApiName}Name {\n ${BulkActionName.from(bulkAction.name)}\n }\n `,\n resolvers: {\n Mutation: {\n [`bulkAction${model.singularApiName}`]: async (_, args, context) => {\n const identity = context.container.resolve(IdentityContext).getIdentity();\n\n const response = await context.container\n .resolve(TriggerTaskUseCase)\n .execute({\n definition: `hcmsBulkList${args.action}Entries`,\n input: {\n modelId: model.modelId,\n where: args.where,\n search: args.search,\n data: args.data,\n identity\n }\n });\n\n return new Response({\n id: response.value.id\n });\n }\n }\n },\n isApplicable: context =>\n context.container.resolve(TenantContext).getTenant().id === tenant.id &&\n // Bulk actions change entries: manage endpoint only.\n context.container.resolve(HeadlessCmsEndpointConfig).type === \"manage\"\n });\n\n plugin.name = `headless-cms.graphql.schema.bulkAction.${model.modelId}.${bulkAction.name}`;\n plugins.push(plugin);\n });\n\n context.container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => plugins\n });\n};\n"],"names":["createBulkActionGraphQL","context","bulkAction","tenant","TenantContext","isHeadlessCmsReady","modelsResult","IdentityContext","ListModelsUseCase","models","model","tags","Array","CMS_MODEL_SINGLETON_TAG","plugins","plugin","CmsGraphQLSchemaPlugin","BulkActionName","_","args","identity","response","TriggerTaskUseCase","Response","HeadlessCmsEndpointConfig","CmsGraphQLSchemaFactory"],"mappings":";;;;;;;;;AAgBO,MAAMA,0BAA0B,OACnCC,SACAC;IAEA,MAAMC,SAASF,QAAQ,SAAS,CAAC,OAAO,CAACG,eAAe,SAAS;IAEjE,IAAI,CAAE,MAAMC,mBAAmBJ,UAC3B;IAGJ,MAAMK,eAAe,MAAML,QAAQ,SAAS,CACvC,OAAO,CAACM,iBACR,oBAAoB,CAAC,UACXN,QAAQ,SAAS,CAAC,OAAO,CAACO,mBAAmB,OAAO;IAEnE,IAAIF,aAAa,MAAM,IACnB;IAEJ,MAAMG,SAASH,aAAa,KAAK,CAAC,MAAM,CAACI,CAAAA;QACrC,IAAIA,MAAM,SAAS,EACf,OAAO;QAEX,MAAMC,OAAOC,MAAM,OAAO,CAACF,MAAM,IAAI,IAAIA,MAAM,IAAI,GAAG,EAAE;QACxD,IAAIC,KAAK,QAAQ,CAACE,0BACd,OAAO;QAEX,IAAIX,WAAW,QAAQ,EAAE,QACrB,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAACQ,MAAM,OAAO;QAErD,OAAO;IACX;IAEA,MAAMI,UAA4D,EAAE;IAEpEL,OAAO,OAAO,CAACC,CAAAA;QACX,MAAMK,SAAS,IAAIC,uBAA+C;YAC9D,UAAwB,CAAC;2CACM,EAAEN,MAAM,eAAe,CAAC;wBAC3C,EAAEO,eAAe,IAAI,CAACf,WAAW,IAAI,EAAE;;gBAE/C,CAAC;YACL,WAAW;gBACP,UAAU;oBACN,CAAC,CAAC,UAAU,EAAEQ,MAAM,eAAe,EAAE,CAAC,EAAE,OAAOQ,GAAGC,MAAMlB;wBACpD,MAAMmB,WAAWnB,QAAQ,SAAS,CAAC,OAAO,CAACM,iBAAiB,WAAW;wBAEvE,MAAMc,WAAW,MAAMpB,QAAQ,SAAS,CACnC,OAAO,CAACqB,oBACR,OAAO,CAAC;4BACL,YAAY,CAAC,YAAY,EAAEH,KAAK,MAAM,CAAC,OAAO,CAAC;4BAC/C,OAAO;gCACH,SAAST,MAAM,OAAO;gCACtB,OAAOS,KAAK,KAAK;gCACjB,QAAQA,KAAK,MAAM;gCACnB,MAAMA,KAAK,IAAI;gCACfC;4BACJ;wBACJ;wBAEJ,OAAO,IAAIG,SAAS;4BAChB,IAAIF,SAAS,KAAK,CAAC,EAAE;wBACzB;oBACJ;gBACJ;YACJ;YACA,cAAcpB,CAAAA,UACVA,QAAQ,SAAS,CAAC,OAAO,CAACG,eAAe,SAAS,GAAG,EAAE,KAAKD,OAAO,EAAE,IAErEF,AAA8D,aAA9DA,QAAQ,SAAS,CAAC,OAAO,CAACuB,2BAA2B,IAAI;QACjE;QAEAT,OAAO,IAAI,GAAG,CAAC,uCAAuC,EAAEL,MAAM,OAAO,CAAC,CAAC,EAAER,WAAW,IAAI,EAAE;QAC1FY,QAAQ,IAAI,CAACC;IACjB;IAEAd,QAAQ,SAAS,CAAC,gBAAgB,CAACwB,yBAAyB;QACxD,SAAS,IAAMX;IACnB;AACJ"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { HcmsBulkActionsContext } from "../types.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Registers the "default" bulk-action GraphQL for every public model: the shared response types plus,
|
|
4
|
+
* per model, an empty `BulkAction<Model>Name` enum + `bulkAction<Model>` mutation skeleton (each
|
|
5
|
+
* action extends the enum via createBulkActionGraphQL). Run per request, since models are only
|
|
6
|
+
* known at request time.
|
|
7
|
+
*/
|
|
8
|
+
export declare const registerDefaultBulkActionGraphQL: (context: HcmsBulkActionsContext) => Promise<void>;
|