@webiny/api-headless-cms-tasks 6.1.0 → 6.2.0-beta.0

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.
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeCreateImpl implements EntryBeforeCrea
6
6
  handle(event: EntryBeforeCreateEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeCreate: typeof BlockModelActionOnEntryBeforeCreateImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/CreateEntry/events.js").EntryBeforeCreateEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/CreateEntry/events.js").EntryBeforeCreateEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeMoveImpl implements EntryBeforeMoveEv
6
6
  handle(event: EntryBeforeMoveEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeMove: typeof BlockModelActionOnEntryBeforeMoveImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/MoveEntry/events.js").EntryBeforeMoveEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/MoveEntry/events.js").EntryBeforeMoveEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforePublishImpl implements EntryBeforePub
6
6
  handle(event: EntryBeforePublishEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforePublish: typeof BlockModelActionOnEntryBeforePublishImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/PublishEntry/events.js").EntryBeforePublishEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/PublishEntry/events.js").EntryBeforePublishEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeRepublishImpl implements EntryBeforeR
6
6
  handle(event: EntryBeforeRepublishEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeRepublish: typeof BlockModelActionOnEntryBeforeRepublishImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/RepublishEntry/events.js").EntryBeforeRepublishEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/RepublishEntry/events.js").EntryBeforeRepublishEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeRestoreFromBinImpl implements EntryBe
6
6
  handle(event: EntryBeforeRestoreFromBinEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeRestoreFromBin: typeof BlockModelActionOnEntryBeforeRestoreFromBinImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/RestoreEntryFromBin/events.js").EntryBeforeRestoreFromBinEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/RestoreEntryFromBin/events.js").EntryBeforeRestoreFromBinEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeUnpublishImpl implements EntryBeforeU
6
6
  handle(event: EntryBeforeUnpublishEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeUnpublish: typeof BlockModelActionOnEntryBeforeUnpublishImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/events.js").EntryBeforeUnpublishEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/events.js").EntryBeforeUnpublishEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryBeforeUpdateImpl implements EntryBeforeUpda
6
6
  handle(event: EntryBeforeUpdateEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryBeforeUpdate: typeof BlockModelActionOnEntryBeforeUpdateImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/UpdateEntry/events.js").EntryBeforeUpdateEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/UpdateEntry/events.js").EntryBeforeUpdateEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnEntryRevisionBeforeCreateImpl implements EntryRe
6
6
  handle(event: EntryRevisionBeforeCreateEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnEntryRevisionBeforeCreate: typeof BlockModelActionOnEntryRevisionBeforeCreateImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/CreateEntryRevisionFrom/events.js").EntryRevisionBeforeCreateEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentEntry/CreateEntryRevisionFrom/events.js").EntryRevisionBeforeCreateEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnModelBeforeCreateFromImpl implements ModelBefore
6
6
  handle(event: ModelBeforeCreateFromEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnModelBeforeCreateFrom: typeof BlockModelActionOnModelBeforeCreateFromImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentModel/CreateModelFrom/events.js").ModelBeforeCreateFromEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentModel/CreateModelFrom/events.js").ModelBeforeCreateFromEvent>>;
10
10
  };
11
11
  export {};
@@ -6,6 +6,6 @@ declare class BlockModelActionOnModelBeforeUpdateImpl implements ModelBeforeUpda
6
6
  handle(event: ModelBeforeUpdateEventHandler.Event): Promise<void>;
7
7
  }
8
8
  export declare const BlockModelActionOnModelBeforeUpdate: typeof BlockModelActionOnModelBeforeUpdateImpl & {
9
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/EventPublisher").IEventHandler<import("@webiny/api-headless-cms/features/contentModel/UpdateModel/events.js").ModelBeforeUpdateEvent>>;
9
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-headless-cms/features/contentModel/UpdateModel/events.js").ModelBeforeUpdateEvent>>;
10
10
  };
11
11
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { HcmsTasksContext } from "../../types.js";
2
2
  import type { IDeleteCmsModelTask } from "../../features/DeleteModelTask/types.js";
3
3
  export interface ICancelDeleteModelParams {
4
- readonly context: Pick<HcmsTasksContext, "cms" | "tasks" | "db">;
4
+ readonly context: Pick<HcmsTasksContext, "cms" | "tasks" | "db" | "container">;
5
5
  readonly modelId: string;
6
6
  }
7
7
  export declare const cancelDeleteModel: (params: ICancelDeleteModelParams) => Promise<IDeleteCmsModelTask>;
@@ -2,20 +2,29 @@ import { WebinyError } from "@webiny/error";
2
2
  import { createStoreKey } from "../../helpers/store.js";
3
3
  import { DELETE_MODEL_TASK } from "../../constants.js";
4
4
  import { getStatus } from "./status.js";
5
+ import { NotAuthorizedError } from "@webiny/api-headless-cms/utils/errors.js";
6
+ import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
5
7
  export const cancelDeleteModel = async params => {
6
8
  const {
7
9
  context,
8
10
  modelId
9
11
  } = params;
10
12
  const model = await context.cms.getModel(modelId);
11
- await context.cms.accessControl.ensureCanAccessModel({
13
+ const accessControl = context.container.resolve(AccessControl);
14
+ const canAccessModel = await accessControl.canAccessModel({
12
15
  model,
13
16
  rwd: "d"
14
17
  });
15
- await context.cms.accessControl.ensureCanAccessEntry({
18
+ if (!canAccessModel) {
19
+ throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
20
+ }
21
+ const canAccessEntry = await accessControl.canAccessEntry({
16
22
  model,
17
23
  rwd: "w"
18
24
  });
25
+ if (!canAccessEntry) {
26
+ throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
27
+ }
19
28
  const storeKey = createStoreKey(model);
20
29
  const result = await context.db.store.getValue(storeKey);
21
30
  const taskId = result.data?.task;
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","createStoreKey","DELETE_MODEL_TASK","getStatus","cancelDeleteModel","params","context","modelId","model","cms","getModel","accessControl","ensureCanAccessModel","rwd","ensureCanAccessEntry","storeKey","result","db","store","getValue","taskId","data","task","removeValue","error","from","code","message","tasks","getTask","definitionId","abortResult","abort","id","canceledTask","value","status","taskStatus","total","output","deleted"],"sources":["cancelDeleteModel.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IDeleteModelTaskOutput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\n\nexport interface ICancelDeleteModelParams {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\">;\n readonly modelId: string;\n}\n\nexport const cancelDeleteModel = async (\n params: ICancelDeleteModelParams\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n const model = await context.cms.getModel(modelId);\n\n await context.cms.accessControl.ensureCanAccessModel({\n model,\n rwd: \"d\"\n });\n\n await context.cms.accessControl.ensureCanAccessEntry({\n model,\n rwd: \"w\"\n });\n\n const storeKey = createStoreKey(model);\n\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n\n const taskId = result.data?.task;\n\n await context.db.store.removeValue(storeKey);\n if (!taskId) {\n if (result.error) {\n throw WebinyError.from(result.error, {\n code: \"DELETE_MODEL_NO_TASK_DEFINED\"\n });\n }\n throw new WebinyError({\n message: `Model \"${modelId}\" is not being deleted.`,\n code: \"MODEL_NOT_BEING_DELETED\"\n });\n }\n\n const task = await context.tasks.getTask<IDeleteModelTaskInput, IDeleteModelTaskOutput>(taskId);\n if (task?.definitionId !== DELETE_MODEL_TASK) {\n throw new WebinyError({\n message: `The task which is deleting a model cannot be found. Please check Step Functions for more info. Task id: ${taskId}`,\n code: \"DELETE_MODEL_TASK_NOT_FOUND\",\n data: {\n model: model.modelId,\n task: taskId\n }\n });\n }\n\n const abortResult = await context.tasks.abort<IDeleteModelTaskInput, IDeleteModelTaskOutput>({\n id: task.id,\n message: \"User canceled the task.\"\n });\n\n const canceledTask = abortResult.value;\n\n return {\n id: canceledTask.id,\n status: getStatus(canceledTask.taskStatus),\n total: canceledTask.output?.total || 0,\n deleted: canceledTask.output?.deleted || 0\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAO3C,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAOlB,OAAO,MAAMC,iBAAiB,GAAG,MAC7BC,MAAgC,IACD;EAC/B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,MAAMG,KAAK,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACC,QAAQ,CAACH,OAAO,CAAC;EAEjD,MAAMD,OAAO,CAACG,GAAG,CAACE,aAAa,CAACC,oBAAoB,CAAC;IACjDJ,KAAK;IACLK,GAAG,EAAE;EACT,CAAC,CAAC;EAEF,MAAMP,OAAO,CAACG,GAAG,CAACE,aAAa,CAACG,oBAAoB,CAAC;IACjDN,KAAK;IACLK,GAAG,EAAE;EACT,CAAC,CAAC;EAEF,MAAME,QAAQ,GAAGd,cAAc,CAACO,KAAK,CAAC;EAEtC,MAAMQ,MAAM,GAAG,MAAMV,OAAO,CAACW,EAAE,CAACC,KAAK,CAACC,QAAQ,CAAcJ,QAAQ,CAAC;EAErE,MAAMK,MAAM,GAAGJ,MAAM,CAACK,IAAI,EAAEC,IAAI;EAEhC,MAAMhB,OAAO,CAACW,EAAE,CAACC,KAAK,CAACK,WAAW,CAACR,QAAQ,CAAC;EAC5C,IAAI,CAACK,MAAM,EAAE;IACT,IAAIJ,MAAM,CAACQ,KAAK,EAAE;MACd,MAAMxB,WAAW,CAACyB,IAAI,CAACT,MAAM,CAACQ,KAAK,EAAE;QACjCE,IAAI,EAAE;MACV,CAAC,CAAC;IACN;IACA,MAAM,IAAI1B,WAAW,CAAC;MAClB2B,OAAO,EAAE,UAAUpB,OAAO,yBAAyB;MACnDmB,IAAI,EAAE;IACV,CAAC,CAAC;EACN;EAEA,MAAMJ,IAAI,GAAG,MAAMhB,OAAO,CAACsB,KAAK,CAACC,OAAO,CAAgDT,MAAM,CAAC;EAC/F,IAAIE,IAAI,EAAEQ,YAAY,KAAK5B,iBAAiB,EAAE;IAC1C,MAAM,IAAIF,WAAW,CAAC;MAClB2B,OAAO,EAAE,2GAA2GP,MAAM,EAAE;MAC5HM,IAAI,EAAE,6BAA6B;MACnCL,IAAI,EAAE;QACFb,KAAK,EAAEA,KAAK,CAACD,OAAO;QACpBe,IAAI,EAAEF;MACV;IACJ,CAAC,CAAC;EACN;EAEA,MAAMW,WAAW,GAAG,MAAMzB,OAAO,CAACsB,KAAK,CAACI,KAAK,CAAgD;IACzFC,EAAE,EAAEX,IAAI,CAACW,EAAE;IACXN,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,MAAMO,YAAY,GAAGH,WAAW,CAACI,KAAK;EAEtC,OAAO;IACHF,EAAE,EAAEC,YAAY,CAACD,EAAE;IACnBG,MAAM,EAAEjC,SAAS,CAAC+B,YAAY,CAACG,UAAU,CAAC;IAC1CC,KAAK,EAAEJ,YAAY,CAACK,MAAM,EAAED,KAAK,IAAI,CAAC;IACtCE,OAAO,EAAEN,YAAY,CAACK,MAAM,EAAEC,OAAO,IAAI;EAC7C,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","createStoreKey","DELETE_MODEL_TASK","getStatus","NotAuthorizedError","AccessControl","cancelDeleteModel","params","context","modelId","model","cms","getModel","accessControl","container","resolve","canAccessModel","rwd","name","canAccessEntry","storeKey","result","db","store","getValue","taskId","data","task","removeValue","error","from","code","message","tasks","getTask","definitionId","abortResult","abort","id","canceledTask","value","status","taskStatus","total","output","deleted"],"sources":["cancelDeleteModel.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IDeleteModelTaskOutput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\nimport { NotAuthorizedError } from \"@webiny/api-headless-cms/utils/errors.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\n\nexport interface ICancelDeleteModelParams {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\" | \"container\">;\n readonly modelId: string;\n}\n\nexport const cancelDeleteModel = async (\n params: ICancelDeleteModelParams\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n const model = await context.cms.getModel(modelId);\n const accessControl = context.container.resolve(AccessControl);\n\n const canAccessModel = await accessControl.canAccessModel({ model, rwd: \"d\" });\n if (!canAccessModel) {\n throw new NotAuthorizedError(`Not allowed to access content model \"${model.name}\".`);\n }\n\n const canAccessEntry = await accessControl.canAccessEntry({ model, rwd: \"w\" });\n if (!canAccessEntry) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n\n const storeKey = createStoreKey(model);\n\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n\n const taskId = result.data?.task;\n\n await context.db.store.removeValue(storeKey);\n if (!taskId) {\n if (result.error) {\n throw WebinyError.from(result.error, {\n code: \"DELETE_MODEL_NO_TASK_DEFINED\"\n });\n }\n throw new WebinyError({\n message: `Model \"${modelId}\" is not being deleted.`,\n code: \"MODEL_NOT_BEING_DELETED\"\n });\n }\n\n const task = await context.tasks.getTask<IDeleteModelTaskInput, IDeleteModelTaskOutput>(taskId);\n if (task?.definitionId !== DELETE_MODEL_TASK) {\n throw new WebinyError({\n message: `The task which is deleting a model cannot be found. Please check Step Functions for more info. Task id: ${taskId}`,\n code: \"DELETE_MODEL_TASK_NOT_FOUND\",\n data: {\n model: model.modelId,\n task: taskId\n }\n });\n }\n\n const abortResult = await context.tasks.abort<IDeleteModelTaskInput, IDeleteModelTaskOutput>({\n id: task.id,\n message: \"User canceled the task.\"\n });\n\n const canceledTask = abortResult.value;\n\n return {\n id: canceledTask.id,\n status: getStatus(canceledTask.taskStatus),\n total: canceledTask.output?.total || 0,\n deleted: canceledTask.output?.deleted || 0\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAO3C,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAClB,SAASC,kBAAkB,QAAQ,0CAA0C;AAC7E,SAASC,aAAa,QAAQ,0DAA0D;AAOxF,OAAO,MAAMC,iBAAiB,GAAG,MAC7BC,MAAgC,IACD;EAC/B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,MAAMG,KAAK,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACC,QAAQ,CAACH,OAAO,CAAC;EACjD,MAAMI,aAAa,GAAGL,OAAO,CAACM,SAAS,CAACC,OAAO,CAACV,aAAa,CAAC;EAE9D,MAAMW,cAAc,GAAG,MAAMH,aAAa,CAACG,cAAc,CAAC;IAAEN,KAAK;IAAEO,GAAG,EAAE;EAAI,CAAC,CAAC;EAC9E,IAAI,CAACD,cAAc,EAAE;IACjB,MAAM,IAAIZ,kBAAkB,CAAC,wCAAwCM,KAAK,CAACQ,IAAI,IAAI,CAAC;EACxF;EAEA,MAAMC,cAAc,GAAG,MAAMN,aAAa,CAACM,cAAc,CAAC;IAAET,KAAK;IAAEO,GAAG,EAAE;EAAI,CAAC,CAAC;EAC9E,IAAI,CAACE,cAAc,EAAE;IACjB,MAAM,IAAIf,kBAAkB,CAAC,0BAA0BM,KAAK,CAACD,OAAO,YAAY,CAAC;EACrF;EAEA,MAAMW,QAAQ,GAAGnB,cAAc,CAACS,KAAK,CAAC;EAEtC,MAAMW,MAAM,GAAG,MAAMb,OAAO,CAACc,EAAE,CAACC,KAAK,CAACC,QAAQ,CAAcJ,QAAQ,CAAC;EAErE,MAAMK,MAAM,GAAGJ,MAAM,CAACK,IAAI,EAAEC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ue } from "../../helpers/store.js";
2
2
  import { DELETE_MODEL_TASK } from "../../constants.js";
3
3
  import { getStatus } from "./status.js";
4
+ import { NotAuthorizedError } from "@webiny/api-headless-cms/utils/errors.js";
4
5
  export const fullyDeleteModel = async params => {
5
6
  const {
6
7
  context,
@@ -10,14 +11,20 @@ export const fullyDeleteModel = async params => {
10
11
  if (model.isPrivate) {
11
12
  throw new Error(`Cannot delete private model.`);
12
13
  }
13
- await context.cms.accessControl.ensureCanAccessModel({
14
+ const canAccessModel = await context.cms.accessControl.canAccessModel({
14
15
  model,
15
16
  rwd: "d"
16
17
  });
17
- await context.cms.accessControl.ensureCanAccessEntry({
18
+ if (!canAccessModel) {
19
+ throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
20
+ }
21
+ const canAccessEntry = await context.cms.accessControl.canAccessEntry({
18
22
  model,
19
23
  rwd: "w"
20
24
  });
25
+ if (!canAccessEntry) {
26
+ throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
27
+ }
21
28
  if (!model) {
22
29
  throw new Error(`Model "${modelId}" not found.`);
23
30
  }
@@ -1 +1 @@
1
- {"version":3,"names":["createStoreKey","createStoreValue","DELETE_MODEL_TASK","getStatus","fullyDeleteModel","params","context","modelId","model","cms","getModel","isPrivate","Error","accessControl","ensureCanAccessModel","rwd","ensureCanAccessEntry","storeKey","result","db","store","getValue","taskId","data","task","triggerResult","tasks","trigger","input","definition","name","value","identity","security","getIdentity","storeValue","id","type","displayName","status","taskStatus","total","deleted"],"sources":["fullyDeleteModel.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey, createStoreValue } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\n\nexport interface IFullyDeleteModelParams {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\" | \"security\">;\n readonly modelId: string;\n}\n\nexport const fullyDeleteModel = async (\n params: IFullyDeleteModelParams\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n const model = await context.cms.getModel(modelId);\n\n if (model.isPrivate) {\n throw new Error(`Cannot delete private model.`);\n }\n\n await context.cms.accessControl.ensureCanAccessModel({\n model,\n rwd: \"d\"\n });\n\n await context.cms.accessControl.ensureCanAccessEntry({\n model,\n rwd: \"w\"\n });\n\n if (!model) {\n throw new Error(`Model \"${modelId}\" not found.`);\n }\n const storeKey = createStoreKey(model);\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n const taskId = result.data?.task;\n if (taskId) {\n throw new Error(`Model \"${modelId}\" is already getting deleted. Task id: ${taskId}.`);\n }\n\n const triggerResult = await context.tasks.trigger<IDeleteModelTaskInput>({\n input: {\n modelId\n },\n definition: DELETE_MODEL_TASK,\n name: `Fully delete model: ${modelId}`\n });\n\n const task = triggerResult.value;\n\n const identity = context.security.getIdentity();\n\n await context.db.store.storeValue(\n storeKey,\n createStoreValue({\n ...model,\n identity: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n task: task.id\n })\n );\n\n return {\n id: task.id,\n status: getStatus(task.taskStatus),\n total: 0,\n deleted: 0\n };\n};\n"],"mappings":"AAMA,SAASA,cAAc,EAAEC,gBAAgB;AACzC,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAOlB,OAAO,MAAMC,gBAAgB,GAAG,MAC5BC,MAA+B,IACA;EAC/B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,MAAMG,KAAK,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACC,QAAQ,CAACH,OAAO,CAAC;EAEjD,IAAIC,KAAK,CAACG,SAAS,EAAE;IACjB,MAAM,IAAIC,KAAK,CAAC,8BAA8B,CAAC;EACnD;EAEA,MAAMN,OAAO,CAACG,GAAG,CAACI,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;IACHA,EAAE,EAAEZ,IAAI,CAACY,EAAE;IACXG,MAAM,EAAEpC,SAAS,CAACqB,IAAI,CAACgB,UAAU,CAAC;IAClCC,KAAK,EAAE,CAAC;IACRC,OAAO,EAAE;EACb,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createStoreKey","createStoreValue","DELETE_MODEL_TASK","getStatus","NotAuthorizedError","fullyDeleteModel","params","context","modelId","model","cms","getModel","isPrivate","Error","canAccessModel","accessControl","rwd","name","canAccessEntry","storeKey","result","db","store","getValue","taskId","data","task","triggerResult","tasks","trigger","input","definition","value","identity","security","getIdentity","storeValue","id","type","displayName","status","taskStatus","total","deleted"],"sources":["fullyDeleteModel.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey, createStoreValue } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\nimport { NotAuthorizedError } from \"@webiny/api-headless-cms/utils/errors.js\";\n\nexport interface IFullyDeleteModelParams {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\" | \"security\">;\n readonly modelId: string;\n}\n\nexport const fullyDeleteModel = async (\n params: IFullyDeleteModelParams\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n const model = await context.cms.getModel(modelId);\n\n if (model.isPrivate) {\n throw new Error(`Cannot delete private model.`);\n }\n\n const canAccessModel = await context.cms.accessControl.canAccessModel({ model, rwd: \"d\" });\n if (!canAccessModel) {\n throw new NotAuthorizedError(`Not allowed to access content model \"${model.name}\".`);\n }\n\n const canAccessEntry = await context.cms.accessControl.canAccessEntry({ model, rwd: \"w\" });\n if (!canAccessEntry) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n\n if (!model) {\n throw new Error(`Model \"${modelId}\" not found.`);\n }\n const storeKey = createStoreKey(model);\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n const taskId = result.data?.task;\n if (taskId) {\n throw new Error(`Model \"${modelId}\" is already getting deleted. Task id: ${taskId}.`);\n }\n\n const triggerResult = await context.tasks.trigger<IDeleteModelTaskInput>({\n input: {\n modelId\n },\n definition: DELETE_MODEL_TASK,\n name: `Fully delete model: ${modelId}`\n });\n\n const task = triggerResult.value;\n\n const identity = context.security.getIdentity();\n\n await context.db.store.storeValue(\n storeKey,\n createStoreValue({\n ...model,\n identity: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n task: task.id\n })\n );\n\n return {\n id: task.id,\n status: getStatus(task.taskStatus),\n total: 0,\n deleted: 0\n };\n};\n"],"mappings":"AAMA,SAASA,cAAc,EAAEC,gBAAgB;AACzC,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAClB,SAASC,kBAAkB,QAAQ,0CAA0C;AAO7E,OAAO,MAAMC,gBAAgB,GAAG,MAC5BC,MAA+B,IACA;EAC/B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,MAAMG,KAAK,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACC,QAAQ,CAACH,OAAO,CAAC;EAEjD,IAAIC,KAAK,CAACG,SAAS,EAAE;IACjB,MAAM,IAAIC,KAAK,CAAC,8BAA8B,CAAC;EACnD;EAEA,MAAMC,cAAc,GAAG,MAAMP,OAAO,CAACG,GAAG,CAACK,aAAa,CAACD,cAAc,CAAC;IAAEL,KAAK;IAAEO,GAAG,EAAE;EAAI,CAAC,CAAC;EAC1F,IAAI,CAACF,cAAc,EAAE;IACjB,MAAM,IAAIV,kBAAkB,CAAC,wCAAwCK,KAAK,CAACQ,IAAI,IAAI,CAAC;EACxF;EAEA,MAAMC,cAAc,GAAG,MAAMX,OAAO,CAACG,GAAG,CAACK,aAAa,CAACG,cAAc,CAAC;IAAET,KAAK;IAAE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M,EAAErC,SAAS,CAACuB,IAAI,CAACe,UAAU,CAAC;IAClCC,KAAK,EAAE,CAAC;IACRC,OAAO,EAAE;EACb,CAAC;AACL,CAAC","ignoreList":[]}
@@ -3,6 +3,7 @@ import { NotFoundError } from "@webiny/handler-graphql";
3
3
  import { createStoreKey } from "../../helpers/store.js";
4
4
  import { DELETE_MODEL_TASK } from "../../constants.js";
5
5
  import { getStatus } from "./status.js";
6
+ import { NotAuthorizedError } from "@webiny/api-headless-cms/utils/errors.js";
6
7
  export const getDeleteModelProgress = async params => {
7
8
  const {
8
9
  context,
@@ -23,14 +24,20 @@ export const getDeleteModelProgress = async params => {
23
24
  }
24
25
  });
25
26
  }
26
- await context.cms.accessControl.ensureCanAccessModel({
27
+ const canAccessModel = await context.cms.accessControl.canAccessModel({
27
28
  model,
28
29
  rwd: "d"
29
30
  });
30
- await context.cms.accessControl.ensureCanAccessEntry({
31
+ if (!canAccessModel) {
32
+ throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
33
+ }
34
+ const canAccessEntry = await context.cms.accessControl.canAccessEntry({
31
35
  model,
32
36
  rwd: "w"
33
37
  });
38
+ if (!canAccessEntry) {
39
+ throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
40
+ }
34
41
  const storeKey = createStoreKey(model);
35
42
  const result = await context.db.store.getValue(storeKey);
36
43
  const taskId = result.data?.task;
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","NotFoundError","createStoreKey","DELETE_MODEL_TASK","getStatus","getDeleteModelProgress","params","context","modelId","model","cms","getModel","ex","message","code","data","accessControl","ensureCanAccessModel","rwd","ensureCanAccessEntry","storeKey","result","db","store","getValue","taskId","task","Error","tasks","getTask","definitionId","id","status","taskStatus","total","output","deleted"],"sources":["getDeleteModelProgress.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IDeleteModelTaskOutput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\n\nexport interface IGetDeleteModelProgress {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\">;\n readonly modelId: string;\n}\n\nexport const getDeleteModelProgress = async (\n params: IGetDeleteModelProgress\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n let model: CmsModel;\n try {\n model = await context.cms.getModel(modelId);\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n throw ex;\n }\n throw new WebinyError({\n message: \"Model not found. It must have been deleted already.\",\n code: \"MODEL_ALREADY_DELETED_FOUND\",\n data: {\n model: modelId\n }\n });\n }\n\n await context.cms.accessControl.ensureCanAccessModel({\n model,\n rwd: \"d\"\n });\n\n await context.cms.accessControl.ensureCanAccessEntry({\n model,\n rwd: \"w\"\n });\n\n const storeKey = createStoreKey(model);\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n\n const taskId = result.data?.task;\n if (!taskId) {\n throw new Error(`Model \"${modelId}\" is not being deleted.`);\n }\n\n const task = await context.tasks.getTask<IDeleteModelTaskInput, IDeleteModelTaskOutput>(taskId);\n if (task?.definitionId !== DELETE_MODEL_TASK) {\n throw new WebinyError({\n message: `The task which is deleting a model cannot be found.`,\n code: \"DELETE_MODEL_TASK_NOT_FOUND\",\n data: {\n model: model.modelId,\n task: taskId\n }\n });\n }\n return {\n id: task.id,\n status: getStatus(task.taskStatus),\n total: task.output?.total || 0,\n deleted: task.output?.deleted || 0\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,aAAa,QAAQ,yBAAyB;AAQvD,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAC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qD;MAC9DC,IAAI,EAAE,6BAA6B;MACnCC,IAAI,EAAE;QACFN,KAAK,EAAEA,KAAK,CAACD,OAAO;QACpBkB,IAAI,EAAED;MACV;IACJ,CAAC,CAAC;EACN;EACA,OAAO;IACHM,EAAE,EAAEL,IAAI,CAACK,EAAE;IACXC,MAAM,EAAE5B,SAAS,CAACsB,IAAI,CAACO,UAAU,CAAC;IAClCC,KAAK,EAAER,IAAI,CAACS,MAAM,EAAED,KAAK,IAAI,CAAC;IAC9BE,OAAO,EAAEV,IAAI,CAACS,MAAM,EAAEC,OAAO,IAAI;EACrC,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","NotFoundError","createStoreKey","DELETE_MODEL_TASK","getStatus","NotAuthorizedError","getDeleteModelProgress","params","context","modelId","model","cms","getModel","ex","message","code","data","canAccessModel","accessControl","rwd","name","canAccessEntry","storeKey","result","db","store","getValue","taskId","task","Error","tasks","getTask","definitionId","id","status","taskStatus","total","output","deleted"],"sources":["getDeleteModelProgress.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type {\n IDeleteCmsModelTask,\n IDeleteModelTaskInput,\n IDeleteModelTaskOutput,\n IStoreValue\n} from \"~/features/DeleteModelTask/types.js\";\nimport { createStoreKey } from \"~/helpers/store.js\";\nimport { DELETE_MODEL_TASK } from \"~/constants.js\";\nimport { getStatus } from \"~/graphql/deleteModel/status.js\";\nimport { NotAuthorizedError } from \"@webiny/api-headless-cms/utils/errors.js\";\n\nexport interface IGetDeleteModelProgress {\n readonly context: Pick<HcmsTasksContext, \"cms\" | \"tasks\" | \"db\">;\n readonly modelId: string;\n}\n\nexport const getDeleteModelProgress = async (\n params: IGetDeleteModelProgress\n): Promise<IDeleteCmsModelTask> => {\n const { context, modelId } = params;\n\n let model: CmsModel;\n try {\n model = await context.cms.getModel(modelId);\n } catch (ex) {\n if (ex instanceof NotFoundError === false) {\n throw ex;\n }\n throw new WebinyError({\n message: \"Model not found. It must have been deleted already.\",\n code: \"MODEL_ALREADY_DELETED_FOUND\",\n data: {\n model: modelId\n }\n });\n }\n\n const canAccessModel = await context.cms.accessControl.canAccessModel({ model, rwd: \"d\" });\n if (!canAccessModel) {\n throw new NotAuthorizedError(`Not allowed to access content model \"${model.name}\".`);\n }\n\n const canAccessEntry = await context.cms.accessControl.canAccessEntry({ model, rwd: \"w\" });\n if (!canAccessEntry) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n\n const storeKey = createStoreKey(model);\n const result = await context.db.store.getValue<IStoreValue>(storeKey);\n\n const taskId = result.data?.task;\n if (!taskId) {\n throw new Error(`Model \"${modelId}\" is not being deleted.`);\n }\n\n const task = await context.tasks.getTask<IDeleteModelTaskInput, IDeleteModelTaskOutput>(taskId);\n if (task?.definitionId !== DELETE_MODEL_TASK) {\n throw new WebinyError({\n message: `The task which is deleting a model cannot be found.`,\n code: \"DELETE_MODEL_TASK_NOT_FOUND\",\n data: {\n model: model.modelId,\n task: taskId\n }\n });\n }\n return {\n id: task.id,\n status: getStatus(task.taskStatus),\n total: task.output?.total || 0,\n deleted: task.output?.deleted || 0\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,aAAa,QAAQ,yBAAyB;AAQvD,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAC1B,SAASC,SAAS;AAClB,SAASC,kBAAkB,QAAQ,0CAA0C;AAO7E,OAAO,MAAMC,sBAAsB,GAAG,MAClCC,MAA+B,IACA;EAC/B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEnC,IAAIG,KAAe;EACnB,IAAI;IACAA,KAAK,GAAG,MAAMF,OAAO,CAACG,GAAG,CAACC,QAAQ,CAACH,OAAO,CAAC;EAC/C,CAAC,CAAC,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AE,qDAAqD;MAC9DC,IAAI,EAAE,6BAA6B;MACnCC,IAAI,EAAE;QACFN,KAAK,EAAEA,KAAK,CAACD,OAAO;QACpBmB,IAAI,EAAED;MACV;IACJ,CAAC,CAAC;EACN;EACA,OAAO;IACHM,EAAE,EAAEL,IAAI,CAACK,EAAE;IACXC,MAAM,EAAE9B,SAAS,CAACwB,IAAI,CAACO,UAAU,CAAC;IAClCC,KAAK,EAAER,IAAI,CAACS,MAAM,EAAED,KAAK,IAAI,CAAC;IAC9BE,OAAO,EAAEV,IAAI,CAACS,MAAM,EAAEC,OAAO,IAAI;EACrC,CAAC;AACL,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-tasks",
3
- "version": "6.1.0",
3
+ "version": "6.2.0-beta.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "description": "Background tasks for Webiny Headless CMS",
@@ -14,33 +14,33 @@
14
14
  },
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@webiny/api": "6.1.0",
18
- "@webiny/api-aco": "6.1.0",
19
- "@webiny/api-headless-cms": "6.1.0",
20
- "@webiny/api-headless-cms-bulk-actions": "6.1.0",
21
- "@webiny/api-headless-cms-import-export": "6.1.0",
22
- "@webiny/db": "6.1.0",
23
- "@webiny/error": "6.1.0",
24
- "@webiny/feature": "6.1.0",
25
- "@webiny/handler-graphql": "6.1.0",
26
- "@webiny/tasks": "6.1.0",
27
- "@webiny/utils": "6.1.0",
17
+ "@webiny/api": "6.2.0-beta.0",
18
+ "@webiny/api-aco": "6.2.0-beta.0",
19
+ "@webiny/api-headless-cms": "6.2.0-beta.0",
20
+ "@webiny/api-headless-cms-bulk-actions": "6.2.0-beta.0",
21
+ "@webiny/api-headless-cms-import-export": "6.2.0-beta.0",
22
+ "@webiny/db": "6.2.0-beta.0",
23
+ "@webiny/error": "6.2.0-beta.0",
24
+ "@webiny/feature": "6.2.0-beta.0",
25
+ "@webiny/handler-graphql": "6.2.0-beta.0",
26
+ "@webiny/tasks": "6.2.0-beta.0",
27
+ "@webiny/utils": "6.2.0-beta.0",
28
28
  "zod": "4.3.6"
29
29
  },
30
30
  "devDependencies": {
31
- "@webiny/api-core": "6.1.0",
32
- "@webiny/build-tools": "6.1.0",
33
- "@webiny/handler": "6.1.0",
34
- "@webiny/handler-aws": "6.1.0",
35
- "@webiny/plugins": "6.1.0",
36
- "@webiny/project-utils": "6.1.0",
37
- "@webiny/wcp": "6.1.0",
31
+ "@webiny/api-core": "6.2.0-beta.0",
32
+ "@webiny/build-tools": "6.2.0-beta.0",
33
+ "@webiny/handler": "6.2.0-beta.0",
34
+ "@webiny/handler-aws": "6.2.0-beta.0",
35
+ "@webiny/plugins": "6.2.0-beta.0",
36
+ "@webiny/project-utils": "6.2.0-beta.0",
37
+ "@webiny/wcp": "6.2.0-beta.0",
38
38
  "typescript": "5.9.3",
39
- "vitest": "4.1.2"
39
+ "vitest": "4.1.4"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public",
43
43
  "directory": "dist"
44
44
  },
45
- "gitHead": "65e0ac1889b3392c99b8cac6cde508e1e831c715"
45
+ "gitHead": "3d3148358b6febbc857371930871743bec3b3939"
46
46
  }