@webiny/api-headless-cms-bulk-actions 6.6.0-alpha.12 → 6.6.0-alpha.13
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/features/EntriesBulkAction/createBulkActionTasks.js +1 -1
- package/features/EntriesBulkAction/createBulkActionTasks.js.map +1 -1
- package/graphql/BulkActionsGraphQLSchema.js +20 -3
- package/graphql/BulkActionsGraphQLSchema.js.map +1 -1
- package/graphql/bulkActionAccess.d.ts +22 -0
- package/graphql/bulkActionAccess.js +94 -0
- package/graphql/bulkActionAccess.js.map +1 -0
- package/package.json +18 -17
- package/tasks/EmptyTrashBinTask.d.ts +3 -9
- package/tasks/EmptyTrashBinTask.js +50 -54
- package/tasks/EmptyTrashBinTask.js.map +1 -1
- package/types.js.map +1 -1
|
@@ -8,7 +8,7 @@ import { ChildTasksCleanup } from "./internals/ChildTasksCleanup.js";
|
|
|
8
8
|
import { ProcessTask } from "./internals/ProcessTask.js";
|
|
9
9
|
import { CreateTasksByModel } from "./internals/CreateTasksByModel.js";
|
|
10
10
|
import { ProcessTasksByModel } from "./internals/ProcessTasksByModel.js";
|
|
11
|
-
import { RequestContainer } from "@webiny/
|
|
11
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
12
12
|
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
13
13
|
const BULK_ACTION_LIST_TASK_ID = "hcmsBulkListEntries";
|
|
14
14
|
const BULK_ACTION_PROCESS_TASK_ID = "hcmsBulkProcessEntries";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/createBulkActionTasks.js","sources":["../../../src/features/EntriesBulkAction/createBulkActionTasks.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { DeleteTaskLogUseCase } from \"@webiny/background-tasks/api\";\nimport { DeleteTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTaskLogsUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type {\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput,\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n} from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction, EntriesBulkActionConfig } from \"./abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { ChildTasksCleanup } from \"./internals/ChildTasksCleanup.js\";\nimport { ProcessTask } from \"./internals/ProcessTask.js\";\nimport { CreateTasksByModel } from \"./internals/CreateTasksByModel.js\";\nimport { ProcessTasksByModel } from \"./internals/ProcessTasksByModel.js\";\nimport type { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nexport const BULK_ACTION_LIST_TASK_ID = \"hcmsBulkListEntries\";\nexport const BULK_ACTION_PROCESS_TASK_ID = \"hcmsBulkProcessEntries\";\n\nconst resolveBulkAction = (container: Container, actionName: string) => {\n const bulkActions = container.resolveAll(EntriesBulkAction);\n const action = bulkActions.find(a => BulkActionName.from(a.name) === actionName);\n if (!action) {\n throw new Error(`Unknown bulk action: \"${actionName}\"`);\n }\n return action;\n};\n\nclass BulkActionListTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly listTasks: ListTasksUseCase.Interface,\n private readonly triggerTask: TriggerTaskUseCase.Interface,\n private readonly listTaskLogs: ListTaskLogsUseCase.Interface,\n private readonly deleteTaskLog: DeleteTaskLogUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly bulkActionsConfig: EntriesBulkActionConfig.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput>) {\n try {\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const batchSize = bulkAction.batchSize ?? this.bulkActionsConfig.batchSize ?? 100;\n const action = input.action ?? BulkActionOperationByModelAction.CREATE_SUBTASKS;\n\n switch (action) {\n case BulkActionOperationByModelAction.PROCESS_SUBTASKS: {\n const processTasks = new ProcessTasksByModel(\n this.listTasks,\n BULK_ACTION_PROCESS_TASK_ID\n );\n return await processTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.CREATE_SUBTASKS:\n case BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS: {\n const createTasks = new CreateTasksByModel(\n this.getModel,\n this.triggerTask,\n bulkAction,\n BULK_ACTION_PROCESS_TASK_ID,\n batchSize,\n this.logger\n );\n return await createTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.END_TASK: {\n return controller.response.done(\n `Task done: bulk action \"${input.actionName}\" has been successfully processed for entries from \"${input.modelId}\" model.`\n );\n }\n default:\n return controller.response.error(`Unknown action: ${action}`);\n }\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action list task\"\n );\n }\n }\n\n async onDone({ task }: TaskHandler.LifecycleHookParams): Promise<void> {\n await this.cleanup(task);\n }\n\n async onError({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onAbort({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onMaxIterations({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async cleanup(task: TaskDefinition.Task) {\n const childTasksCleanup = new ChildTasksCleanup();\n try {\n await childTasksCleanup.execute({\n listTasks: this.listTasks,\n listTaskLogs: this.listTaskLogs,\n deleteTaskLog: this.deleteTaskLog,\n deleteTask: this.deleteTask,\n task\n });\n } catch (ex) {\n this.logger.error({ error: ex }, \"Error while cleaning bulk action list child tasks.\");\n }\n }\n}\n\nconst BulkActionListTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionListTaskHandlerImpl,\n dependencies: [\n RequestContainer,\n GetModelUseCase,\n ListTasksUseCase,\n TriggerTaskUseCase,\n ListTaskLogsUseCase,\n DeleteTaskLogUseCase,\n DeleteTaskUseCase,\n EntriesBulkActionConfig,\n Logger\n ]\n});\n\nclass BulkActionListTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_LIST_TASK_ID;\n public readonly title = \"Headless CMS: list entries for bulk action\";\n public readonly maxIterations = 500;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionListTaskHandler;\n}\n\nclass BulkActionProcessTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationInput, IBulkActionOperationOutput>) {\n try {\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const processTask = new ProcessTask(bulkAction, this.getModel, this.logger);\n return await processTask.execute({ input, controller, definition });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action process task\"\n );\n }\n }\n}\n\nconst BulkActionProcessTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionProcessTaskHandlerImpl,\n dependencies: [RequestContainer, GetModelUseCase, Logger]\n});\n\nclass BulkActionProcessTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_PROCESS_TASK_ID;\n public readonly title = \"Headless CMS: process entries for bulk action\";\n public readonly maxIterations = 2;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionProcessTaskHandler;\n}\n\nexport const BulkActionListTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionListTask,\n dependencies: []\n});\n\nexport const BulkActionProcessTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionProcessTask,\n dependencies: []\n});\n"],"names":["BULK_ACTION_LIST_TASK_ID","BULK_ACTION_PROCESS_TASK_ID","resolveBulkAction","container","actionName","bulkActions","EntriesBulkAction","action","a","BulkActionName","Error","BulkActionListTaskHandlerImpl","getModel","listTasks","triggerTask","listTaskLogs","deleteTaskLog","deleteTask","bulkActionsConfig","logger","input","controller","definition","bulkAction","batchSize","BulkActionOperationByModelAction","processTasks","ProcessTasksByModel","createTasks","CreateTasksByModel","ex","task","childTasksCleanup","ChildTasksCleanup","BulkActionListTaskHandler","TaskHandler","RequestContainer","GetModelUseCase","ListTasksUseCase","TriggerTaskUseCase","ListTaskLogsUseCase","DeleteTaskLogUseCase","DeleteTaskUseCase","EntriesBulkActionConfig","Logger","BulkActionListTask","BulkActionProcessTaskHandlerImpl","processTask","ProcessTask","BulkActionProcessTaskHandler","BulkActionProcessTask","BulkActionListTaskDefinition","TaskDefinition","BulkActionProcessTaskDefinition"],"mappings":";;;;;;;;;;;;AA2BO,MAAMA,2BAA2B;AACjC,MAAMC,8BAA8B;AAE3C,MAAMC,oBAAoB,CAACC,WAAsBC;IAC7C,MAAMC,cAAcF,UAAU,UAAU,CAACG;IACzC,MAAMC,SAASF,YAAY,IAAI,CAACG,CAAAA,IAAKC,eAAe,IAAI,CAACD,EAAE,IAAI,MAAMJ;IACrE,IAAI,CAACG,QACD,MAAM,IAAIG,MAAM,CAAC,sBAAsB,EAAEN,WAAW,CAAC,CAAC;IAE1D,O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
+
{"version":3,"file":"features/EntriesBulkAction/createBulkActionTasks.js","sources":["../../../src/features/EntriesBulkAction/createBulkActionTasks.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { DeleteTaskLogUseCase } from \"@webiny/background-tasks/api\";\nimport { DeleteTaskUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTaskLogsUseCase } from \"@webiny/background-tasks/api\";\nimport { ListTasksUseCase } from \"@webiny/background-tasks/api\";\nimport { TriggerTaskUseCase } from \"@webiny/background-tasks/api\";\nimport type {\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput,\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n} from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction, EntriesBulkActionConfig } from \"./abstractions.js\";\nimport { BulkActionName } from \"~/domain/BulkActionName.js\";\nimport { ChildTasksCleanup } from \"./internals/ChildTasksCleanup.js\";\nimport { ProcessTask } from \"./internals/ProcessTask.js\";\nimport { CreateTasksByModel } from \"./internals/CreateTasksByModel.js\";\nimport { ProcessTasksByModel } from \"./internals/ProcessTasksByModel.js\";\nimport type { Container } from \"@webiny/di\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nexport const BULK_ACTION_LIST_TASK_ID = \"hcmsBulkListEntries\";\nexport const BULK_ACTION_PROCESS_TASK_ID = \"hcmsBulkProcessEntries\";\n\nconst resolveBulkAction = (container: Container, actionName: string) => {\n const bulkActions = container.resolveAll(EntriesBulkAction);\n const action = bulkActions.find(a => BulkActionName.from(a.name) === actionName);\n if (!action) {\n throw new Error(`Unknown bulk action: \"${actionName}\"`);\n }\n return action;\n};\n\nclass BulkActionListTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly listTasks: ListTasksUseCase.Interface,\n private readonly triggerTask: TriggerTaskUseCase.Interface,\n private readonly listTaskLogs: ListTaskLogsUseCase.Interface,\n private readonly deleteTaskLog: DeleteTaskLogUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly bulkActionsConfig: EntriesBulkActionConfig.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationByModelInput, IBulkActionOperationByModelOutput>) {\n try {\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const batchSize = bulkAction.batchSize ?? this.bulkActionsConfig.batchSize ?? 100;\n const action = input.action ?? BulkActionOperationByModelAction.CREATE_SUBTASKS;\n\n switch (action) {\n case BulkActionOperationByModelAction.PROCESS_SUBTASKS: {\n const processTasks = new ProcessTasksByModel(\n this.listTasks,\n BULK_ACTION_PROCESS_TASK_ID\n );\n return await processTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.CREATE_SUBTASKS:\n case BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS: {\n const createTasks = new CreateTasksByModel(\n this.getModel,\n this.triggerTask,\n bulkAction,\n BULK_ACTION_PROCESS_TASK_ID,\n batchSize,\n this.logger\n );\n return await createTasks.execute({ input, controller, definition });\n }\n case BulkActionOperationByModelAction.END_TASK: {\n return controller.response.done(\n `Task done: bulk action \"${input.actionName}\" has been successfully processed for entries from \"${input.modelId}\" model.`\n );\n }\n default:\n return controller.response.error(`Unknown action: ${action}`);\n }\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action list task\"\n );\n }\n }\n\n async onDone({ task }: TaskHandler.LifecycleHookParams): Promise<void> {\n await this.cleanup(task);\n }\n\n async onError({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onAbort({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async onMaxIterations({ task }: TaskHandler.LifecycleHookParams) {\n await this.cleanup(task);\n }\n\n async cleanup(task: TaskDefinition.Task) {\n const childTasksCleanup = new ChildTasksCleanup();\n try {\n await childTasksCleanup.execute({\n listTasks: this.listTasks,\n listTaskLogs: this.listTaskLogs,\n deleteTaskLog: this.deleteTaskLog,\n deleteTask: this.deleteTask,\n task\n });\n } catch (ex) {\n this.logger.error({ error: ex }, \"Error while cleaning bulk action list child tasks.\");\n }\n }\n}\n\nconst BulkActionListTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionListTaskHandlerImpl,\n dependencies: [\n RequestContainer,\n GetModelUseCase,\n ListTasksUseCase,\n TriggerTaskUseCase,\n ListTaskLogsUseCase,\n DeleteTaskLogUseCase,\n DeleteTaskUseCase,\n EntriesBulkActionConfig,\n Logger\n ]\n});\n\nclass BulkActionListTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_LIST_TASK_ID;\n public readonly title = \"Headless CMS: list entries for bulk action\";\n public readonly maxIterations = 500;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionListTaskHandler;\n}\n\nclass BulkActionProcessTaskHandlerImpl implements TaskHandler.Interface<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n> {\n constructor(\n private readonly container: Container,\n private readonly getModel: GetModelUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async run({\n input,\n controller,\n definition\n }: TaskHandler.RunParams<IBulkActionOperationInput, IBulkActionOperationOutput>) {\n try {\n if (!input.actionName) {\n return controller.response.error(`Missing \"actionName\" in the input.`);\n }\n\n const bulkAction = resolveBulkAction(this.container, input.actionName);\n const processTask = new ProcessTask(bulkAction, this.getModel, this.logger);\n return await processTask.execute({ input, controller, definition });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? \"Error while executing bulk action process task\"\n );\n }\n }\n}\n\nconst BulkActionProcessTaskHandler = TaskHandler.createImplementation({\n implementation: BulkActionProcessTaskHandlerImpl,\n dependencies: [RequestContainer, GetModelUseCase, Logger]\n});\n\nclass BulkActionProcessTask implements TaskDefinition.Interface {\n public readonly id = BULK_ACTION_PROCESS_TASK_ID;\n public readonly title = \"Headless CMS: process entries for bulk action\";\n public readonly maxIterations = 2;\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = BulkActionProcessTaskHandler;\n}\n\nexport const BulkActionListTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionListTask,\n dependencies: []\n});\n\nexport const BulkActionProcessTaskDefinition = TaskDefinition.createImplementation({\n implementation: BulkActionProcessTask,\n dependencies: []\n});\n"],"names":["BULK_ACTION_LIST_TASK_ID","BULK_ACTION_PROCESS_TASK_ID","resolveBulkAction","container","actionName","bulkActions","EntriesBulkAction","action","a","BulkActionName","Error","BulkActionListTaskHandlerImpl","getModel","listTasks","triggerTask","listTaskLogs","deleteTaskLog","deleteTask","bulkActionsConfig","logger","input","controller","definition","bulkAction","batchSize","BulkActionOperationByModelAction","processTasks","ProcessTasksByModel","createTasks","CreateTasksByModel","ex","task","childTasksCleanup","ChildTasksCleanup","BulkActionListTaskHandler","TaskHandler","RequestContainer","GetModelUseCase","ListTasksUseCase","TriggerTaskUseCase","ListTaskLogsUseCase","DeleteTaskLogUseCase","DeleteTaskUseCase","EntriesBulkActionConfig","Logger","BulkActionListTask","BulkActionProcessTaskHandlerImpl","processTask","ProcessTask","BulkActionProcessTaskHandler","BulkActionProcessTask","BulkActionListTaskDefinition","TaskDefinition","BulkActionProcessTaskDefinition"],"mappings":";;;;;;;;;;;;AA2BO,MAAMA,2BAA2B;AACjC,MAAMC,8BAA8B;AAE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AS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGgD;;AACd;AAEO,MAAME,+BAA+BC,eAAe,oBAAoB,CAAC;IAC5E,gBAAgBP;IAChB,cAAc,EAAE;AACpB;AAEO,MAAMQ,kCAAkCD,eAAe,oBAAoB,CAAC;IAC/E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CmsGraphQLSchemaFactory, CmsGraphQLSchemaPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
|
|
2
2
|
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
3
|
import { CMS_MODEL_SINGLETON_TAG } from "@webiny/api-headless-cms/constants.js";
|
|
4
|
-
import { Response } from "@webiny/api-graphql";
|
|
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";
|
|
5
7
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
6
8
|
import { HeadlessCmsEndpointConfig } from "@webiny/api-headless-cms/HeadlessCmsEndpointConfig.js";
|
|
7
9
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
@@ -9,7 +11,8 @@ import { TriggerTaskUseCase } from "@webiny/background-tasks/api";
|
|
|
9
11
|
import { EntriesBulkAction } from "../features/EntriesBulkAction/abstractions.js";
|
|
10
12
|
import { BulkActionName } from "../domain/BulkActionName.js";
|
|
11
13
|
import { BULK_ACTION_LIST_TASK_ID } from "../features/EntriesBulkAction/createBulkActionTasks.js";
|
|
12
|
-
import { RequestContainer } from "@webiny/
|
|
14
|
+
import { RequestContainer } from "@webiny/api-kernel-core";
|
|
15
|
+
import { canMoveToFolder, getRequiredAccess, restrictWhere } from "./bulkActionAccess.js";
|
|
13
16
|
class BulkActionsGraphQLSchemaImpl {
|
|
14
17
|
constructor(container){
|
|
15
18
|
this.container = container;
|
|
@@ -70,13 +73,27 @@ class BulkActionsGraphQLSchemaImpl {
|
|
|
70
73
|
resolvers: {
|
|
71
74
|
Mutation: {
|
|
72
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
|
+
}
|
|
73
89
|
const identity = context.container.resolve(IdentityContext).getIdentity();
|
|
90
|
+
const where = await restrictWhere(context, model, args.action, args.where);
|
|
74
91
|
const response = await context.container.resolve(TriggerTaskUseCase).execute({
|
|
75
92
|
definition: BULK_ACTION_LIST_TASK_ID,
|
|
76
93
|
input: {
|
|
77
94
|
actionName: args.action,
|
|
78
95
|
modelId: model.modelId,
|
|
79
|
-
where
|
|
96
|
+
where,
|
|
80
97
|
search: args.search,
|
|
81
98
|
data: args.data,
|
|
82
99
|
identity
|
|
@@ -1 +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 { 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/event-handler-core\";\nimport type { HcmsBulkActionsContext } from \"~/types.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 identity = context.container\n .resolve(IdentityContext)\n .getIdentity();\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: 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 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","identity","response","TriggerTaskUseCase","BULK_ACTION_LIST_TASK_ID","Response","HeadlessCmsEndpointConfig","BulkActionsGraphQLSchema","CmsGraphQLSchemaFactory","RequestContainer"],"mappings":";;;;;;;;;;;;AAmBA,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,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,CAACO;QACjB;QAEA,OAAOP;IACX;AACJ;AAEO,MAAMgB,2BAA2BC,wBAAwB,oBAAoB,CAAC;IACjF,gBAAgBnC;IAChB,cAAc;QAACoC;KAAiB;AACpC"}
|
|
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","CmsGraphQLSchemaF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;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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;YACX,iBAAiB;mBAAKA,SAAS,eAAe,IAAI,EAAE;mBAAMD;aAAgB;QAC9E;IACJ;IAEA,OAAOD;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-bulk-actions",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,26 +17,27 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api-
|
|
21
|
-
"@webiny/api-
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/
|
|
20
|
+
"@webiny/api-aco": "6.6.0-alpha.13",
|
|
21
|
+
"@webiny/api-graphql": "6.6.0-alpha.13",
|
|
22
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.13",
|
|
23
|
+
"@webiny/api-kernel-core": "6.6.0-alpha.13",
|
|
24
|
+
"@webiny/background-tasks": "6.6.0-alpha.13",
|
|
25
|
+
"@webiny/feature": "6.6.0-alpha.13",
|
|
26
|
+
"@webiny/handler": "6.6.0-alpha.13",
|
|
27
|
+
"@webiny/utils": "6.6.0-alpha.13"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@webiny/api": "6.6.0-alpha.
|
|
30
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
31
|
-
"@webiny/api-graphql": "6.6.0-alpha.
|
|
32
|
-
"@webiny/api-headless-cms-testing": "6.6.0-alpha.
|
|
33
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
30
|
+
"@webiny/api": "6.6.0-alpha.13",
|
|
31
|
+
"@webiny/api-core": "6.6.0-alpha.13",
|
|
32
|
+
"@webiny/api-graphql": "6.6.0-alpha.13",
|
|
33
|
+
"@webiny/api-headless-cms-testing": "6.6.0-alpha.13",
|
|
34
|
+
"@webiny/build-tools": "6.6.0-alpha.13",
|
|
34
35
|
"@webiny/di": "2.0.0",
|
|
35
|
-
"@webiny/plugins": "6.6.0-alpha.
|
|
36
|
-
"@webiny/wcp": "6.6.0-alpha.
|
|
37
|
-
"graphql": "16.
|
|
36
|
+
"@webiny/plugins": "6.6.0-alpha.13",
|
|
37
|
+
"@webiny/wcp": "6.6.0-alpha.13",
|
|
38
|
+
"graphql": "16.15.0",
|
|
38
39
|
"typescript": "7.0.2",
|
|
39
|
-
"vitest": "5.
|
|
40
|
+
"vitest": "5.1.1"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from "../types.js";
|
|
2
2
|
import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
3
|
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
6
|
-
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
|
-
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
4
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
8
5
|
declare class EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<IEmptyTrashBinsInput, IEmptyTrashBinsOutput> {
|
|
9
|
-
private
|
|
6
|
+
private tenantScopes;
|
|
10
7
|
private listTenants;
|
|
11
|
-
|
|
12
|
-
private listDeletedEntries;
|
|
13
|
-
private deleteEntry;
|
|
14
|
-
constructor(tenantContext: TenantContext.Interface, listTenants: ListTenantsUseCase.Interface, listModels: ListModelsUseCase.Interface, listDeletedEntries: ListDeletedEntriesUseCase.Interface, deleteEntry: DeleteEntryUseCase.Interface);
|
|
8
|
+
constructor(tenantScopes: TenantScopes.Interface, listTenants: ListTenantsUseCase.Interface);
|
|
15
9
|
run(params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>>;
|
|
16
10
|
}
|
|
17
11
|
declare class EmptyTrashBinTask implements TaskDefinition.Interface {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
2
|
import { ListTenantsUseCase } from "@webiny/api-core/features/tenancy/ListTenants/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
4
4
|
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
5
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
6
|
import { ListDeletedEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
@@ -12,12 +12,9 @@ const calculateDateTimeString = ()=>{
|
|
|
12
12
|
return currentDate.toISOString();
|
|
13
13
|
};
|
|
14
14
|
class EmptyTrashBinTaskHandlerImpl {
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
15
|
+
constructor(tenantScopes, listTenants){
|
|
16
|
+
this.tenantScopes = tenantScopes;
|
|
17
17
|
this.listTenants = listTenants;
|
|
18
|
-
this.listModels = listModels;
|
|
19
|
-
this.listDeletedEntries = listDeletedEntries;
|
|
20
|
-
this.deleteEntry = deleteEntry;
|
|
21
18
|
}
|
|
22
19
|
async run(params) {
|
|
23
20
|
const { input, controller } = params;
|
|
@@ -28,58 +25,60 @@ class EmptyTrashBinTaskHandlerImpl {
|
|
|
28
25
|
const executedTenantIds = input.executedTenantIds || [];
|
|
29
26
|
const tenants = baseTenants.filter((tenant)=>!executedTenantIds.includes(tenant.id));
|
|
30
27
|
let shouldTaskContinue = false;
|
|
31
|
-
|
|
28
|
+
for (const tenant of tenants){
|
|
32
29
|
if (controller.runtime.isCloseToTimeout()) {
|
|
33
30
|
shouldTaskContinue = true;
|
|
34
|
-
|
|
31
|
+
break;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (controller.runtime.isCloseToTimeout()) {
|
|
67
|
-
shouldTaskContinue = true;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
for (const entry of entries){
|
|
33
|
+
await this.tenantScopes.withTenant(tenant, async (scope)=>{
|
|
34
|
+
const listModels = scope.resolve(ListModelsUseCase);
|
|
35
|
+
const listDeletedEntries = scope.resolve(ListDeletedEntriesUseCase);
|
|
36
|
+
const deleteEntry = scope.resolve(DeleteEntryUseCase);
|
|
37
|
+
const modelsResult = await listModels.execute({
|
|
38
|
+
includePrivate: false
|
|
39
|
+
});
|
|
40
|
+
if (modelsResult.isFail()) return void await controller.logger.error({
|
|
41
|
+
message: `Failed to list models for tenant "${tenant.id}".`,
|
|
42
|
+
error: modelsResult.error
|
|
43
|
+
});
|
|
44
|
+
const models = modelsResult.value;
|
|
45
|
+
for (const model of models){
|
|
46
|
+
const listEntriesParams = {
|
|
47
|
+
where: {
|
|
48
|
+
deletedOn_lt: calculateDateTimeString()
|
|
49
|
+
},
|
|
50
|
+
limit: 50
|
|
51
|
+
};
|
|
52
|
+
while(true){
|
|
53
|
+
const listResult = await listDeletedEntries.execute(model, listEntriesParams);
|
|
54
|
+
if (listResult.isFail()) {
|
|
55
|
+
await controller.logger.error({
|
|
56
|
+
message: `Failed to list deleted entries of model "${model.modelId}".`,
|
|
57
|
+
error: listResult.error
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const { entries, meta } = listResult.value;
|
|
62
|
+
if (0 === meta.totalCount) break;
|
|
71
63
|
if (controller.runtime.isCloseToTimeout()) {
|
|
72
64
|
shouldTaskContinue = true;
|
|
73
65
|
break;
|
|
74
66
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
for (const entry of entries){
|
|
68
|
+
if (controller.runtime.isCloseToTimeout()) {
|
|
69
|
+
shouldTaskContinue = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
await deleteEntry.execute(model, entry.id, {
|
|
73
|
+
permanently: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if (!shouldTaskContinue) executedTenantIds.push(tenant.id);
|
|
79
|
+
});
|
|
80
|
+
if (shouldTaskContinue) break;
|
|
81
|
+
}
|
|
83
82
|
return shouldTaskContinue ? controller.response.continue({
|
|
84
83
|
...input,
|
|
85
84
|
executedTenantIds
|
|
@@ -89,11 +88,8 @@ class EmptyTrashBinTaskHandlerImpl {
|
|
|
89
88
|
const EmptyTrashBinTaskHandler = TaskHandler.createImplementation({
|
|
90
89
|
implementation: EmptyTrashBinTaskHandlerImpl,
|
|
91
90
|
dependencies: [
|
|
92
|
-
|
|
93
|
-
ListTenantsUseCase
|
|
94
|
-
ListModelsUseCase,
|
|
95
|
-
ListDeletedEntriesUseCase,
|
|
96
|
-
DeleteEntryUseCase
|
|
91
|
+
TenantScopes,
|
|
92
|
+
ListTenantsUseCase
|
|
97
93
|
]
|
|
98
94
|
});
|
|
99
95
|
class EmptyTrashBinTask {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks/EmptyTrashBinTask.js","sources":["../../src/tasks/EmptyTrashBinTask.ts"],"sourcesContent":["import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from \"~/types.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListTenantsUseCase } from \"@webiny/api-core/features/tenancy/ListTenants/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\n\nconst calculateDateTimeString = () => {\n // Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,\n // or default to 90 days if not set or set to 0.\n const retentionPeriodFromEnv = process.env[\"WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS\"];\n const retentionPeriod =\n retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0\n ? Number(retentionPeriodFromEnv)\n : 90;\n\n // Calculate the date-time by subtracting the retention period (in days) from the current date.\n const currentDate = new Date();\n currentDate.setDate(currentDate.getDate() - retentionPeriod);\n\n // Return the calculated date-time string in ISO 8601 format.\n return currentDate.toISOString();\n};\n\nclass EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n> {\n constructor(\n private tenantContext: TenantContext.Interface,\n private listTenants: ListTenantsUseCase.Interface,\n private listModels: ListModelsUseCase.Interface,\n private listDeletedEntries: ListDeletedEntriesUseCase.Interface,\n private deleteEntry: DeleteEntryUseCase.Interface\n ) {}\n\n async run(\n params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n ): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>> {\n const { input, controller } = params;\n\n // Abort the task if needed.\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n // Fetch all tenants, excluding those already processed.\n const tenantsResult = await this.listTenants.execute();\n if (tenantsResult.isFail()) {\n return controller.response.error(tenantsResult.error);\n }\n const baseTenants = tenantsResult.value;\n const executedTenantIds = input.executedTenantIds || [];\n const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));\n\n let shouldTaskContinue = false;\n\n // Iterate over each tenant.\n await this.tenantContext.withEachTenant(tenants, async tenant => {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n return;\n }\n\n // List all non-private models.\n const modelsResult = await this.listModels.execute({ includePrivate: false });\n if (modelsResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list models for tenant \"${tenant.id}\".`,\n error: modelsResult.error\n });\n return;\n }\n const models = modelsResult.value;\n\n // Process each model to delete trashed entries.\n for (const model of models) {\n // Query parameters for fetching deleted entries older than a minute ago.\n const listEntriesParams = {\n where: {\n deletedOn_lt: calculateDateTimeString()\n },\n limit: 50\n };\n\n // Continue deleting entries while there are entries left to delete.\n while (true) {\n const listResult = await this.listDeletedEntries.execute(\n model,\n listEntriesParams\n );\n if (listResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list deleted entries of model \"${model.modelId}\".`,\n error: listResult.error\n });\n break;\n }\n const { entries, meta } = listResult.value;\n\n if (meta.totalCount === 0) {\n break;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n for (const entry of entries) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n // Delete each entry individually.\n await this.deleteEntry.execute(model, entry.id, { permanently: true });\n }\n }\n }\n\n // If the task isn't continuing, add the tenant to the executed list.\n if (!shouldTaskContinue) {\n executedTenantIds.push(tenant.id);\n }\n });\n\n // Continue the task or mark it as done based on the `shouldContinue` flag.\n return shouldTaskContinue\n ? controller.response.continue({ ...input, executedTenantIds })\n : controller.response.done(\n \"Task done: emptied the trash bin for all registered models.\"\n );\n }\n}\n\nconst EmptyTrashBinTaskHandler = TaskHandler.createImplementation({\n implementation: EmptyTrashBinTaskHandlerImpl,\n dependencies: [\n TenantContext,\n ListTenantsUseCase,\n ListModelsUseCase,\n ListDeletedEntriesUseCase,\n DeleteEntryUseCase\n ]\n});\n\nclass EmptyTrashBinTask implements TaskDefinition.Interface {\n public readonly isPrivate = true;\n public readonly id = \"hcmsEntriesEmptyTrashBins\";\n public readonly title = \"Headless CMS - Empty all trash bins\";\n public readonly description =\n \"Delete all entries in the trash bin for each model in the system.\";\n public readonly maxIterations = 120;\n public readonly databaseLogs = false;\n\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = EmptyTrashBinTaskHandler;\n}\n\nexport const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({\n implementation: EmptyTrashBinTask,\n dependencies: []\n});\n"],"names":["calculateDateTimeString","retentionPeriodFromEnv","process","retentionPeriod","Number","currentDate","Date","EmptyTrashBinTaskHandlerImpl","tenantContext","listTenants","listModels","listDeletedEntries","deleteEntry","params","input","controller","tenantsResult","baseTenants","executedTenantIds","tenants","tenant","shouldTaskContinue","modelsResult","models","model","listEntriesParams","listResult","entries","meta","entry","EmptyTrashBinTaskHandler","TaskHandler","TenantContext","ListTenantsUseCase","ListModelsUseCase","ListDeletedEntriesUseCase","DeleteEntryUseCase","EmptyTrashBinTask","EmptyTrashBinTaskDefinition","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA,0BAA0B;IAG5B,MAAMC,yBAAy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C;IAC9D,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL;AAEA,MAAMC;;aACc,SAAS,GAAG;aACZ,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GACvB;aACY,aAAa,GAAG;aAChB,YAAY,GAAG;aAEf,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGP;;AACd;AAEO,MAAMQ,8BAA8BC,eAAe,oBAAoB,CAAC;IAC3E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"tasks/EmptyTrashBinTask.js","sources":["../../src/tasks/EmptyTrashBinTask.ts"],"sourcesContent":["import type { IEmptyTrashBinsInput, IEmptyTrashBinsOutput } from \"~/types.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListTenantsUseCase } from \"@webiny/api-core/features/tenancy/ListTenants/index.js\";\nimport { TenantScopes } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ListDeletedEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\n\nconst calculateDateTimeString = () => {\n // Retrieve the retention period from the environment variable WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS,\n // or default to 90 days if not set or set to 0.\n const retentionPeriodFromEnv = process.env[\"WEBINY_TRASH_BIN_RETENTION_PERIOD_DAYS\"];\n const retentionPeriod =\n retentionPeriodFromEnv && Number(retentionPeriodFromEnv) !== 0\n ? Number(retentionPeriodFromEnv)\n : 90;\n\n // Calculate the date-time by subtracting the retention period (in days) from the current date.\n const currentDate = new Date();\n currentDate.setDate(currentDate.getDate() - retentionPeriod);\n\n // Return the calculated date-time string in ISO 8601 format.\n return currentDate.toISOString();\n};\n\nclass EmptyTrashBinTaskHandlerImpl implements TaskHandler.Interface<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n> {\n constructor(\n private tenantScopes: TenantScopes.Interface,\n private listTenants: ListTenantsUseCase.Interface\n ) {}\n\n async run(\n params: TaskHandler.RunParams<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>\n ): Promise<TaskDefinition.Result<IEmptyTrashBinsInput, IEmptyTrashBinsOutput>> {\n const { input, controller } = params;\n\n // Abort the task if needed.\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n // Fetch all tenants, excluding those already processed.\n const tenantsResult = await this.listTenants.execute();\n if (tenantsResult.isFail()) {\n return controller.response.error(tenantsResult.error);\n }\n const baseTenants = tenantsResult.value;\n const executedTenantIds = input.executedTenantIds || [];\n const tenants = baseTenants.filter(tenant => !executedTenantIds.includes(tenant.id));\n\n let shouldTaskContinue = false;\n\n // Iterate over each tenant, in its scope: its models and entries are in its storage. The\n // timeout is checked before entering a scope, so no scope is built once time is up.\n for (const tenant of tenants) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n\n await this.tenantScopes.withTenant(tenant, async scope => {\n const listModels = scope.resolve(ListModelsUseCase);\n const listDeletedEntries = scope.resolve(ListDeletedEntriesUseCase);\n const deleteEntry = scope.resolve(DeleteEntryUseCase);\n\n // List all non-private models.\n const modelsResult = await listModels.execute({ includePrivate: false });\n if (modelsResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list models for tenant \"${tenant.id}\".`,\n error: modelsResult.error\n });\n return;\n }\n const models = modelsResult.value;\n\n // Process each model to delete trashed entries.\n for (const model of models) {\n // Query parameters for fetching deleted entries older than a minute ago.\n const listEntriesParams = {\n where: {\n deletedOn_lt: calculateDateTimeString()\n },\n limit: 50\n };\n\n // Continue deleting entries while there are entries left to delete.\n while (true) {\n const listResult = await listDeletedEntries.execute(\n model,\n listEntriesParams\n );\n if (listResult.isFail()) {\n await controller.logger.error({\n message: `Failed to list deleted entries of model \"${model.modelId}\".`,\n error: listResult.error\n });\n break;\n }\n const { entries, meta } = listResult.value;\n\n if (meta.totalCount === 0) {\n break;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n for (const entry of entries) {\n if (controller.runtime.isCloseToTimeout()) {\n shouldTaskContinue = true;\n break;\n }\n // Delete each entry individually.\n await deleteEntry.execute(model, entry.id, { permanently: true });\n }\n }\n }\n\n // If the task isn't continuing, add the tenant to the executed list.\n if (!shouldTaskContinue) {\n executedTenantIds.push(tenant.id);\n }\n });\n\n if (shouldTaskContinue) {\n break;\n }\n }\n\n // Continue the task or mark it as done based on the `shouldContinue` flag.\n return shouldTaskContinue\n ? controller.response.continue({ ...input, executedTenantIds })\n : controller.response.done(\n \"Task done: emptied the trash bin for all registered models.\"\n );\n }\n}\n\nconst EmptyTrashBinTaskHandler = TaskHandler.createImplementation({\n implementation: EmptyTrashBinTaskHandlerImpl,\n dependencies: [TenantScopes, ListTenantsUseCase]\n});\n\nclass EmptyTrashBinTask implements TaskDefinition.Interface {\n public readonly isPrivate = true;\n public readonly id = \"hcmsEntriesEmptyTrashBins\";\n public readonly title = \"Headless CMS - Empty all trash bins\";\n public readonly description =\n \"Delete all entries in the trash bin for each model in the system.\";\n public readonly maxIterations = 120;\n public readonly databaseLogs = false;\n\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = EmptyTrashBinTaskHandler;\n}\n\nexport const EmptyTrashBinTaskDefinition = TaskDefinition.createImplementation({\n implementation: EmptyTrashBinTask,\n dependencies: []\n});\n"],"names":["calculateDateTimeString","retentionPeriodFromEnv","process","retentionPeriod","Number","currentDate","Date","EmptyTrashBinTaskHandlerImpl","tenantScopes","listTenants","params","input","controller","tenantsResult","baseTenants","executedTenantIds","tenants","tenant","shouldTaskContinue","scope","listModels","ListModelsUseCase","listDeletedEntries","ListDeletedEntriesUseCase","deleteEntry","DeleteEntryUseCase","modelsResult","models","model","listEntriesParams","listResult","entries","meta","entry","EmptyTrashBinTaskHandler","TaskHandler","TenantScopes","ListTenantsUseCase","EmptyTrashBinTask","EmptyTrashBinTaskDefinition","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA,0BAA0B;IAG5B,MAAMC,yBAAyBC,QAAQ,GAAG,CAAC,yCAAyC;IACpF,MAAMC,kBACFF,0BAA0BG,AAAmC,MAAnCA,OAAOH,0BAC3BG,OAAOH,0BACP;IAGV,MAAMI,cAAc,IAAIC;IACxBD,YAAY,OAAO,CAACA,YAAY,OAAO,KAAKF;IAG5C,OAAOE,YAAY,WAAW;AAClC;AAEA,MAAME;IAIF,YACYC,YAAoC,EACpCC,WAAyC,CACnD;aAFUD,YAAY,GAAZA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IACFC,MAA0E,EACC;QAC3E,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAG9B,IAAIE,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAItC,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QACpD,IAAIA,cAAc,MAAM,IACpB,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAACC,cAAc,KAAK;QAExD,MAAMC,cAAcD,cAAc,KAAK;QACvC,MAAME,oBAAoBJ,MAAM,iBAAiB,IAAI,EAAE;QACvD,MAAMK,UAAUF,YAAY,MAAM,CAACG,CAAAA,SAAU,CAACF,kBAAkB,QAAQ,CAACE,OAAO,EAAE;QAElF,IAAIC,qBAAqB;QAIzB,KAAK,MAAMD,UAAUD,QAAS;YAC1B,IAAIJ,WAAW,OAAO,CAAC,gBAAgB,IAAI;gBACvCM,qBAAqB;gBACrB;YACJ;YAEA,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAACD,QAAQ,OAAME;gBAC7C,MAAMC,aAAaD,MAAM,OAAO,CAACE;gBACjC,MAAMC,qBAAqBH,M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,QAAQ,CAAC,QAAQ,CAAC;YAAE,GAAGD,KAAK;YAAEI;QAAkB,KAC3DH,WAAW,QAAQ,CAAC,IAAI,CACpB;IAEd;AACJ;AAEA,MAAMsB,2BAA2BC,YAAY,oBAAoB,CAAC;IAC9D,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAcC;KAAmB;AACpD;AAEA,MAAMC;;aACc,SAAS,GAAG;aACZ,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GACvB;aACY,aAAa,GAAG;aAChB,YAAY,GAAG;aAEf,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGJ;;AACd;AAEO,MAAMK,8BAA8BC,eAAe,oBAAoB,CAAC;IAC3E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context as BaseContext } from \"@webiny/handler/types.js\";\nimport type { ITaskIdentity } from \"@webiny/background-tasks/api/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HcmsBulkActionsContext extends BaseContext, CmsContext {}\n\n/**\n * Bulk Action Operation\n */\n\nexport interface IBulkActionOperationInput {\n actionName: string;\n modelId: string;\n ids: string[];\n data?: Record<string, any>;\n identity: ITaskIdentity;\n done?: string[];\n failed?: string[];\n}\n\nexport interface IBulkActionOperationOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n>;\n\n/**\n * Bulk Action Operation By Model\n */\n\nexport enum BulkActionOperationByModelAction {\n CREATE_SUBTASKS = \"CREATE_SUBTASKS\",\n CHECK_MORE_SUBTASKS = \"CHECK_MORE_SUBTASKS\",\n PROCESS_SUBTASKS = \"PROCESS_SUBTASKS\",\n END_TASK = \"END_TASK\"\n}\n\nexport interface IBulkActionOperationByModelInput {\n actionName: string;\n modelId: string;\n identity?: ITaskIdentity;\n where?: Record<string, any>;\n search?: string;\n after?: string | null;\n data?: Record<string, any>;\n action?: BulkActionOperationByModelAction;\n}\n\nexport interface IBulkActionOperationByModelOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n>;\n\n/**\n * Empty Trash Bin\n */\n\nexport interface IEmptyTrashBinsInput {\n executedTenantIds?: string[] | null;\n}\n\nexport type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;\n\nexport type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n>;\n"],"names":["BulkActionOperationByModelAction"],"mappings":"AAmCO,IAAKA,yCAAgCA,WAAAA,GAAAA,
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Context as BaseContext } from \"@webiny/handler/types.js\";\nimport type { ITaskIdentity } from \"@webiny/background-tasks/api/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HcmsBulkActionsContext extends BaseContext, CmsContext {}\n\n/**\n * Bulk Action Operation\n */\n\nexport interface IBulkActionOperationInput {\n actionName: string;\n modelId: string;\n ids: string[];\n data?: Record<string, any>;\n identity: ITaskIdentity;\n done?: string[];\n failed?: string[];\n}\n\nexport interface IBulkActionOperationOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationInput,\n IBulkActionOperationOutput\n>;\n\n/**\n * Bulk Action Operation By Model\n */\n\nexport enum BulkActionOperationByModelAction {\n CREATE_SUBTASKS = \"CREATE_SUBTASKS\",\n CHECK_MORE_SUBTASKS = \"CHECK_MORE_SUBTASKS\",\n PROCESS_SUBTASKS = \"PROCESS_SUBTASKS\",\n END_TASK = \"END_TASK\"\n}\n\nexport interface IBulkActionOperationByModelInput {\n actionName: string;\n modelId: string;\n identity?: ITaskIdentity;\n where?: Record<string, any>;\n search?: string;\n after?: string | null;\n data?: Record<string, any>;\n action?: BulkActionOperationByModelAction;\n}\n\nexport interface IBulkActionOperationByModelOutput {\n done: string[];\n failed: string[];\n}\n\nexport type IBulkActionOperationByModelTaskParams = TaskDefinition.RunParams<\n IBulkActionOperationByModelInput,\n IBulkActionOperationByModelOutput\n>;\n\n/**\n * Empty Trash Bin\n */\n\nexport interface IEmptyTrashBinsInput {\n executedTenantIds?: string[] | null;\n}\n\nexport type IEmptyTrashBinsOutput = TaskDefinition.ResultDone;\n\nexport type IEmptyTrashBinsTaskParams = TaskDefinition.RunParams<\n IEmptyTrashBinsInput,\n IEmptyTrashBinsOutput\n>;\n"],"names":["BulkActionOperationByModelAction"],"mappings":"AAmCO,IAAKA,yCAAgCA,WAAAA,GAAAA,SAAAA,gCAAAA"}
|