@webiny/api-headless-cms-tasks 6.3.0-beta.4 → 6.4.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.
- package/constants.js +2 -1
- package/constants.js.map +1 -1
- package/features/DeleteModelTask/DeleteModel.js +92 -119
- package/features/DeleteModelTask/DeleteModel.js.map +1 -1
- package/features/DeleteModelTask/DeleteModelTask.js +33 -31
- package/features/DeleteModelTask/DeleteModelTask.js.map +1 -1
- package/features/DeleteModelTask/feature.js +6 -5
- package/features/DeleteModelTask/feature.js.map +1 -1
- package/features/DeleteModelTask/types.js +7 -6
- package/features/DeleteModelTask/types.js.map +1 -1
- package/features/DisableModel/BlockActionIfModelDisabled.js +9 -10
- package/features/DisableModel/BlockActionIfModelDisabled.js.map +1 -1
- package/features/DisableModel/abstractions.js +2 -1
- package/features/DisableModel/abstractions.js.map +1 -1
- package/features/DisableModel/feature.js +18 -22
- package/features/DisableModel/feature.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeCreate.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeCreate.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeMove.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeMove.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforePublish.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforePublish.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeRepublish.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeRepublish.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeRestoreFromBin.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeRestoreFromBin.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeUnpublish.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeUnpublish.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeUpdate.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryBeforeUpdate.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnEntryRevisionBeforeCreate.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnEntryRevisionBeforeCreate.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnModelBeforeCreateFrom.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnModelBeforeCreateFrom.js.map +1 -1
- package/features/DisableModel/handlers/BlockModelActionOnModelBeforeUpdate.js +12 -9
- package/features/DisableModel/handlers/BlockModelActionOnModelBeforeUpdate.js.map +1 -1
- package/features/DisableModel/index.js +0 -2
- package/graphql/deleteModel/cancelDeleteModel.js +45 -55
- package/graphql/deleteModel/cancelDeleteModel.js.map +1 -1
- package/graphql/deleteModel/crud.js +52 -61
- package/graphql/deleteModel/crud.js.map +1 -1
- package/graphql/deleteModel/fullyDeleteModel.js +44 -56
- package/graphql/deleteModel/fullyDeleteModel.js.map +1 -1
- package/graphql/deleteModel/getDeleteModelProgress.js +42 -54
- package/graphql/deleteModel/getDeleteModelProgress.js.map +1 -1
- package/graphql/deleteModel/index.js +78 -101
- package/graphql/deleteModel/index.js.map +1 -1
- package/graphql/deleteModel/status.js +13 -12
- package/graphql/deleteModel/status.js.map +1 -1
- package/helpers/confirmation.js +6 -12
- package/helpers/confirmation.js.map +1 -1
- package/helpers/store.js +9 -14
- package/helpers/store.js.map +1 -1
- package/index.js +15 -8
- package/index.js.map +1 -1
- package/package.json +21 -21
- package/types.js +0 -3
- package/features/DisableModel/index.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,72 +1,63 @@
|
|
|
1
|
-
import { createCacheKey } from "@webiny/api-headless-cms/utils/index.js";
|
|
2
|
-
import { createMemoryCache } from "@webiny/api-headless-cms/utils/index.js";
|
|
1
|
+
import { createCacheKey, createMemoryCache } from "@webiny/api-headless-cms/utils/index.js";
|
|
3
2
|
import { ContextPlugin } from "@webiny/api";
|
|
4
3
|
import { DisableModelFeature } from "../../features/DisableModel/feature.js";
|
|
5
4
|
import { createStoreNamespace } from "../../helpers/store.js";
|
|
6
5
|
import { fullyDeleteModel } from "./fullyDeleteModel.js";
|
|
7
6
|
import { cancelDeleteModel } from "./cancelDeleteModel.js";
|
|
8
7
|
import { getDeleteModelProgress } from "./getDeleteModelProgress.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
const createDeleteModelCrud = ()=>{
|
|
9
|
+
const plugin = new ContextPlugin(async (context)=>{
|
|
10
|
+
const getTenant = ()=>context.tenancy.getCurrentTenant().id;
|
|
11
|
+
const cache = createMemoryCache();
|
|
12
|
+
context.cms.listModelsBeingDeleted = async ()=>{
|
|
13
|
+
const tenant = getTenant();
|
|
14
|
+
const cacheKey = createCacheKey({
|
|
15
|
+
tenant: getTenant(),
|
|
16
|
+
type: "deleteModel"
|
|
17
|
+
});
|
|
18
|
+
const result = await cache.getOrSet(cacheKey, async ()=>{
|
|
19
|
+
const beginsWith = createStoreNamespace({
|
|
20
|
+
tenant
|
|
21
|
+
});
|
|
22
|
+
return await context.db.store.listValues({
|
|
23
|
+
beginsWith
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
if (result.error) throw result.error;
|
|
27
|
+
if (!result.data) return [];
|
|
28
|
+
return Object.values(result.data);
|
|
29
|
+
};
|
|
30
|
+
context.cms.isModelBeingDeleted = async (modelId)=>{
|
|
31
|
+
const items = await context.cms.listModelsBeingDeleted();
|
|
32
|
+
return items.some((item)=>item.modelId === modelId);
|
|
33
|
+
};
|
|
34
|
+
context.cms.fullyDeleteModel = async (modelId)=>{
|
|
35
|
+
const result = await fullyDeleteModel({
|
|
36
|
+
context,
|
|
37
|
+
modelId
|
|
38
|
+
});
|
|
39
|
+
cache.clear();
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
context.cms.cancelFullyDeleteModel = async (modelId)=>{
|
|
43
|
+
const result = await cancelDeleteModel({
|
|
44
|
+
context,
|
|
45
|
+
modelId
|
|
46
|
+
});
|
|
47
|
+
cache.clear();
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
context.cms.getDeleteModelProgress = async (modelId)=>await getDeleteModelProgress({
|
|
51
|
+
context,
|
|
52
|
+
modelId
|
|
53
|
+
});
|
|
54
|
+
DisableModelFeature.register(context.container, {
|
|
55
|
+
isModelBeingDeleted: context.cms.isModelBeingDeleted
|
|
24
56
|
});
|
|
25
|
-
return await context.db.store.listValues({
|
|
26
|
-
beginsWith
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
if (result.error) {
|
|
30
|
-
throw result.error;
|
|
31
|
-
} else if (!result.data) {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
return Object.values(result.data);
|
|
35
|
-
};
|
|
36
|
-
context.cms.isModelBeingDeleted = async modelId => {
|
|
37
|
-
const items = await context.cms.listModelsBeingDeleted();
|
|
38
|
-
return items.some(item => item.modelId === modelId);
|
|
39
|
-
};
|
|
40
|
-
context.cms.fullyDeleteModel = async modelId => {
|
|
41
|
-
const result = await fullyDeleteModel({
|
|
42
|
-
context,
|
|
43
|
-
modelId
|
|
44
|
-
});
|
|
45
|
-
cache.clear();
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
context.cms.cancelFullyDeleteModel = async modelId => {
|
|
49
|
-
const result = await cancelDeleteModel({
|
|
50
|
-
context,
|
|
51
|
-
modelId
|
|
52
|
-
});
|
|
53
|
-
cache.clear();
|
|
54
|
-
return result;
|
|
55
|
-
};
|
|
56
|
-
context.cms.getDeleteModelProgress = async modelId => {
|
|
57
|
-
return await getDeleteModelProgress({
|
|
58
|
-
context,
|
|
59
|
-
modelId
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// Register feature
|
|
64
|
-
DisableModelFeature.register(context.container, {
|
|
65
|
-
isModelBeingDeleted: context.cms.isModelBeingDeleted
|
|
66
57
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return plugin;
|
|
58
|
+
plugin.name = "headlessCms.context.cms.fullyDeleteModel";
|
|
59
|
+
return plugin;
|
|
70
60
|
};
|
|
61
|
+
export { createDeleteModelCrud };
|
|
71
62
|
|
|
72
63
|
//# sourceMappingURL=crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/deleteModel/crud.js","sources":["../../../src/graphql/deleteModel/crud.ts"],"sourcesContent":["import type { HcmsTasksContext } from \"~/types.js\";\nimport { createCacheKey } from \"@webiny/api-headless-cms/utils/index.js\";\nimport { createMemoryCache } from \"@webiny/api-headless-cms/utils/index.js\";\nimport type { IStoreValue } from \"~/features/DeleteModelTask/types.js\";\nimport type { ListStoreKeysResult } from \"~/features/DeleteModelTask/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { DisableModelFeature } from \"~/features/DisableModel/feature.js\";\nimport { createStoreNamespace } from \"~/helpers/store.js\";\nimport { fullyDeleteModel } from \"~/graphql/deleteModel/fullyDeleteModel.js\";\nimport { cancelDeleteModel } from \"~/graphql/deleteModel/cancelDeleteModel.js\";\nimport { getDeleteModelProgress } from \"~/graphql/deleteModel/getDeleteModelProgress.js\";\n\nexport const createDeleteModelCrud = () => {\n const plugin = new ContextPlugin<HcmsTasksContext>(async context => {\n const getTenant = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n const cache = createMemoryCache<ListStoreKeysResult>();\n\n context.cms.listModelsBeingDeleted = async () => {\n const tenant = getTenant();\n const cacheKey = createCacheKey({\n tenant: getTenant(),\n type: \"deleteModel\"\n });\n\n const result = await cache.getOrSet(cacheKey, async () => {\n const beginsWith = createStoreNamespace({\n tenant\n });\n return await context.db.store.listValues<GenericRecord<string, IStoreValue>>({\n beginsWith\n });\n });\n\n if (result.error) {\n throw result.error;\n } else if (!result.data) {\n return [];\n }\n return Object.values(result.data);\n };\n\n context.cms.isModelBeingDeleted = async (modelId: string) => {\n const items = await context.cms.listModelsBeingDeleted();\n return items.some(item => item.modelId === modelId);\n };\n context.cms.fullyDeleteModel = async (modelId: string) => {\n const result = await fullyDeleteModel({\n context,\n modelId\n });\n cache.clear();\n return result;\n };\n\n context.cms.cancelFullyDeleteModel = async (modelId: string) => {\n const result = await cancelDeleteModel({\n context,\n modelId\n });\n cache.clear();\n return result;\n };\n\n context.cms.getDeleteModelProgress = async (modelId: string) => {\n return await getDeleteModelProgress({\n context,\n modelId\n });\n };\n\n // Register feature\n DisableModelFeature.register(context.container, {\n isModelBeingDeleted: context.cms.isModelBeingDeleted\n });\n });\n\n plugin.name = \"headlessCms.context.cms.fullyDeleteModel\";\n\n return plugin;\n};\n"],"names":["createDeleteModelCrud","plugin","ContextPlugin","context","getTenant","cache","createMemoryCache","tenant","cacheKey","createCacheKey","result","beginsWith","createStoreNamespace","Object","modelId","items","item","fullyDeleteModel","cancelDeleteModel","getDeleteModelProgress","DisableModelFeature"],"mappings":";;;;;;;AAaO,MAAMA,wBAAwB;IACjC,MAAMC,SAAS,IAAIC,cAAgC,OAAMC;QACrD,MAAMC,YAAY,IACPD,QAAQ,OAAO,CAAC,gBAAgB,GAAG,EAAE;QAGhD,MAAME,QAAQC;QAEdH,QAAQ,GAAG,CAAC,sBAAsB,GAAG;YACjC,MAAMI,SAASH;YACf,MAAMI,WAAWC,eAAe;gBAC5B,QAAQL;gBACR,MAAM;YACV;YAEA,MAAMM,SAAS,MAAML,MAAM,QAAQ,CAACG,UAAU;gBAC1C,MAAMG,aAAaC,qBAAqB;oBACpCL;gBACJ;gBACA,OAAO,MAAMJ,QAAQ,EAAE,CAAC,KAAK,CAAC,UAAU,CAAqC;oBACzEQ;gBACJ;YACJ;YAEA,IAAID,OAAO,KAAK,EACZ,MAAMA,OAAO,KAAK;YACf,IAAI,CAACA,OAAO,IAAI,EACnB,OAAO,EAAE;YAEb,OAAOG,OAAO,MAAM,CAACH,OAAO,IAAI;QACpC;QAEAP,QAAQ,GAAG,CAAC,mBAAmB,GAAG,OAAOW;YACrC,MAAMC,QAAQ,MAAMZ,QAAQ,GAAG,CAAC,sBAAsB;YACtD,OAAOY,MAAM,IAAI,CAACC,CAAAA,OAAQA,KAAK,OAAO,KAAKF;QAC/C;QACAX,QAAQ,GAAG,CAAC,gBAAgB,GAAG,OAAOW;YAClC,MAAMJ,SAAS,MAAMO,iBAAiB;gBAClCd;gBACAW;YACJ;YACAT,MAAM,KAAK;YACX,OAAOK;QACX;QAEAP,QAAQ,GAAG,CAAC,sBAAsB,GAAG,OAAOW;YACxC,MAAMJ,SAAS,MAAMQ,kBAAkB;gBACnCf;gBACAW;YACJ;YACAT,MAAM,KAAK;YACX,OAAOK;QACX;QAEAP,QAAQ,GAAG,CAAC,sBAAsB,GAAG,OAAOW,UACjC,MAAMK,uBAAuB;gBAChChB;gBACAW;YACJ;QAIJM,oBAAoB,QAAQ,CAACjB,QAAQ,SAAS,EAAE;YAC5C,qBAAqBA,QAAQ,GAAG,CAAC,mBAAmB;QACxD;IACJ;IAEAF,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
|
@@ -2,62 +2,50 @@ import { createStoreKey, createStoreValue } from "../../helpers/store.js";
|
|
|
2
2
|
import { DELETE_MODEL_TASK } from "../../constants.js";
|
|
3
3
|
import { getStatus } from "./status.js";
|
|
4
4
|
import { NotAuthorizedError } from "@webiny/api-headless-cms/utils/errors.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
context
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
identity: {
|
|
49
|
-
id: identity.id,
|
|
50
|
-
type: identity.type,
|
|
51
|
-
displayName: identity.displayName
|
|
52
|
-
},
|
|
53
|
-
task: task.id
|
|
54
|
-
}));
|
|
55
|
-
return {
|
|
56
|
-
id: task.id,
|
|
57
|
-
status: getStatus(task.taskStatus),
|
|
58
|
-
total: 0,
|
|
59
|
-
deleted: 0
|
|
60
|
-
};
|
|
5
|
+
const fullyDeleteModel = async (params)=>{
|
|
6
|
+
const { context, modelId } = params;
|
|
7
|
+
const model = await context.cms.getModel(modelId);
|
|
8
|
+
if (model.isPrivate) throw new Error("Cannot delete private model.");
|
|
9
|
+
const canAccessModel = await context.cms.accessControl.canAccessModel({
|
|
10
|
+
model,
|
|
11
|
+
rwd: "d"
|
|
12
|
+
});
|
|
13
|
+
if (!canAccessModel) throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
|
|
14
|
+
const canAccessEntry = await context.cms.accessControl.canAccessEntry({
|
|
15
|
+
model,
|
|
16
|
+
rwd: "w"
|
|
17
|
+
});
|
|
18
|
+
if (!canAccessEntry) throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
|
|
19
|
+
if (!model) throw new Error(`Model "${modelId}" not found.`);
|
|
20
|
+
const storeKey = createStoreKey(model);
|
|
21
|
+
const result = await context.db.store.getValue(storeKey);
|
|
22
|
+
const taskId = result.data?.task;
|
|
23
|
+
if (taskId) throw new Error(`Model "${modelId}" is already getting deleted. Task id: ${taskId}.`);
|
|
24
|
+
const triggerResult = await context.tasks.trigger({
|
|
25
|
+
input: {
|
|
26
|
+
modelId
|
|
27
|
+
},
|
|
28
|
+
definition: DELETE_MODEL_TASK,
|
|
29
|
+
name: `Fully delete model: ${modelId}`
|
|
30
|
+
});
|
|
31
|
+
const task = triggerResult.value;
|
|
32
|
+
const identity = context.security.getIdentity();
|
|
33
|
+
await context.db.store.storeValue(storeKey, createStoreValue({
|
|
34
|
+
...model,
|
|
35
|
+
identity: {
|
|
36
|
+
id: identity.id,
|
|
37
|
+
type: identity.type,
|
|
38
|
+
displayName: identity.displayName
|
|
39
|
+
},
|
|
40
|
+
task: task.id
|
|
41
|
+
}));
|
|
42
|
+
return {
|
|
43
|
+
id: task.id,
|
|
44
|
+
status: getStatus(task.taskStatus),
|
|
45
|
+
total: 0,
|
|
46
|
+
deleted: 0
|
|
47
|
+
};
|
|
61
48
|
};
|
|
49
|
+
export { fullyDeleteModel };
|
|
62
50
|
|
|
63
51
|
//# sourceMappingURL=fullyDeleteModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/deleteModel/fullyDeleteModel.js","sources":["../../../src/graphql/deleteModel/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"],"names":["fullyDeleteModel","params","context","modelId","model","Error","canAccessModel","NotAuthorizedError","canAccessEntry","storeKey","createStoreKey","result","taskId","triggerResult","DELETE_MODEL_TASK","task","identity","createStoreValue","getStatus"],"mappings":";;;;AAgBO,MAAMA,mBAAmB,OAC5BC;IAEA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;IAE7B,MAAMG,QAAQ,MAAMF,QAAQ,GAAG,CAAC,QAAQ,CAACC;IAEzC,IAAIC,MAAM,SAAS,EACf,MAAM,IAAIC,MAAM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;QACP,SAAS;IACb;AACJ"}
|
|
@@ -4,63 +4,51 @@ import { createStoreKey } from "../../helpers/store.js";
|
|
|
4
4
|
import { DELETE_MODEL_TASK } from "../../constants.js";
|
|
5
5
|
import { getStatus } from "./status.js";
|
|
6
6
|
import { NotAuthorizedError } from "@webiny/api-headless-cms/utils/errors.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const getDeleteModelProgress = async (params)=>{
|
|
8
|
+
const { context, modelId } = params;
|
|
9
|
+
let model;
|
|
10
|
+
try {
|
|
11
|
+
model = await context.cms.getModel(modelId);
|
|
12
|
+
} catch (ex) {
|
|
13
|
+
if (ex instanceof NotFoundError === false) throw ex;
|
|
14
|
+
throw new WebinyError({
|
|
15
|
+
message: "Model not found. It must have been deleted already.",
|
|
16
|
+
code: "MODEL_ALREADY_DELETED_FOUND",
|
|
17
|
+
data: {
|
|
18
|
+
model: modelId
|
|
19
|
+
}
|
|
20
|
+
});
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
data: {
|
|
23
|
-
model: modelId
|
|
24
|
-
}
|
|
22
|
+
const canAccessModel = await context.cms.accessControl.canAccessModel({
|
|
23
|
+
model,
|
|
24
|
+
rwd: "d"
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
if (!canAccessModel) {
|
|
32
|
-
throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
|
|
33
|
-
}
|
|
34
|
-
const canAccessEntry = await context.cms.accessControl.canAccessEntry({
|
|
35
|
-
model,
|
|
36
|
-
rwd: "w"
|
|
37
|
-
});
|
|
38
|
-
if (!canAccessEntry) {
|
|
39
|
-
throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
|
|
40
|
-
}
|
|
41
|
-
const storeKey = createStoreKey(model);
|
|
42
|
-
const result = await context.db.store.getValue(storeKey);
|
|
43
|
-
const taskId = result.data?.task;
|
|
44
|
-
if (!taskId) {
|
|
45
|
-
throw new Error(`Model "${modelId}" is not being deleted.`);
|
|
46
|
-
}
|
|
47
|
-
const task = await context.tasks.getTask(taskId);
|
|
48
|
-
if (task?.definitionId !== DELETE_MODEL_TASK) {
|
|
49
|
-
throw new WebinyError({
|
|
50
|
-
message: `The task which is deleting a model cannot be found.`,
|
|
51
|
-
code: "DELETE_MODEL_TASK_NOT_FOUND",
|
|
52
|
-
data: {
|
|
53
|
-
model: model.modelId,
|
|
54
|
-
task: taskId
|
|
55
|
-
}
|
|
26
|
+
if (!canAccessModel) throw new NotAuthorizedError(`Not allowed to access content model "${model.name}".`);
|
|
27
|
+
const canAccessEntry = await context.cms.accessControl.canAccessEntry({
|
|
28
|
+
model,
|
|
29
|
+
rwd: "w"
|
|
56
30
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
31
|
+
if (!canAccessEntry) throw new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`);
|
|
32
|
+
const storeKey = createStoreKey(model);
|
|
33
|
+
const result = await context.db.store.getValue(storeKey);
|
|
34
|
+
const taskId = result.data?.task;
|
|
35
|
+
if (!taskId) throw new Error(`Model "${modelId}" is not being deleted.`);
|
|
36
|
+
const task = await context.tasks.getTask(taskId);
|
|
37
|
+
if (task?.definitionId !== DELETE_MODEL_TASK) throw new WebinyError({
|
|
38
|
+
message: "The task which is deleting a model cannot be found.",
|
|
39
|
+
code: "DELETE_MODEL_TASK_NOT_FOUND",
|
|
40
|
+
data: {
|
|
41
|
+
model: model.modelId,
|
|
42
|
+
task: taskId
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
id: task.id,
|
|
47
|
+
status: getStatus(task.taskStatus),
|
|
48
|
+
total: task.output?.total || 0,
|
|
49
|
+
deleted: task.output?.deleted || 0
|
|
50
|
+
};
|
|
64
51
|
};
|
|
52
|
+
export { getDeleteModelProgress };
|
|
65
53
|
|
|
66
54
|
//# sourceMappingURL=getDeleteModelProgress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/deleteModel/getDeleteModelProgress.js","sources":["../../../src/graphql/deleteModel/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"],"names":["getDeleteModelProgress","params","context","modelId","model","ex","NotFoundError","WebinyError","canAccessModel","NotAuthorizedError","canAccessEntry","storeKey","createStoreKey","result","taskId","Error","task","DELETE_MODEL_TASK","getStatus"],"mappings":";;;;;;AAoBO,MAAMA,yBAAyB,OAClCC;IAEA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;IAE7B,IAAIG;IACJ,IAAI;QACAA,QAAQ,MAAMF,QAAQ,GAAG,CAAC,QAAQ,CAACC;IACvC,EAAE,OAAOE,IAAI;QACT,IAAIA,cAAcC,kBAAkB,OAChC,MAAMD;QAEV,MAAM,IAAIE,YAAY;YAClB,SAAS;YACT,MAAM;YACN,MAAM;gBACF,OAAOJ;YACX;QACJ;IACJ;IAEA,MAAMK,iBAAiB,MAAMN,QAAQ,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC;QAAEE;QAAO,KAAK;IAAI;IACxF,IAAI,CAACI,gBACD,MAAM,IAAIC,mBAAmB,CAAC,qCAAqC,EAAEL,MAAM,IAAI,CAAC,EAAE,CAAC;IAGvF,MAAMM,iBAAiB,MAAMR,QAAQ,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC;QAAEE;QA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