@webiny/api-headless-cms 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.da99e0b846
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/context.js +47 -43
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +3 -0
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +5 -2
- package/crud/contentEntry.crud.js +848 -830
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +39 -76
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -5
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +31 -3
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +24 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +58 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +42 -0
- package/crud/contentModel/fields/descriptionField.js.map +1 -0
- package/crud/contentModel/fields/imageField.d.ts +2 -0
- package/crud/contentModel/fields/imageField.js +46 -0
- package/crud/contentModel/fields/imageField.js.map +1 -0
- package/crud/contentModel/fields/titleField.d.ts +2 -0
- package/crud/contentModel/fields/titleField.js +58 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +26 -0
- package/crud/contentModel/validate/endingAllowed.js.map +1 -0
- package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
- package/crud/contentModel/validate/modelId.d.ts +11 -0
- package/crud/contentModel/validate/modelId.js +36 -0
- package/crud/contentModel/validate/modelId.js.map +1 -0
- package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
- package/crud/contentModel/validate/pluralApiName.js +24 -0
- package/crud/contentModel/validate/pluralApiName.js.map +1 -0
- package/crud/contentModel/validate/singularApiName.d.ts +7 -0
- package/crud/contentModel/validate/singularApiName.js +24 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +19 -57
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +136 -62
- package/crud/contentModel/validation.js +61 -13
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +346 -285
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup.crud.js +170 -142
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +1 -1
- package/crud/settings.crud.js +5 -10
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +0 -60
- package/crud/system.crud.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +2 -3
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +6 -145
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/schema/baseContentSchema.js +1 -7
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +90 -53
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +7 -7
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +23 -4
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +33 -17
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +55 -49
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +4 -8
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +24 -22
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +12 -12
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +0 -16
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +12 -4
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/object.js +21 -2
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +42 -14
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +25 -2
- package/index.js.map +1 -1
- package/package.json +22 -23
- package/plugins/CmsModelPlugin.d.ts +19 -3
- package/plugins/CmsModelPlugin.js +28 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +11 -0
- package/plugins/index.js.map +1 -1
- package/types.d.ts +118 -66
- package/types.js +1 -1
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +26 -3
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +3 -0
- package/upgrades/index.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +21 -18
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +7 -5
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +2 -10
- package/utils/createTypeName.js.map +1 -1
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +17 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +17 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +29 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/ownership.d.ts +3 -3
- package/utils/ownership.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +8 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +4 -0
- package/utils/renderInputFields.js.map +1 -1
|
@@ -6,22 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createContentEntryCrud = exports.STATUS_UNPUBLISHED = exports.STATUS_PUBLISHED = exports.STATUS_DRAFT = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
9
10
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
11
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
12
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
11
13
|
var _entryDataValidation = require("./contentEntry/entryDataValidation");
|
|
12
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
14
|
var _pubsub = require("@webiny/pubsub");
|
|
14
15
|
var _beforeCreate = require("./contentEntry/beforeCreate");
|
|
15
16
|
var _beforeUpdate = require("./contentEntry/beforeUpdate");
|
|
16
17
|
var _utils = require("@webiny/utils");
|
|
17
18
|
var _afterDelete = require("./contentEntry/afterDelete");
|
|
18
19
|
var _referenceFieldsMapping = require("./contentEntry/referenceFieldsMapping");
|
|
19
|
-
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
20
20
|
var _permissions = require("../utils/permissions");
|
|
21
21
|
var _access = require("../utils/access");
|
|
22
22
|
var _ownership = require("../utils/ownership");
|
|
23
23
|
var _entryStorage = require("../utils/entryStorage");
|
|
24
|
-
var _valueKeyStorageConverter = require("../utils/converters/valueKeyStorageConverter");
|
|
25
24
|
var _searchableFields = require("./contentEntry/searchableFields");
|
|
26
25
|
/**
|
|
27
26
|
* Package mdbid does not have types.
|
|
@@ -131,19 +130,13 @@ const mapAndCleanUpdatedInputData = (model, input) => {
|
|
|
131
130
|
*/
|
|
132
131
|
const createEntryMeta = (input, original) => {
|
|
133
132
|
const meta = (0, _merge.default)(original || {}, input || {});
|
|
134
|
-
|
|
135
|
-
if (meta[key] !== undefined || meta[key] !== null) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
delete meta[key];
|
|
139
|
-
}
|
|
140
|
-
return meta;
|
|
133
|
+
return (0, _utils.removeUndefinedValues)((0, _utils.removeNullValues)(meta));
|
|
141
134
|
};
|
|
142
135
|
const createEntryId = input => {
|
|
143
136
|
let entryId = (0, _mdbid.default)();
|
|
144
137
|
if (input.id) {
|
|
145
138
|
if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9\-]+)([a-zA-Z0-9])$/) === null) {
|
|
146
|
-
throw new _error.default("The provided ID is not valid. It must be a string which can A-Z, a-z, 0-9, - and it cannot start or end with a -.", "INVALID_ID", {
|
|
139
|
+
throw new _error.default("The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.", "INVALID_ID", {
|
|
147
140
|
id: input.id
|
|
148
141
|
});
|
|
149
142
|
}
|
|
@@ -151,7 +144,7 @@ const createEntryId = input => {
|
|
|
151
144
|
}
|
|
152
145
|
const version = 1;
|
|
153
146
|
return {
|
|
154
|
-
entryId
|
|
147
|
+
entryId,
|
|
155
148
|
version,
|
|
156
149
|
id: (0, _utils.createIdentifier)({
|
|
157
150
|
id: entryId,
|
|
@@ -187,11 +180,17 @@ const createContentEntryCrud = params => {
|
|
|
187
180
|
storageOperations,
|
|
188
181
|
context,
|
|
189
182
|
getIdentity,
|
|
190
|
-
getTenant
|
|
183
|
+
getTenant,
|
|
184
|
+
getLocale
|
|
191
185
|
} = params;
|
|
192
|
-
const {
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
const getCreatedBy = () => {
|
|
187
|
+
const identity = getIdentity();
|
|
188
|
+
return {
|
|
189
|
+
id: identity.id,
|
|
190
|
+
displayName: identity.displayName,
|
|
191
|
+
type: identity.type
|
|
192
|
+
};
|
|
193
|
+
};
|
|
195
194
|
|
|
196
195
|
/**
|
|
197
196
|
* Create
|
|
@@ -242,15 +241,21 @@ const createContentEntryCrud = params => {
|
|
|
242
241
|
const onEntryAfterDelete = (0, _pubsub.createTopic)("cms.onEntryAfterDelete");
|
|
243
242
|
const onEntryDeleteError = (0, _pubsub.createTopic)("cms.onEntryDeleteError");
|
|
244
243
|
|
|
245
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Delete revision
|
|
246
|
+
*/
|
|
246
247
|
const onEntryRevisionBeforeDelete = (0, _pubsub.createTopic)("cms.onEntryRevisionBeforeDelete");
|
|
247
248
|
const onEntryRevisionAfterDelete = (0, _pubsub.createTopic)("cms.onEntryRevisionAfterDelete");
|
|
248
249
|
const onEntryRevisionDeleteError = (0, _pubsub.createTopic)("cms.onEntryRevisionDeleteError");
|
|
249
250
|
|
|
250
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Get entry
|
|
253
|
+
*/
|
|
251
254
|
const onEntryBeforeGet = (0, _pubsub.createTopic)("cms.onEntryBeforeGet");
|
|
252
255
|
|
|
253
|
-
|
|
256
|
+
/**
|
|
257
|
+
* List entries
|
|
258
|
+
*/
|
|
254
259
|
const onEntryBeforeList = (0, _pubsub.createTopic)("cms.onEntryBeforeList");
|
|
255
260
|
|
|
256
261
|
/**
|
|
@@ -275,189 +280,847 @@ const createContentEntryCrud = params => {
|
|
|
275
280
|
/**
|
|
276
281
|
* A helper to delete the entire entry.
|
|
277
282
|
*/
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
entry
|
|
282
|
-
} = params;
|
|
283
|
-
try {
|
|
284
|
-
await onEntryBeforeDelete.publish({
|
|
285
|
-
entry,
|
|
286
|
-
model
|
|
287
|
-
});
|
|
288
|
-
await storageOperations.entries.delete(model, {
|
|
289
|
-
entry
|
|
290
|
-
});
|
|
291
|
-
await onEntryAfterDelete.publish({
|
|
292
|
-
entry,
|
|
293
|
-
model
|
|
294
|
-
});
|
|
295
|
-
} catch (ex) {
|
|
296
|
-
await onEntryDeleteError.publish({
|
|
297
|
-
entry,
|
|
283
|
+
const deleteEntryHelper = async params => {
|
|
284
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntry", async () => {
|
|
285
|
+
const {
|
|
298
286
|
model,
|
|
299
|
-
error: ex
|
|
300
|
-
});
|
|
301
|
-
throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
|
|
302
287
|
entry
|
|
303
|
-
}
|
|
304
|
-
|
|
288
|
+
} = params;
|
|
289
|
+
try {
|
|
290
|
+
await onEntryBeforeDelete.publish({
|
|
291
|
+
entry,
|
|
292
|
+
model
|
|
293
|
+
});
|
|
294
|
+
await storageOperations.entries.delete(model, {
|
|
295
|
+
entry
|
|
296
|
+
});
|
|
297
|
+
await onEntryAfterDelete.publish({
|
|
298
|
+
entry,
|
|
299
|
+
model
|
|
300
|
+
});
|
|
301
|
+
} catch (ex) {
|
|
302
|
+
await onEntryDeleteError.publish({
|
|
303
|
+
entry,
|
|
304
|
+
model,
|
|
305
|
+
error: ex
|
|
306
|
+
});
|
|
307
|
+
throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
|
|
308
|
+
entry
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
});
|
|
305
312
|
};
|
|
306
313
|
/**
|
|
307
314
|
* A helper to get entries by revision IDs
|
|
308
315
|
*/
|
|
309
|
-
const getEntriesByIds = async (
|
|
316
|
+
const getEntriesByIds = async (model, ids) => {
|
|
317
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntriesByIds", async () => {
|
|
318
|
+
const permission = await checkEntryPermissions({
|
|
319
|
+
rwd: "r"
|
|
320
|
+
});
|
|
321
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
322
|
+
const entries = await storageOperations.entries.getByIds(model, {
|
|
323
|
+
ids
|
|
324
|
+
});
|
|
325
|
+
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
const getEntryById = async (model, id) => {
|
|
329
|
+
const where = {
|
|
330
|
+
id
|
|
331
|
+
};
|
|
332
|
+
await onEntryBeforeGet.publish({
|
|
333
|
+
where,
|
|
334
|
+
model
|
|
335
|
+
});
|
|
336
|
+
const [entry] = await getEntriesByIds(model, [id]);
|
|
337
|
+
if (!entry) {
|
|
338
|
+
throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
|
|
339
|
+
}
|
|
340
|
+
return entry;
|
|
341
|
+
};
|
|
342
|
+
const getPublishedEntriesByIds = async (model, ids) => {
|
|
310
343
|
const permission = await checkEntryPermissions({
|
|
311
344
|
rwd: "r"
|
|
312
345
|
});
|
|
313
|
-
await (0, _access.checkModelAccess)(context,
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
346
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
347
|
+
const entries = await storageOperations.entries.getPublishedByIds(model, {
|
|
348
|
+
ids
|
|
349
|
+
});
|
|
350
|
+
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
351
|
+
};
|
|
352
|
+
const getLatestEntriesByIds = async (model, ids) => {
|
|
353
|
+
const permission = await checkEntryPermissions({
|
|
354
|
+
rwd: "r"
|
|
317
355
|
});
|
|
318
|
-
|
|
356
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
357
|
+
const entries = await storageOperations.entries.getLatestByIds(model, {
|
|
319
358
|
ids
|
|
320
359
|
});
|
|
321
360
|
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
322
361
|
};
|
|
323
|
-
|
|
362
|
+
const getEntry = async (model, params) => {
|
|
363
|
+
await checkEntryPermissions({
|
|
364
|
+
rwd: "r"
|
|
365
|
+
});
|
|
366
|
+
const {
|
|
367
|
+
where,
|
|
368
|
+
sort
|
|
369
|
+
} = params;
|
|
370
|
+
await onEntryBeforeGet.publish({
|
|
371
|
+
where,
|
|
372
|
+
model
|
|
373
|
+
});
|
|
374
|
+
const [items] = await listEntries(model, {
|
|
375
|
+
where,
|
|
376
|
+
sort,
|
|
377
|
+
limit: 1
|
|
378
|
+
});
|
|
379
|
+
const item = items.shift();
|
|
380
|
+
if (!item) {
|
|
381
|
+
throw new _handlerGraphql.NotFoundError(`Entry not found!`);
|
|
382
|
+
}
|
|
383
|
+
return item;
|
|
384
|
+
};
|
|
385
|
+
const getEntryRevisions = async (model, entryId) => {
|
|
386
|
+
return storageOperations.entries.getRevisions(model, {
|
|
387
|
+
id: entryId
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
const listEntries = async (model, params) => {
|
|
391
|
+
const permission = await checkEntryPermissions({
|
|
392
|
+
rwd: "r"
|
|
393
|
+
});
|
|
394
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
395
|
+
const {
|
|
396
|
+
where: initialWhere,
|
|
397
|
+
limit: initialLimit
|
|
398
|
+
} = params;
|
|
399
|
+
const limit = initialLimit && initialLimit > 0 ? initialLimit : 50;
|
|
324
400
|
/**
|
|
325
|
-
*
|
|
401
|
+
* We always assign tenant and locale because we do not allow one model to have content through multiple tenants.
|
|
326
402
|
*/
|
|
327
|
-
|
|
328
|
-
onAfterEntryCreate: onEntryAfterCreate,
|
|
329
|
-
onBeforeEntryCreateRevision: onEntryBeforeCreateRevision,
|
|
330
|
-
onAfterEntryCreateRevision: onEntryRevisionAfterCreate,
|
|
331
|
-
onBeforeEntryUpdate: onEntryBeforeUpdate,
|
|
332
|
-
onAfterEntryUpdate: onEntryAfterUpdate,
|
|
333
|
-
onBeforeEntryDelete: onEntryBeforeDelete,
|
|
334
|
-
onAfterEntryDelete: onEntryAfterDelete,
|
|
335
|
-
onBeforeEntryDeleteRevision: onEntryRevisionBeforeDelete,
|
|
336
|
-
onAfterEntryDeleteRevision: onEntryRevisionAfterDelete,
|
|
337
|
-
onBeforeEntryPublish: onEntryBeforePublish,
|
|
338
|
-
onAfterEntryPublish: onEntryAfterPublish,
|
|
339
|
-
onBeforeEntryUnpublish: onEntryBeforeUnpublish,
|
|
340
|
-
onAfterEntryUnpublish: onEntryAfterUnpublish,
|
|
341
|
-
onBeforeEntryGet: onEntryBeforeGet,
|
|
342
|
-
onBeforeEntryList: onEntryBeforeList,
|
|
403
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
343
404
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
* Create
|
|
405
|
+
* Possibly only get records which are owned by current user.
|
|
406
|
+
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
347
407
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
408
|
+
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
409
|
+
if (ownedBy !== undefined) {
|
|
410
|
+
where.ownedBy = ownedBy;
|
|
411
|
+
}
|
|
351
412
|
/**
|
|
352
|
-
*
|
|
413
|
+
* Where must contain either latest or published keys.
|
|
414
|
+
* We cannot list entries without one of those
|
|
353
415
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
416
|
+
if (where.latest && where.published) {
|
|
417
|
+
throw new _error.default("Cannot list entries that are both published and latest.", "LIST_ENTRIES_ERROR", {
|
|
418
|
+
where
|
|
419
|
+
});
|
|
420
|
+
} else if (!where.latest && !where.published) {
|
|
421
|
+
throw new _error.default("Cannot list entries if we do not have latest or published defined.", "LIST_ENTRIES_ERROR", {
|
|
422
|
+
where
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
const fields = (0, _searchableFields.getSearchableFields)({
|
|
426
|
+
fields: model.fields,
|
|
427
|
+
plugins: context.plugins,
|
|
428
|
+
input: params.fields || []
|
|
429
|
+
});
|
|
430
|
+
try {
|
|
431
|
+
await onEntryBeforeList.publish({
|
|
432
|
+
where,
|
|
433
|
+
model
|
|
434
|
+
});
|
|
435
|
+
const {
|
|
436
|
+
hasMoreItems,
|
|
437
|
+
totalCount,
|
|
438
|
+
cursor,
|
|
439
|
+
items
|
|
440
|
+
} = await storageOperations.entries.list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
441
|
+
limit,
|
|
442
|
+
where,
|
|
443
|
+
fields
|
|
444
|
+
}));
|
|
445
|
+
const meta = {
|
|
446
|
+
hasMoreItems,
|
|
447
|
+
totalCount,
|
|
448
|
+
/**
|
|
449
|
+
* Cursor should be null if there are no more items to load.
|
|
450
|
+
* Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
|
|
451
|
+
*/
|
|
452
|
+
cursor: hasMoreItems ? cursor : null
|
|
453
|
+
};
|
|
454
|
+
return [items, meta];
|
|
455
|
+
} catch (ex) {
|
|
456
|
+
throw new _error.default("Error while fetching entries from storage.", "LIST_ENTRIES_ERROR", {
|
|
457
|
+
params,
|
|
458
|
+
error: {
|
|
459
|
+
message: ex.message,
|
|
460
|
+
code: ex.code,
|
|
461
|
+
data: ex.data
|
|
462
|
+
},
|
|
463
|
+
model,
|
|
464
|
+
fields
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
const createEntry = async (model, inputData) => {
|
|
469
|
+
await checkEntryPermissions({
|
|
470
|
+
rwd: "w"
|
|
471
|
+
});
|
|
472
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
473
|
+
|
|
357
474
|
/**
|
|
358
|
-
*
|
|
475
|
+
* Make sure we only work with fields that are defined in the model.
|
|
359
476
|
*/
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
477
|
+
const initialInput = mapAndCleanCreateInputData(model, inputData);
|
|
478
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
479
|
+
context,
|
|
480
|
+
model,
|
|
481
|
+
data: initialInput
|
|
482
|
+
});
|
|
483
|
+
const input = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
484
|
+
context,
|
|
485
|
+
model,
|
|
486
|
+
input: initialInput,
|
|
487
|
+
validateEntries: true
|
|
488
|
+
});
|
|
489
|
+
const locale = getLocale();
|
|
490
|
+
const owner = getCreatedBy();
|
|
491
|
+
const {
|
|
492
|
+
id,
|
|
493
|
+
entryId,
|
|
494
|
+
version
|
|
495
|
+
} = createEntryId(inputData);
|
|
363
496
|
/**
|
|
364
|
-
*
|
|
497
|
+
* There is a possibility that user sends an ID in the input, so we will use that one.
|
|
498
|
+
* There is no check if the ID is unique or not, that is up to the user.
|
|
365
499
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
500
|
+
const entry = {
|
|
501
|
+
webinyVersion: context.WEBINY_VERSION,
|
|
502
|
+
tenant: getTenant().id,
|
|
503
|
+
entryId,
|
|
504
|
+
id,
|
|
505
|
+
modelId: model.modelId,
|
|
506
|
+
locale: locale.code,
|
|
507
|
+
createdOn: new Date().toISOString(),
|
|
508
|
+
savedOn: new Date().toISOString(),
|
|
509
|
+
createdBy: owner,
|
|
510
|
+
ownedBy: owner,
|
|
511
|
+
modifiedBy: null,
|
|
512
|
+
version,
|
|
513
|
+
locked: false,
|
|
514
|
+
status: STATUS_DRAFT,
|
|
515
|
+
values: input
|
|
516
|
+
};
|
|
517
|
+
let storageEntry = null;
|
|
518
|
+
try {
|
|
519
|
+
await onEntryBeforeCreate.publish({
|
|
520
|
+
entry,
|
|
521
|
+
input,
|
|
522
|
+
model
|
|
523
|
+
});
|
|
524
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
525
|
+
const result = await storageOperations.entries.create(model, {
|
|
526
|
+
entry,
|
|
527
|
+
storageEntry
|
|
528
|
+
});
|
|
529
|
+
await onEntryAfterCreate.publish({
|
|
530
|
+
entry,
|
|
531
|
+
storageEntry: result,
|
|
532
|
+
model,
|
|
533
|
+
input
|
|
534
|
+
});
|
|
535
|
+
return result;
|
|
536
|
+
} catch (ex) {
|
|
537
|
+
await onEntryCreateError.publish({
|
|
538
|
+
error: ex,
|
|
539
|
+
entry,
|
|
540
|
+
model,
|
|
541
|
+
input
|
|
542
|
+
});
|
|
543
|
+
throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
|
|
544
|
+
error: ex,
|
|
545
|
+
input,
|
|
546
|
+
entry,
|
|
547
|
+
storageEntry
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
const createEntryRevisionFrom = async (model, sourceId, inputData) => {
|
|
552
|
+
const permission = await checkEntryPermissions({
|
|
553
|
+
rwd: "w"
|
|
554
|
+
});
|
|
555
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
556
|
+
|
|
369
557
|
/**
|
|
370
|
-
*
|
|
558
|
+
* Make sure we only work with fields that are defined in the model.
|
|
371
559
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
onEntryRevisionDeleteError,
|
|
560
|
+
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
561
|
+
|
|
375
562
|
/**
|
|
376
|
-
*
|
|
563
|
+
* Entries are identified by a common parent ID + Revision number.
|
|
377
564
|
*/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
565
|
+
const {
|
|
566
|
+
id: uniqueId
|
|
567
|
+
} = (0, _utils.parseIdentifier)(sourceId);
|
|
568
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
569
|
+
id: sourceId
|
|
570
|
+
});
|
|
571
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
572
|
+
id: uniqueId
|
|
573
|
+
});
|
|
574
|
+
if (!originalStorageEntry) {
|
|
575
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
|
|
576
|
+
}
|
|
577
|
+
|
|
381
578
|
/**
|
|
382
|
-
*
|
|
579
|
+
* We need to convert data from DB to its original form before using it further.
|
|
383
580
|
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
581
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
582
|
+
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
583
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
584
|
+
context,
|
|
585
|
+
model,
|
|
586
|
+
data: initialValues,
|
|
587
|
+
entry: originalEntry
|
|
588
|
+
});
|
|
589
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
590
|
+
context,
|
|
591
|
+
model,
|
|
592
|
+
input: initialValues,
|
|
593
|
+
validateEntries: false
|
|
594
|
+
});
|
|
595
|
+
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
596
|
+
const identity = getIdentity();
|
|
597
|
+
const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
|
|
598
|
+
const {
|
|
599
|
+
id,
|
|
600
|
+
version: nextVersion
|
|
601
|
+
} = increaseEntryIdVersion(latestId);
|
|
602
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
603
|
+
id,
|
|
604
|
+
version: nextVersion,
|
|
605
|
+
savedOn: new Date().toISOString(),
|
|
606
|
+
createdOn: new Date().toISOString(),
|
|
607
|
+
createdBy: {
|
|
608
|
+
id: identity.id,
|
|
609
|
+
displayName: identity.displayName,
|
|
610
|
+
type: identity.type
|
|
611
|
+
},
|
|
612
|
+
modifiedBy: null,
|
|
613
|
+
locked: false,
|
|
614
|
+
publishedOn: undefined,
|
|
615
|
+
status: STATUS_DRAFT,
|
|
616
|
+
values
|
|
617
|
+
});
|
|
618
|
+
let storageEntry = null;
|
|
619
|
+
try {
|
|
620
|
+
await onEntryBeforeCreateRevision.publish({
|
|
621
|
+
input,
|
|
622
|
+
entry,
|
|
623
|
+
original: originalEntry,
|
|
624
|
+
model
|
|
625
|
+
});
|
|
626
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
627
|
+
const result = await storageOperations.entries.createRevisionFrom(model, {
|
|
628
|
+
entry,
|
|
629
|
+
storageEntry
|
|
630
|
+
});
|
|
631
|
+
await onEntryRevisionAfterCreate.publish({
|
|
632
|
+
input,
|
|
633
|
+
entry,
|
|
634
|
+
model,
|
|
635
|
+
original: originalEntry,
|
|
636
|
+
storageEntry: result
|
|
637
|
+
});
|
|
638
|
+
return result;
|
|
639
|
+
} catch (ex) {
|
|
640
|
+
await onEntryCreateRevisionError.publish({
|
|
641
|
+
entry,
|
|
642
|
+
original: originalEntry,
|
|
643
|
+
model,
|
|
644
|
+
input,
|
|
645
|
+
error: ex
|
|
646
|
+
});
|
|
647
|
+
throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
|
|
648
|
+
error: ex,
|
|
649
|
+
entry,
|
|
650
|
+
storageEntry,
|
|
651
|
+
originalEntry,
|
|
652
|
+
originalStorageEntry
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
const updateEntry = async (model, id, inputData, metaInput) => {
|
|
657
|
+
const permission = await checkEntryPermissions({
|
|
658
|
+
rwd: "w"
|
|
659
|
+
});
|
|
660
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
661
|
+
|
|
387
662
|
/**
|
|
388
|
-
*
|
|
663
|
+
* Make sure we only work with fields that are defined in the model.
|
|
389
664
|
*/
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
onEntryUnpublishError,
|
|
393
|
-
onEntryBeforeGet,
|
|
394
|
-
onEntryBeforeList,
|
|
665
|
+
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
666
|
+
|
|
395
667
|
/**
|
|
396
|
-
*
|
|
668
|
+
* The entry we are going to update.
|
|
397
669
|
*/
|
|
398
|
-
|
|
670
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
671
|
+
id
|
|
672
|
+
});
|
|
673
|
+
if (!originalStorageEntry) {
|
|
674
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
675
|
+
}
|
|
676
|
+
if (originalStorageEntry.locked) {
|
|
677
|
+
throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
|
|
678
|
+
}
|
|
679
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
680
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
681
|
+
context,
|
|
682
|
+
model,
|
|
683
|
+
data: input,
|
|
684
|
+
entry: originalEntry
|
|
685
|
+
});
|
|
686
|
+
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
687
|
+
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
688
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
689
|
+
context,
|
|
690
|
+
model,
|
|
691
|
+
input: initialValues,
|
|
692
|
+
validateEntries: false
|
|
693
|
+
});
|
|
399
694
|
/**
|
|
400
|
-
*
|
|
695
|
+
* If users wants to remove a key from meta values, they need to send meta key with the null value.
|
|
401
696
|
*/
|
|
402
|
-
|
|
403
|
-
const where = {
|
|
404
|
-
id
|
|
405
|
-
};
|
|
406
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
407
|
-
model: initialModel,
|
|
408
|
-
plugins
|
|
409
|
-
});
|
|
410
|
-
await onEntryBeforeGet.publish({
|
|
411
|
-
where,
|
|
412
|
-
model
|
|
413
|
-
});
|
|
414
|
-
const [entry] = await getEntriesByIds(model, [id]);
|
|
415
|
-
if (!entry) {
|
|
416
|
-
throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
|
|
417
|
-
}
|
|
418
|
-
return entry;
|
|
419
|
-
},
|
|
697
|
+
const meta = createEntryMeta(metaInput, originalEntry.meta);
|
|
420
698
|
/**
|
|
421
|
-
*
|
|
699
|
+
* We always send the full entry to the hooks and storage operations update.
|
|
422
700
|
*/
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
701
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
702
|
+
savedOn: new Date().toISOString(),
|
|
703
|
+
modifiedBy: getCreatedBy(),
|
|
704
|
+
values,
|
|
705
|
+
meta,
|
|
706
|
+
status: transformEntryStatus(originalEntry.status)
|
|
707
|
+
});
|
|
708
|
+
let storageEntry = null;
|
|
709
|
+
try {
|
|
710
|
+
await onEntryBeforeUpdate.publish({
|
|
711
|
+
entry,
|
|
712
|
+
model,
|
|
713
|
+
input,
|
|
714
|
+
original: originalEntry
|
|
426
715
|
});
|
|
427
|
-
await (0,
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
716
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
717
|
+
const result = await storageOperations.entries.update(model, {
|
|
718
|
+
entry,
|
|
719
|
+
storageEntry
|
|
431
720
|
});
|
|
432
|
-
|
|
433
|
-
|
|
721
|
+
await onEntryAfterUpdate.publish({
|
|
722
|
+
entry,
|
|
723
|
+
storageEntry: result,
|
|
724
|
+
model,
|
|
725
|
+
input,
|
|
726
|
+
original: originalEntry
|
|
434
727
|
});
|
|
435
|
-
return
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
728
|
+
return result;
|
|
729
|
+
} catch (ex) {
|
|
730
|
+
await onEntryUpdateError.publish({
|
|
731
|
+
entry,
|
|
732
|
+
model,
|
|
733
|
+
input,
|
|
734
|
+
error: ex
|
|
735
|
+
});
|
|
736
|
+
throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
|
|
737
|
+
error: ex,
|
|
738
|
+
entry,
|
|
739
|
+
storageEntry,
|
|
740
|
+
originalEntry,
|
|
741
|
+
input
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
const republishEntry = async (model, id) => {
|
|
746
|
+
await checkEntryPermissions({
|
|
747
|
+
rwd: "w"
|
|
748
|
+
});
|
|
749
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
750
|
+
/**
|
|
751
|
+
* Fetch the entry from the storage.
|
|
439
752
|
*/
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
753
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
754
|
+
id
|
|
755
|
+
});
|
|
756
|
+
if (!originalStorageEntry) {
|
|
757
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" was not found!`);
|
|
758
|
+
}
|
|
759
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
760
|
+
/**
|
|
761
|
+
* We can only process published entries.
|
|
762
|
+
*/
|
|
763
|
+
if (originalEntry.status !== "published") {
|
|
764
|
+
throw new _error.default("Entry with given ID is not published!", "NOT_PUBLISHED_ERROR", {
|
|
765
|
+
id,
|
|
766
|
+
original: originalEntry
|
|
443
767
|
});
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
768
|
+
}
|
|
769
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
770
|
+
context,
|
|
771
|
+
model,
|
|
772
|
+
input: originalEntry.values,
|
|
773
|
+
validateEntries: false
|
|
774
|
+
});
|
|
775
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
776
|
+
savedOn: new Date().toISOString(),
|
|
777
|
+
webinyVersion: context.WEBINY_VERSION,
|
|
778
|
+
values
|
|
779
|
+
});
|
|
780
|
+
const storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
781
|
+
/**
|
|
782
|
+
* First we need to update existing entry.
|
|
783
|
+
*/
|
|
784
|
+
try {
|
|
785
|
+
await storageOperations.entries.update(model, {
|
|
786
|
+
entry,
|
|
787
|
+
storageEntry
|
|
448
788
|
});
|
|
449
|
-
|
|
450
|
-
|
|
789
|
+
} catch (ex) {
|
|
790
|
+
throw new _error.default("Could not update existing entry with new data while re-publishing.", "REPUBLISH_UPDATE_ERROR", {
|
|
791
|
+
entry
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Then we move onto publishing it again.
|
|
796
|
+
*/
|
|
797
|
+
try {
|
|
798
|
+
await onEntryBeforeRepublish.publish({
|
|
799
|
+
entry,
|
|
800
|
+
model
|
|
801
|
+
});
|
|
802
|
+
const result = await storageOperations.entries.publish(model, {
|
|
803
|
+
entry,
|
|
804
|
+
storageEntry
|
|
805
|
+
});
|
|
806
|
+
await onEntryAfterRepublish.publish({
|
|
807
|
+
entry,
|
|
808
|
+
model,
|
|
809
|
+
storageEntry
|
|
810
|
+
});
|
|
811
|
+
return result;
|
|
812
|
+
} catch (ex) {
|
|
813
|
+
await onEntryRepublishError.publish({
|
|
814
|
+
entry,
|
|
815
|
+
model,
|
|
816
|
+
error: ex
|
|
817
|
+
});
|
|
818
|
+
throw new _error.default("Could not publish existing entry while re-publishing.", "REPUBLISH_PUBLISH_ERROR", {
|
|
819
|
+
entry
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
const deleteEntryRevision = async (model, revisionId) => {
|
|
824
|
+
const permission = await checkEntryPermissions({
|
|
825
|
+
rwd: "d"
|
|
826
|
+
});
|
|
827
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
828
|
+
const {
|
|
829
|
+
id: entryId,
|
|
830
|
+
version
|
|
831
|
+
} = (0, _utils.parseIdentifier)(revisionId);
|
|
832
|
+
const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
|
|
833
|
+
id: revisionId
|
|
834
|
+
});
|
|
835
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
836
|
+
id: entryId
|
|
837
|
+
});
|
|
838
|
+
const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
|
|
839
|
+
entryId,
|
|
840
|
+
version: version
|
|
841
|
+
});
|
|
842
|
+
if (!storageEntryToDelete) {
|
|
843
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
|
|
844
|
+
}
|
|
845
|
+
(0, _ownership.checkOwnership)(context, permission, storageEntryToDelete);
|
|
846
|
+
const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
|
|
847
|
+
const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
|
|
848
|
+
/**
|
|
849
|
+
* If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
|
|
850
|
+
* At this point deleteRevision hooks are not fired.
|
|
851
|
+
*/
|
|
852
|
+
if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
|
|
853
|
+
return await deleteEntryHelper({
|
|
854
|
+
model,
|
|
855
|
+
entry: entryToDelete
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* If targeted record is latest entry revision, set the previous one as the new latest
|
|
860
|
+
*/
|
|
861
|
+
let entryToSetAsLatest = null;
|
|
862
|
+
let storageEntryToSetAsLatest = null;
|
|
863
|
+
if (entryToDelete.id === latestEntryRevisionId && previousStorageEntry) {
|
|
864
|
+
entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
|
|
865
|
+
storageEntryToSetAsLatest = previousStorageEntry;
|
|
866
|
+
}
|
|
867
|
+
try {
|
|
868
|
+
await onEntryRevisionBeforeDelete.publish({
|
|
869
|
+
entry: entryToDelete,
|
|
870
|
+
model
|
|
871
|
+
});
|
|
872
|
+
await storageOperations.entries.deleteRevision(model, {
|
|
873
|
+
entry: entryToDelete,
|
|
874
|
+
storageEntry: storageEntryToDelete,
|
|
875
|
+
latestEntry: entryToSetAsLatest,
|
|
876
|
+
latestStorageEntry: storageEntryToSetAsLatest
|
|
877
|
+
});
|
|
878
|
+
await onEntryRevisionAfterDelete.publish({
|
|
879
|
+
entry: entryToDelete,
|
|
880
|
+
model
|
|
881
|
+
});
|
|
882
|
+
} catch (ex) {
|
|
883
|
+
await onEntryRevisionDeleteError.publish({
|
|
884
|
+
entry: entryToDelete,
|
|
885
|
+
model,
|
|
886
|
+
error: ex
|
|
887
|
+
});
|
|
888
|
+
throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
|
|
889
|
+
error: ex,
|
|
890
|
+
entry: entryToDelete,
|
|
891
|
+
storageEntry: storageEntryToDelete,
|
|
892
|
+
latestEntry: entryToSetAsLatest,
|
|
893
|
+
latestStorageEntry: storageEntryToSetAsLatest
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
const deleteEntry = async (model, entryId) => {
|
|
898
|
+
const permission = await checkEntryPermissions({
|
|
899
|
+
rwd: "d"
|
|
900
|
+
});
|
|
901
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
902
|
+
const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
903
|
+
id: entryId
|
|
904
|
+
});
|
|
905
|
+
if (!storageEntry) {
|
|
906
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
|
|
907
|
+
}
|
|
908
|
+
(0, _ownership.checkOwnership)(context, permission, storageEntry);
|
|
909
|
+
const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
|
|
910
|
+
return await deleteEntryHelper({
|
|
911
|
+
model,
|
|
912
|
+
entry
|
|
913
|
+
});
|
|
914
|
+
};
|
|
915
|
+
const publishEntry = async (model, id) => {
|
|
916
|
+
const permission = await checkEntryPermissions({
|
|
917
|
+
pw: "p"
|
|
918
|
+
});
|
|
919
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
920
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
921
|
+
id
|
|
922
|
+
});
|
|
923
|
+
if (!originalStorageEntry) {
|
|
924
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
|
|
925
|
+
}
|
|
926
|
+
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
927
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
928
|
+
const currentDate = new Date().toISOString();
|
|
929
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
930
|
+
status: STATUS_PUBLISHED,
|
|
931
|
+
locked: true,
|
|
932
|
+
savedOn: currentDate,
|
|
933
|
+
publishedOn: currentDate
|
|
934
|
+
});
|
|
935
|
+
let storageEntry = null;
|
|
936
|
+
try {
|
|
937
|
+
await onEntryBeforePublish.publish({
|
|
938
|
+
entry,
|
|
939
|
+
model
|
|
940
|
+
});
|
|
941
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
942
|
+
const result = await storageOperations.entries.publish(model, {
|
|
943
|
+
entry,
|
|
944
|
+
storageEntry
|
|
945
|
+
});
|
|
946
|
+
await onEntryAfterPublish.publish({
|
|
947
|
+
entry,
|
|
948
|
+
storageEntry: result,
|
|
949
|
+
model
|
|
950
|
+
});
|
|
951
|
+
return result;
|
|
952
|
+
} catch (ex) {
|
|
953
|
+
await onEntryPublishError.publish({
|
|
954
|
+
entry,
|
|
955
|
+
model,
|
|
956
|
+
error: ex
|
|
957
|
+
});
|
|
958
|
+
throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
|
|
959
|
+
error: ex,
|
|
960
|
+
entry,
|
|
961
|
+
storageEntry,
|
|
962
|
+
originalEntry,
|
|
963
|
+
originalStorageEntry
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const unpublishEntry = async (model, id) => {
|
|
968
|
+
const permission = await checkEntryPermissions({
|
|
969
|
+
pw: "u"
|
|
970
|
+
});
|
|
971
|
+
const {
|
|
972
|
+
id: entryId
|
|
973
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
974
|
+
const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
|
|
975
|
+
id: entryId
|
|
976
|
+
});
|
|
977
|
+
if (!originalStorageEntry) {
|
|
978
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
979
|
+
}
|
|
980
|
+
if (originalStorageEntry.id !== id) {
|
|
981
|
+
throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
|
|
982
|
+
entry: originalStorageEntry
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
986
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
987
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
988
|
+
status: STATUS_UNPUBLISHED
|
|
989
|
+
});
|
|
990
|
+
let storageEntry = null;
|
|
991
|
+
try {
|
|
992
|
+
await onEntryBeforeUnpublish.publish({
|
|
993
|
+
entry,
|
|
994
|
+
model
|
|
995
|
+
});
|
|
996
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
997
|
+
const result = await storageOperations.entries.unpublish(model, {
|
|
998
|
+
entry,
|
|
999
|
+
storageEntry
|
|
1000
|
+
});
|
|
1001
|
+
await onEntryAfterUnpublish.publish({
|
|
1002
|
+
entry,
|
|
1003
|
+
storageEntry: result,
|
|
1004
|
+
model
|
|
1005
|
+
});
|
|
1006
|
+
return result;
|
|
1007
|
+
} catch (ex) {
|
|
1008
|
+
await onEntryUnpublishError.publish({
|
|
1009
|
+
entry,
|
|
1010
|
+
model,
|
|
1011
|
+
error: ex
|
|
1012
|
+
});
|
|
1013
|
+
throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
|
|
1014
|
+
originalEntry,
|
|
1015
|
+
originalStorageEntry,
|
|
1016
|
+
entry,
|
|
1017
|
+
storageEntry
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
return {
|
|
1022
|
+
/**
|
|
1023
|
+
* Deprecated - will be removed in 5.35.0
|
|
1024
|
+
*/
|
|
1025
|
+
onBeforeEntryCreate: onEntryBeforeCreate,
|
|
1026
|
+
onAfterEntryCreate: onEntryAfterCreate,
|
|
1027
|
+
onBeforeEntryCreateRevision: onEntryBeforeCreateRevision,
|
|
1028
|
+
onAfterEntryCreateRevision: onEntryRevisionAfterCreate,
|
|
1029
|
+
onBeforeEntryUpdate: onEntryBeforeUpdate,
|
|
1030
|
+
onAfterEntryUpdate: onEntryAfterUpdate,
|
|
1031
|
+
onBeforeEntryDelete: onEntryBeforeDelete,
|
|
1032
|
+
onAfterEntryDelete: onEntryAfterDelete,
|
|
1033
|
+
onBeforeEntryDeleteRevision: onEntryRevisionBeforeDelete,
|
|
1034
|
+
onAfterEntryDeleteRevision: onEntryRevisionAfterDelete,
|
|
1035
|
+
onBeforeEntryPublish: onEntryBeforePublish,
|
|
1036
|
+
onAfterEntryPublish: onEntryAfterPublish,
|
|
1037
|
+
onBeforeEntryUnpublish: onEntryBeforeUnpublish,
|
|
1038
|
+
onAfterEntryUnpublish: onEntryAfterUnpublish,
|
|
1039
|
+
onBeforeEntryGet: onEntryBeforeGet,
|
|
1040
|
+
onBeforeEntryList: onEntryBeforeList,
|
|
1041
|
+
/**
|
|
1042
|
+
* Released in 5.34.0
|
|
1043
|
+
*
|
|
1044
|
+
* Create
|
|
1045
|
+
*/
|
|
1046
|
+
onEntryBeforeCreate,
|
|
1047
|
+
onEntryAfterCreate,
|
|
1048
|
+
onEntryCreateError,
|
|
1049
|
+
/**
|
|
1050
|
+
* Create revision
|
|
1051
|
+
*/
|
|
1052
|
+
onEntryRevisionBeforeCreate: onEntryBeforeCreateRevision,
|
|
1053
|
+
onEntryRevisionAfterCreate,
|
|
1054
|
+
onEntryRevisionCreateError: onEntryCreateRevisionError,
|
|
1055
|
+
/**
|
|
1056
|
+
* Update
|
|
1057
|
+
*/
|
|
1058
|
+
onEntryBeforeUpdate,
|
|
1059
|
+
onEntryAfterUpdate,
|
|
1060
|
+
onEntryUpdateError,
|
|
1061
|
+
/**
|
|
1062
|
+
* Delete whole entry
|
|
1063
|
+
*/
|
|
1064
|
+
onEntryBeforeDelete,
|
|
1065
|
+
onEntryAfterDelete,
|
|
1066
|
+
onEntryDeleteError,
|
|
1067
|
+
/**
|
|
1068
|
+
* Delete entry revision
|
|
1069
|
+
*/
|
|
1070
|
+
onEntryRevisionBeforeDelete,
|
|
1071
|
+
onEntryRevisionAfterDelete,
|
|
1072
|
+
onEntryRevisionDeleteError,
|
|
1073
|
+
/**
|
|
1074
|
+
* Publish
|
|
1075
|
+
*/
|
|
1076
|
+
onEntryBeforePublish,
|
|
1077
|
+
onEntryAfterPublish,
|
|
1078
|
+
onEntryPublishError,
|
|
1079
|
+
/**
|
|
1080
|
+
* Republish
|
|
1081
|
+
*/
|
|
1082
|
+
onEntryBeforeRepublish,
|
|
1083
|
+
onEntryAfterRepublish,
|
|
1084
|
+
onEntryRepublishError,
|
|
1085
|
+
/**
|
|
1086
|
+
* Unpublish
|
|
1087
|
+
*/
|
|
1088
|
+
onEntryBeforeUnpublish,
|
|
1089
|
+
onEntryAfterUnpublish,
|
|
1090
|
+
onEntryUnpublishError,
|
|
1091
|
+
onEntryBeforeGet,
|
|
1092
|
+
onEntryBeforeList,
|
|
1093
|
+
/**
|
|
1094
|
+
* Get entries by exact revision IDs from the database.
|
|
1095
|
+
*/
|
|
1096
|
+
getEntriesByIds,
|
|
1097
|
+
/**
|
|
1098
|
+
* Get a single entry by revision ID from the database.
|
|
1099
|
+
*/
|
|
1100
|
+
async getEntryById(model, id) {
|
|
1101
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntryById", async () => {
|
|
1102
|
+
return getEntryById(model, id);
|
|
1103
|
+
});
|
|
1104
|
+
},
|
|
1105
|
+
/**
|
|
1106
|
+
* Get published revisions by entry IDs.
|
|
1107
|
+
*/
|
|
1108
|
+
async getPublishedEntriesByIds(model, ids) {
|
|
1109
|
+
return context.benchmark.measure("headlessCms.crud.entries.getPublishedEntriesByIds", async () => {
|
|
1110
|
+
return getPublishedEntriesByIds(model, ids);
|
|
451
1111
|
});
|
|
452
|
-
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
453
1112
|
},
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
1113
|
+
/**
|
|
1114
|
+
* Get the latest revisions by entry IDs.
|
|
1115
|
+
*/
|
|
1116
|
+
async getLatestEntriesByIds(model, ids) {
|
|
1117
|
+
return context.benchmark.measure("headlessCms.crud.entries.getLatestEntriesByIds", async () => {
|
|
1118
|
+
return getLatestEntriesByIds(model, ids);
|
|
458
1119
|
});
|
|
459
|
-
|
|
460
|
-
|
|
1120
|
+
},
|
|
1121
|
+
async getEntryRevisions(model, entryId) {
|
|
1122
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntryRevisions", async () => {
|
|
1123
|
+
return getEntryRevisions(model, entryId);
|
|
461
1124
|
});
|
|
462
1125
|
},
|
|
463
1126
|
/**
|
|
@@ -465,118 +1128,20 @@ const createContentEntryCrud = params => {
|
|
|
465
1128
|
*
|
|
466
1129
|
* @internal
|
|
467
1130
|
*/
|
|
468
|
-
async getEntry(
|
|
469
|
-
|
|
470
|
-
|
|
1131
|
+
async getEntry(model, params) {
|
|
1132
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntry", async () => {
|
|
1133
|
+
return getEntry(model, params);
|
|
471
1134
|
});
|
|
472
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
473
|
-
model: initialModel,
|
|
474
|
-
plugins
|
|
475
|
-
});
|
|
476
|
-
const {
|
|
477
|
-
where,
|
|
478
|
-
sort
|
|
479
|
-
} = params;
|
|
480
|
-
await onEntryBeforeGet.publish({
|
|
481
|
-
where,
|
|
482
|
-
model
|
|
483
|
-
});
|
|
484
|
-
const [items] = await this.listEntries(model, {
|
|
485
|
-
where,
|
|
486
|
-
sort,
|
|
487
|
-
limit: 1
|
|
488
|
-
});
|
|
489
|
-
if (items.length === 0) {
|
|
490
|
-
throw new _handlerGraphql.NotFoundError(`Entry not found!`);
|
|
491
|
-
}
|
|
492
|
-
return items[0];
|
|
493
1135
|
},
|
|
494
1136
|
/**
|
|
495
1137
|
* @description Should not be used directly. Internal use only!
|
|
496
1138
|
*
|
|
497
1139
|
* @internal
|
|
498
1140
|
*/
|
|
499
|
-
async listEntries(
|
|
500
|
-
|
|
501
|
-
|
|
1141
|
+
async listEntries(model, params) {
|
|
1142
|
+
return context.benchmark.measure("headlessCms.crud.entries.listEntries", async () => {
|
|
1143
|
+
return listEntries(model, params);
|
|
502
1144
|
});
|
|
503
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
504
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
505
|
-
model: initialModel,
|
|
506
|
-
plugins
|
|
507
|
-
});
|
|
508
|
-
const {
|
|
509
|
-
where: initialWhere,
|
|
510
|
-
limit: initialLimit
|
|
511
|
-
} = params;
|
|
512
|
-
const limit = initialLimit && initialLimit > 0 ? initialLimit : 50;
|
|
513
|
-
/**
|
|
514
|
-
* We always assign tenant and locale because we do not allow one model to have content through multiple tenants.
|
|
515
|
-
*/
|
|
516
|
-
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
517
|
-
/**
|
|
518
|
-
* Possibly only get records which are owned by current user.
|
|
519
|
-
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
520
|
-
*/
|
|
521
|
-
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
522
|
-
if (ownedBy !== undefined) {
|
|
523
|
-
where.ownedBy = ownedBy;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Where must contain either latest or published keys.
|
|
527
|
-
* We cannot list entries without one of those
|
|
528
|
-
*/
|
|
529
|
-
if (where.latest && where.published) {
|
|
530
|
-
throw new _error.default("Cannot list entries that are both published and latest.", "LIST_ENTRIES_ERROR", {
|
|
531
|
-
where
|
|
532
|
-
});
|
|
533
|
-
} else if (!where.latest && !where.published) {
|
|
534
|
-
throw new _error.default("Cannot list entries if we do not have latest or published defined.", "LIST_ENTRIES_ERROR", {
|
|
535
|
-
where
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
const fields = (0, _searchableFields.getSearchableFields)({
|
|
539
|
-
fields: model.fields,
|
|
540
|
-
plugins: context.plugins,
|
|
541
|
-
input: params.fields || []
|
|
542
|
-
});
|
|
543
|
-
try {
|
|
544
|
-
await onEntryBeforeList.publish({
|
|
545
|
-
where,
|
|
546
|
-
model
|
|
547
|
-
});
|
|
548
|
-
const {
|
|
549
|
-
hasMoreItems,
|
|
550
|
-
totalCount,
|
|
551
|
-
cursor,
|
|
552
|
-
items
|
|
553
|
-
} = await storageOperations.entries.list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
554
|
-
limit,
|
|
555
|
-
where,
|
|
556
|
-
fields
|
|
557
|
-
}));
|
|
558
|
-
const meta = {
|
|
559
|
-
hasMoreItems,
|
|
560
|
-
totalCount,
|
|
561
|
-
/**
|
|
562
|
-
* Cursor should be null if there are no more items to load.
|
|
563
|
-
* Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
|
|
564
|
-
*/
|
|
565
|
-
cursor: hasMoreItems ? cursor : null
|
|
566
|
-
};
|
|
567
|
-
return [items, meta];
|
|
568
|
-
} catch (ex) {
|
|
569
|
-
throw new _error.default("Error while fetching entries from storage.", "LIST_ENTRIES_ERROR", {
|
|
570
|
-
params,
|
|
571
|
-
error: {
|
|
572
|
-
message: ex.message,
|
|
573
|
-
code: ex.code,
|
|
574
|
-
data: ex.data
|
|
575
|
-
},
|
|
576
|
-
model,
|
|
577
|
-
fields
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
1145
|
},
|
|
581
1146
|
async listLatestEntries(model, params) {
|
|
582
1147
|
const where = (params === null || params === void 0 ? void 0 : params.where) || {};
|
|
@@ -598,596 +1163,49 @@ const createContentEntryCrud = params => {
|
|
|
598
1163
|
})
|
|
599
1164
|
}));
|
|
600
1165
|
},
|
|
601
|
-
async createEntry(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
});
|
|
605
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
606
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
607
|
-
model: initialModel,
|
|
608
|
-
plugins
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Make sure we only work with fields that are defined in the model.
|
|
613
|
-
*/
|
|
614
|
-
const initialInput = mapAndCleanCreateInputData(model, inputData);
|
|
615
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
616
|
-
context,
|
|
617
|
-
model,
|
|
618
|
-
data: initialInput
|
|
619
|
-
});
|
|
620
|
-
const input = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
621
|
-
context,
|
|
622
|
-
model,
|
|
623
|
-
input: initialInput,
|
|
624
|
-
validateEntries: true
|
|
1166
|
+
async createEntry(model, input) {
|
|
1167
|
+
return context.benchmark.measure("headlessCms.crud.entries.createEntry", async () => {
|
|
1168
|
+
return createEntry(model, input);
|
|
625
1169
|
});
|
|
626
|
-
const identity = context.security.getIdentity();
|
|
627
|
-
const locale = this.getLocale();
|
|
628
|
-
const owner = {
|
|
629
|
-
id: identity.id,
|
|
630
|
-
displayName: identity.displayName,
|
|
631
|
-
type: identity.type
|
|
632
|
-
};
|
|
633
|
-
/**
|
|
634
|
-
* There is a possibility that user sends an ID in the input, so we will use that one.
|
|
635
|
-
* There is no check if the ID is unique or not, that is up to the user.
|
|
636
|
-
*/
|
|
637
|
-
const {
|
|
638
|
-
id,
|
|
639
|
-
entryId,
|
|
640
|
-
version
|
|
641
|
-
} = createEntryId(inputData);
|
|
642
|
-
const entry = {
|
|
643
|
-
webinyVersion: context.WEBINY_VERSION,
|
|
644
|
-
tenant: getTenant().id,
|
|
645
|
-
entryId,
|
|
646
|
-
id,
|
|
647
|
-
modelId: model.modelId,
|
|
648
|
-
locale: locale.code,
|
|
649
|
-
createdOn: new Date().toISOString(),
|
|
650
|
-
savedOn: new Date().toISOString(),
|
|
651
|
-
createdBy: owner,
|
|
652
|
-
ownedBy: owner,
|
|
653
|
-
version,
|
|
654
|
-
locked: false,
|
|
655
|
-
status: STATUS_DRAFT,
|
|
656
|
-
values: input
|
|
657
|
-
};
|
|
658
|
-
let storageEntry = null;
|
|
659
|
-
try {
|
|
660
|
-
await onEntryBeforeCreate.publish({
|
|
661
|
-
entry,
|
|
662
|
-
input,
|
|
663
|
-
model
|
|
664
|
-
});
|
|
665
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
666
|
-
const result = await storageOperations.entries.create(model, {
|
|
667
|
-
entry,
|
|
668
|
-
storageEntry
|
|
669
|
-
});
|
|
670
|
-
await onEntryAfterCreate.publish({
|
|
671
|
-
entry,
|
|
672
|
-
storageEntry: result,
|
|
673
|
-
model,
|
|
674
|
-
input
|
|
675
|
-
});
|
|
676
|
-
return result;
|
|
677
|
-
} catch (ex) {
|
|
678
|
-
await onEntryCreateError.publish({
|
|
679
|
-
error: ex,
|
|
680
|
-
entry,
|
|
681
|
-
model,
|
|
682
|
-
input
|
|
683
|
-
});
|
|
684
|
-
throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
|
|
685
|
-
error: ex,
|
|
686
|
-
input,
|
|
687
|
-
entry,
|
|
688
|
-
storageEntry
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
1170
|
},
|
|
692
|
-
async createEntryRevisionFrom(
|
|
693
|
-
|
|
694
|
-
|
|
1171
|
+
async createEntryRevisionFrom(model, sourceId, input) {
|
|
1172
|
+
return context.benchmark.measure("headlessCms.crud.entries.createEntryRevisionFrom", async () => {
|
|
1173
|
+
return createEntryRevisionFrom(model, sourceId, input);
|
|
695
1174
|
});
|
|
696
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
697
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
698
|
-
model: initialModel,
|
|
699
|
-
plugins
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Make sure we only work with fields that are defined in the model.
|
|
704
|
-
*/
|
|
705
|
-
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* Entries are identified by a common parent ID + Revision number.
|
|
709
|
-
*/
|
|
710
|
-
const {
|
|
711
|
-
id: uniqueId
|
|
712
|
-
} = (0, _utils.parseIdentifier)(sourceId);
|
|
713
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
714
|
-
id: sourceId
|
|
715
|
-
});
|
|
716
|
-
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
717
|
-
id: uniqueId
|
|
718
|
-
});
|
|
719
|
-
if (!originalStorageEntry) {
|
|
720
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
* We need to convert data from DB to its original form before using it further.
|
|
725
|
-
*/
|
|
726
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
727
|
-
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
728
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
729
|
-
context,
|
|
730
|
-
model,
|
|
731
|
-
data: initialValues,
|
|
732
|
-
entry: originalEntry
|
|
733
|
-
});
|
|
734
|
-
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
735
|
-
context,
|
|
736
|
-
model,
|
|
737
|
-
input: initialValues,
|
|
738
|
-
validateEntries: false
|
|
739
|
-
});
|
|
740
|
-
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
741
|
-
const identity = context.security.getIdentity();
|
|
742
|
-
const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
|
|
743
|
-
const {
|
|
744
|
-
id,
|
|
745
|
-
version: nextVersion
|
|
746
|
-
} = increaseEntryIdVersion(latestId);
|
|
747
|
-
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
748
|
-
id,
|
|
749
|
-
version: nextVersion,
|
|
750
|
-
savedOn: new Date().toISOString(),
|
|
751
|
-
createdOn: new Date().toISOString(),
|
|
752
|
-
createdBy: {
|
|
753
|
-
id: identity.id,
|
|
754
|
-
displayName: identity.displayName,
|
|
755
|
-
type: identity.type
|
|
756
|
-
},
|
|
757
|
-
locked: false,
|
|
758
|
-
publishedOn: undefined,
|
|
759
|
-
status: STATUS_DRAFT,
|
|
760
|
-
values
|
|
761
|
-
});
|
|
762
|
-
let storageEntry = null;
|
|
763
|
-
try {
|
|
764
|
-
await onEntryBeforeCreateRevision.publish({
|
|
765
|
-
input,
|
|
766
|
-
entry,
|
|
767
|
-
original: originalEntry,
|
|
768
|
-
model
|
|
769
|
-
});
|
|
770
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
771
|
-
const result = await storageOperations.entries.createRevisionFrom(model, {
|
|
772
|
-
entry,
|
|
773
|
-
storageEntry
|
|
774
|
-
});
|
|
775
|
-
await onEntryRevisionAfterCreate.publish({
|
|
776
|
-
input,
|
|
777
|
-
entry,
|
|
778
|
-
model,
|
|
779
|
-
original: originalEntry,
|
|
780
|
-
storageEntry: result
|
|
781
|
-
});
|
|
782
|
-
return result;
|
|
783
|
-
} catch (ex) {
|
|
784
|
-
await onEntryCreateRevisionError.publish({
|
|
785
|
-
entry,
|
|
786
|
-
original: originalEntry,
|
|
787
|
-
model,
|
|
788
|
-
input,
|
|
789
|
-
error: ex
|
|
790
|
-
});
|
|
791
|
-
throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
|
|
792
|
-
error: ex,
|
|
793
|
-
entry,
|
|
794
|
-
storageEntry,
|
|
795
|
-
originalEntry,
|
|
796
|
-
originalStorageEntry
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
1175
|
},
|
|
800
|
-
async updateEntry(
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
});
|
|
804
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
805
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
806
|
-
model: initialModel,
|
|
807
|
-
plugins
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* Make sure we only work with fields that are defined in the model.
|
|
812
|
-
*/
|
|
813
|
-
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* The entry we are going to update.
|
|
817
|
-
*/
|
|
818
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
819
|
-
id
|
|
820
|
-
});
|
|
821
|
-
if (!originalStorageEntry) {
|
|
822
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
823
|
-
}
|
|
824
|
-
if (originalStorageEntry.locked) {
|
|
825
|
-
throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
|
|
826
|
-
}
|
|
827
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
828
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
829
|
-
context,
|
|
830
|
-
model,
|
|
831
|
-
data: input,
|
|
832
|
-
entry: originalEntry
|
|
1176
|
+
async updateEntry(model, id, input, meta) {
|
|
1177
|
+
return context.benchmark.measure("headlessCms.crud.entries.updateEntry", async () => {
|
|
1178
|
+
return updateEntry(model, id, input, meta);
|
|
833
1179
|
});
|
|
834
|
-
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
835
|
-
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
836
|
-
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
837
|
-
context,
|
|
838
|
-
model,
|
|
839
|
-
input: initialValues,
|
|
840
|
-
validateEntries: false
|
|
841
|
-
});
|
|
842
|
-
/**
|
|
843
|
-
* If users wants to remove a key from meta values, they need to send meta key with the null value.
|
|
844
|
-
*/
|
|
845
|
-
const meta = createEntryMeta(metaInput, originalEntry.meta);
|
|
846
|
-
/**
|
|
847
|
-
* We always send the full entry to the hooks and storage operations update.
|
|
848
|
-
*/
|
|
849
|
-
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
850
|
-
savedOn: new Date().toISOString(),
|
|
851
|
-
values,
|
|
852
|
-
meta,
|
|
853
|
-
status: transformEntryStatus(originalEntry.status)
|
|
854
|
-
});
|
|
855
|
-
let storageEntry = null;
|
|
856
|
-
try {
|
|
857
|
-
await onEntryBeforeUpdate.publish({
|
|
858
|
-
entry,
|
|
859
|
-
model,
|
|
860
|
-
input,
|
|
861
|
-
original: originalEntry
|
|
862
|
-
});
|
|
863
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
864
|
-
const result = await storageOperations.entries.update(model, {
|
|
865
|
-
entry,
|
|
866
|
-
storageEntry
|
|
867
|
-
});
|
|
868
|
-
await onEntryAfterUpdate.publish({
|
|
869
|
-
entry,
|
|
870
|
-
storageEntry: result,
|
|
871
|
-
model,
|
|
872
|
-
input,
|
|
873
|
-
original: originalEntry
|
|
874
|
-
});
|
|
875
|
-
return result;
|
|
876
|
-
} catch (ex) {
|
|
877
|
-
await onEntryUpdateError.publish({
|
|
878
|
-
entry,
|
|
879
|
-
model,
|
|
880
|
-
input,
|
|
881
|
-
error: ex
|
|
882
|
-
});
|
|
883
|
-
throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
|
|
884
|
-
error: ex,
|
|
885
|
-
entry,
|
|
886
|
-
storageEntry,
|
|
887
|
-
originalEntry,
|
|
888
|
-
input
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
1180
|
},
|
|
892
1181
|
/**
|
|
893
1182
|
* Method used internally. Not documented and should not be used in users systems.
|
|
894
1183
|
* @internal
|
|
895
1184
|
*/
|
|
896
|
-
async republishEntry(
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
});
|
|
900
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
901
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
902
|
-
model: initialModel,
|
|
903
|
-
plugins
|
|
904
|
-
});
|
|
905
|
-
/**
|
|
906
|
-
* Fetch the entry from the storage.
|
|
907
|
-
*/
|
|
908
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
909
|
-
id
|
|
1185
|
+
async republishEntry(model, id) {
|
|
1186
|
+
return context.benchmark.measure("headlessCms.crud.entries.republishEntry", async () => {
|
|
1187
|
+
return republishEntry(model, id);
|
|
910
1188
|
});
|
|
911
|
-
if (!originalStorageEntry) {
|
|
912
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${id}" was not found!`);
|
|
913
|
-
}
|
|
914
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
915
|
-
/**
|
|
916
|
-
* We can only process published entries.
|
|
917
|
-
*/
|
|
918
|
-
if (originalEntry.status !== "published") {
|
|
919
|
-
throw new _error.default("Entry with given ID is not published!", "NOT_PUBLISHED_ERROR", {
|
|
920
|
-
id,
|
|
921
|
-
original: originalEntry
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
925
|
-
context,
|
|
926
|
-
model,
|
|
927
|
-
input: originalEntry.values,
|
|
928
|
-
validateEntries: false
|
|
929
|
-
});
|
|
930
|
-
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
931
|
-
savedOn: new Date().toISOString(),
|
|
932
|
-
webinyVersion: context.WEBINY_VERSION,
|
|
933
|
-
values
|
|
934
|
-
});
|
|
935
|
-
const storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
936
|
-
/**
|
|
937
|
-
* First we need to update existing entry.
|
|
938
|
-
*/
|
|
939
|
-
try {
|
|
940
|
-
await storageOperations.entries.update(model, {
|
|
941
|
-
entry,
|
|
942
|
-
storageEntry
|
|
943
|
-
});
|
|
944
|
-
} catch (ex) {
|
|
945
|
-
throw new _error.default("Could not update existing entry with new data while re-publishing.", "REPUBLISH_UPDATE_ERROR", {
|
|
946
|
-
entry
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Then we move onto publishing it again.
|
|
951
|
-
*/
|
|
952
|
-
try {
|
|
953
|
-
await onEntryBeforeRepublish.publish({
|
|
954
|
-
entry,
|
|
955
|
-
model
|
|
956
|
-
});
|
|
957
|
-
const result = await storageOperations.entries.publish(model, {
|
|
958
|
-
entry,
|
|
959
|
-
storageEntry
|
|
960
|
-
});
|
|
961
|
-
await onEntryAfterRepublish.publish({
|
|
962
|
-
entry,
|
|
963
|
-
model,
|
|
964
|
-
storageEntry
|
|
965
|
-
});
|
|
966
|
-
return result;
|
|
967
|
-
} catch (ex) {
|
|
968
|
-
await onEntryRepublishError.publish({
|
|
969
|
-
entry,
|
|
970
|
-
model,
|
|
971
|
-
error: ex
|
|
972
|
-
});
|
|
973
|
-
throw new _error.default("Could not publish existing entry while re-publishing.", "REPUBLISH_PUBLISH_ERROR", {
|
|
974
|
-
entry
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
1189
|
},
|
|
978
|
-
async deleteEntryRevision(
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
983
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
984
|
-
model: initialModel,
|
|
985
|
-
plugins
|
|
986
|
-
});
|
|
987
|
-
const {
|
|
988
|
-
id: entryId,
|
|
989
|
-
version
|
|
990
|
-
} = (0, _utils.parseIdentifier)(revisionId);
|
|
991
|
-
const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
|
|
992
|
-
id: revisionId
|
|
993
|
-
});
|
|
994
|
-
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
995
|
-
id: entryId
|
|
996
|
-
});
|
|
997
|
-
const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
|
|
998
|
-
entryId,
|
|
999
|
-
version: version
|
|
1190
|
+
async deleteEntryRevision(model, id) {
|
|
1191
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntryRevision", async () => {
|
|
1192
|
+
return deleteEntryRevision(model, id);
|
|
1000
1193
|
});
|
|
1001
|
-
if (!storageEntryToDelete) {
|
|
1002
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
|
|
1003
|
-
}
|
|
1004
|
-
(0, _ownership.checkOwnership)(context, permission, storageEntryToDelete);
|
|
1005
|
-
const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
|
|
1006
|
-
const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
|
|
1007
|
-
/**
|
|
1008
|
-
* If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
|
|
1009
|
-
* At this point deleteRevision hooks are not fired.
|
|
1010
|
-
*/
|
|
1011
|
-
if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
|
|
1012
|
-
return await deleteEntry({
|
|
1013
|
-
model,
|
|
1014
|
-
entry: entryToDelete
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* If targeted record is latest entry revision, set the previous one as the new latest
|
|
1019
|
-
*/
|
|
1020
|
-
let entryToSetAsLatest = null;
|
|
1021
|
-
let storageEntryToSetAsLatest = null;
|
|
1022
|
-
if (entryToDelete.id === latestEntryRevisionId && previousStorageEntry) {
|
|
1023
|
-
entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
|
|
1024
|
-
storageEntryToSetAsLatest = previousStorageEntry;
|
|
1025
|
-
}
|
|
1026
|
-
try {
|
|
1027
|
-
await onEntryRevisionBeforeDelete.publish({
|
|
1028
|
-
entry: entryToDelete,
|
|
1029
|
-
model
|
|
1030
|
-
});
|
|
1031
|
-
await storageOperations.entries.deleteRevision(model, {
|
|
1032
|
-
entry: entryToDelete,
|
|
1033
|
-
storageEntry: storageEntryToDelete,
|
|
1034
|
-
latestEntry: entryToSetAsLatest,
|
|
1035
|
-
latestStorageEntry: storageEntryToSetAsLatest
|
|
1036
|
-
});
|
|
1037
|
-
await onEntryRevisionAfterDelete.publish({
|
|
1038
|
-
entry: entryToDelete,
|
|
1039
|
-
model
|
|
1040
|
-
});
|
|
1041
|
-
} catch (ex) {
|
|
1042
|
-
await onEntryRevisionDeleteError.publish({
|
|
1043
|
-
entry: entryToDelete,
|
|
1044
|
-
model,
|
|
1045
|
-
error: ex
|
|
1046
|
-
});
|
|
1047
|
-
throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
|
|
1048
|
-
error: ex,
|
|
1049
|
-
entry: entryToDelete,
|
|
1050
|
-
storageEntry: storageEntryToDelete,
|
|
1051
|
-
latestEntry: entryToSetAsLatest,
|
|
1052
|
-
latestStorageEntry: storageEntryToSetAsLatest
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
1194
|
},
|
|
1056
|
-
async deleteEntry(
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
});
|
|
1060
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
1061
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
1062
|
-
model: initialModel,
|
|
1063
|
-
plugins
|
|
1064
|
-
});
|
|
1065
|
-
const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
1066
|
-
id: entryId
|
|
1067
|
-
});
|
|
1068
|
-
if (!storageEntry) {
|
|
1069
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
|
|
1070
|
-
}
|
|
1071
|
-
(0, _ownership.checkOwnership)(context, permission, storageEntry);
|
|
1072
|
-
const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
|
|
1073
|
-
return await deleteEntry({
|
|
1074
|
-
model,
|
|
1075
|
-
entry
|
|
1195
|
+
async deleteEntry(model, entryId) {
|
|
1196
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntry", async () => {
|
|
1197
|
+
return deleteEntry(model, entryId);
|
|
1076
1198
|
});
|
|
1077
1199
|
},
|
|
1078
|
-
async publishEntry(
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
});
|
|
1082
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
1083
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
1084
|
-
model: initialModel,
|
|
1085
|
-
plugins
|
|
1086
|
-
});
|
|
1087
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
1088
|
-
id
|
|
1089
|
-
});
|
|
1090
|
-
if (!originalStorageEntry) {
|
|
1091
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
|
|
1092
|
-
}
|
|
1093
|
-
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
1094
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
1095
|
-
const currentDate = new Date().toISOString();
|
|
1096
|
-
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
1097
|
-
status: STATUS_PUBLISHED,
|
|
1098
|
-
locked: true,
|
|
1099
|
-
savedOn: currentDate,
|
|
1100
|
-
publishedOn: currentDate
|
|
1200
|
+
async publishEntry(model, id) {
|
|
1201
|
+
return context.benchmark.measure("headlessCms.crud.entries.publishEntry", async () => {
|
|
1202
|
+
return publishEntry(model, id);
|
|
1101
1203
|
});
|
|
1102
|
-
let storageEntry = null;
|
|
1103
|
-
try {
|
|
1104
|
-
await onEntryBeforePublish.publish({
|
|
1105
|
-
entry,
|
|
1106
|
-
model
|
|
1107
|
-
});
|
|
1108
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1109
|
-
const result = await storageOperations.entries.publish(model, {
|
|
1110
|
-
entry,
|
|
1111
|
-
storageEntry
|
|
1112
|
-
});
|
|
1113
|
-
await onEntryAfterPublish.publish({
|
|
1114
|
-
entry,
|
|
1115
|
-
storageEntry: result,
|
|
1116
|
-
model
|
|
1117
|
-
});
|
|
1118
|
-
return result;
|
|
1119
|
-
} catch (ex) {
|
|
1120
|
-
await onEntryPublishError.publish({
|
|
1121
|
-
entry,
|
|
1122
|
-
model,
|
|
1123
|
-
error: ex
|
|
1124
|
-
});
|
|
1125
|
-
throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
|
|
1126
|
-
error: ex,
|
|
1127
|
-
entry,
|
|
1128
|
-
storageEntry,
|
|
1129
|
-
originalEntry,
|
|
1130
|
-
originalStorageEntry
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
1204
|
},
|
|
1134
|
-
async unpublishEntry(
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
});
|
|
1138
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
1139
|
-
model: initialModel,
|
|
1140
|
-
plugins
|
|
1141
|
-
});
|
|
1142
|
-
const {
|
|
1143
|
-
id: entryId
|
|
1144
|
-
} = (0, _utils.parseIdentifier)(id);
|
|
1145
|
-
const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
|
|
1146
|
-
id: entryId
|
|
1205
|
+
async unpublishEntry(model, id) {
|
|
1206
|
+
return context.benchmark.measure("headlessCms.crud.entries.unpublishEntry", async () => {
|
|
1207
|
+
return unpublishEntry(model, id);
|
|
1147
1208
|
});
|
|
1148
|
-
if (!originalStorageEntry) {
|
|
1149
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
1150
|
-
}
|
|
1151
|
-
if (originalStorageEntry.id !== id) {
|
|
1152
|
-
throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
|
|
1153
|
-
entry: originalStorageEntry
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
1157
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
1158
|
-
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
1159
|
-
status: STATUS_UNPUBLISHED
|
|
1160
|
-
});
|
|
1161
|
-
let storageEntry = null;
|
|
1162
|
-
try {
|
|
1163
|
-
await onEntryBeforeUnpublish.publish({
|
|
1164
|
-
entry,
|
|
1165
|
-
model
|
|
1166
|
-
});
|
|
1167
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1168
|
-
const result = await storageOperations.entries.unpublish(model, {
|
|
1169
|
-
entry,
|
|
1170
|
-
storageEntry
|
|
1171
|
-
});
|
|
1172
|
-
await onEntryAfterUnpublish.publish({
|
|
1173
|
-
entry,
|
|
1174
|
-
storageEntry: result,
|
|
1175
|
-
model
|
|
1176
|
-
});
|
|
1177
|
-
return result;
|
|
1178
|
-
} catch (ex) {
|
|
1179
|
-
await onEntryUnpublishError.publish({
|
|
1180
|
-
entry,
|
|
1181
|
-
model,
|
|
1182
|
-
error: ex
|
|
1183
|
-
});
|
|
1184
|
-
throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
|
|
1185
|
-
originalEntry,
|
|
1186
|
-
originalStorageEntry,
|
|
1187
|
-
entry,
|
|
1188
|
-
storageEntry
|
|
1189
|
-
});
|
|
1190
|
-
}
|
|
1191
1209
|
}
|
|
1192
1210
|
};
|
|
1193
1211
|
};
|