@webiny/api-headless-cms 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +73 -0
- package/content/contextSetup.d.ts +4 -0
- package/content/contextSetup.js +65 -0
- package/content/graphQLHandlerFactory.d.ts +5 -0
- package/content/graphQLHandlerFactory.js +173 -0
- package/content/plugins/CmsGroupPlugin.d.ts +11 -0
- package/content/plugins/CmsGroupPlugin.js +24 -0
- package/content/plugins/CmsModelPlugin.d.ts +11 -0
- package/content/plugins/CmsModelPlugin.js +24 -0
- package/content/plugins/buildSchemaPlugins.d.ts +7 -0
- package/content/plugins/buildSchemaPlugins.js +29 -0
- package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
- package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
- package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
- package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
- package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
- package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
- package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +4 -0
- package/content/plugins/crud/contentEntry/entryDataValidation.js +188 -0
- package/content/plugins/crud/contentEntry/markLockedFields.d.ts +12 -0
- package/content/plugins/crud/contentEntry/markLockedFields.js +117 -0
- package/content/plugins/crud/contentEntry.crud.d.ts +17 -0
- package/content/plugins/crud/contentEntry.crud.js +931 -0
- package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterCreate.js +18 -0
- package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterDelete.js +18 -0
- package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
- package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
- package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
- package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
- package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
- package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
- package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
- package/content/plugins/crud/contentModel/contentModelManagerFactory.js +29 -0
- package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -0
- package/content/plugins/crud/contentModel/createFieldModels.js +22 -0
- package/content/plugins/crud/contentModel/idValidation.d.ts +2 -0
- package/content/plugins/crud/contentModel/idValidation.js +22 -0
- package/content/plugins/crud/contentModel/models.d.ts +3 -0
- package/content/plugins/crud/contentModel/models.js +141 -0
- package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -0
- package/content/plugins/crud/contentModel/validateLayout.js +38 -0
- package/content/plugins/crud/contentModel.crud.d.ts +12 -0
- package/content/plugins/crud/contentModel.crud.js +425 -0
- package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
- package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
- package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
- package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
- package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
- package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
- package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -0
- package/content/plugins/crud/contentModelGroup.crud.js +351 -0
- package/content/plugins/crud/index.d.ts +6 -0
- package/content/plugins/crud/index.js +100 -0
- package/content/plugins/graphqlFields/boolean.d.ts +3 -0
- package/content/plugins/graphqlFields/boolean.js +69 -0
- package/content/plugins/graphqlFields/datetime.d.ts +3 -0
- package/content/plugins/graphqlFields/datetime.js +83 -0
- package/content/plugins/graphqlFields/file.d.ts +3 -0
- package/content/plugins/graphqlFields/file.js +49 -0
- package/content/plugins/graphqlFields/index.d.ts +2 -0
- package/content/plugins/graphqlFields/index.js +30 -0
- package/content/plugins/graphqlFields/longText.d.ts +3 -0
- package/content/plugins/graphqlFields/longText.js +62 -0
- package/content/plugins/graphqlFields/number.d.ts +3 -0
- package/content/plugins/graphqlFields/number.js +75 -0
- package/content/plugins/graphqlFields/object.d.ts +3 -0
- package/content/plugins/graphqlFields/object.js +180 -0
- package/content/plugins/graphqlFields/ref.d.ts +3 -0
- package/content/plugins/graphqlFields/ref.js +205 -0
- package/content/plugins/graphqlFields/richText.d.ts +3 -0
- package/content/plugins/graphqlFields/richText.js +55 -0
- package/content/plugins/graphqlFields/text.d.ts +3 -0
- package/content/plugins/graphqlFields/text.js +72 -0
- package/content/plugins/internalSecurity/InternalAuthenticationPlugin.d.ts +8 -0
- package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +54 -0
- package/content/plugins/internalSecurity/InternalAuthorizationPlugin.d.ts +7 -0
- package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +35 -0
- package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
- package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
- package/content/plugins/modelManager/index.d.ts +3 -0
- package/content/plugins/modelManager/index.js +20 -0
- package/content/plugins/schema/baseSchema.d.ts +4 -0
- package/content/plugins/schema/baseSchema.js +98 -0
- package/content/plugins/schema/contentEntries.d.ts +4 -0
- package/content/plugins/schema/contentEntries.js +166 -0
- package/content/plugins/schema/contentModelGroups.d.ts +4 -0
- package/content/plugins/schema/contentModelGroups.js +153 -0
- package/content/plugins/schema/contentModels.d.ts +4 -0
- package/content/plugins/schema/contentModels.js +225 -0
- package/content/plugins/schema/createFieldResolvers.d.ts +19 -0
- package/content/plugins/schema/createFieldResolvers.js +92 -0
- package/content/plugins/schema/createManageResolvers.d.ts +11 -0
- package/content/plugins/schema/createManageResolvers.js +135 -0
- package/content/plugins/schema/createManageSDL.d.ts +9 -0
- package/content/plugins/schema/createManageSDL.js +153 -0
- package/content/plugins/schema/createPreviewResolvers.d.ts +10 -0
- package/content/plugins/schema/createPreviewResolvers.js +55 -0
- package/content/plugins/schema/createReadResolvers.d.ts +10 -0
- package/content/plugins/schema/createReadResolvers.js +55 -0
- package/content/plugins/schema/createReadSDL.d.ts +9 -0
- package/content/plugins/schema/createReadSDL.js +96 -0
- package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +6 -0
- package/content/plugins/schema/resolvers/commonFieldResolvers.js +14 -0
- package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveCreate.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +7 -0
- package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveDelete.js +30 -0
- package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGet.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveList.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolvePublish.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +6 -0
- package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +23 -0
- package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +2 -0
- package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +21 -0
- package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +7 -0
- package/content/plugins/schema/resolvers/manage/resolveUpdate.js +23 -0
- package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/preview/resolveGet.js +38 -0
- package/content/plugins/schema/resolvers/preview/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/preview/resolveList.js +23 -0
- package/content/plugins/schema/resolvers/read/resolveGet.d.ts +2 -0
- package/content/plugins/schema/resolvers/read/resolveGet.js +38 -0
- package/content/plugins/schema/resolvers/read/resolveList.d.ts +2 -0
- package/content/plugins/schema/resolvers/read/resolveList.js +23 -0
- package/content/plugins/schema/schemaPlugins.d.ts +3 -0
- package/content/plugins/schema/schemaPlugins.js +92 -0
- package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
- package/content/plugins/storage/StorageTransformPlugin.js +36 -0
- package/content/plugins/storage/default.d.ts +3 -0
- package/content/plugins/storage/default.js +28 -0
- package/content/plugins/storage/object.d.ts +3 -0
- package/content/plugins/storage/object.js +119 -0
- package/content/plugins/utils/createTypeName.d.ts +3 -0
- package/content/plugins/utils/createTypeName.js +28 -0
- package/content/plugins/utils/entryStorage.d.ts +17 -0
- package/content/plugins/utils/entryStorage.js +125 -0
- package/content/plugins/utils/getEntryTitle.d.ts +2 -0
- package/content/plugins/utils/getEntryTitle.js +42 -0
- package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +11 -0
- package/content/plugins/utils/getSchemaFromFieldPlugins.js +30 -0
- package/content/plugins/utils/pluralizedTypeName.d.ts +1 -0
- package/content/plugins/utils/pluralizedTypeName.js +26 -0
- package/content/plugins/utils/renderFields.d.ts +16 -0
- package/content/plugins/utils/renderFields.js +51 -0
- package/content/plugins/utils/renderGetFilterFields.d.ts +9 -0
- package/content/plugins/utils/renderGetFilterFields.js +41 -0
- package/content/plugins/utils/renderInputFields.d.ts +14 -0
- package/content/plugins/utils/renderInputFields.js +53 -0
- package/content/plugins/utils/renderListFilterFields.d.ts +10 -0
- package/content/plugins/utils/renderListFilterFields.js +39 -0
- package/content/plugins/utils/renderSortEnum.d.ts +9 -0
- package/content/plugins/utils/renderSortEnum.js +32 -0
- package/content/plugins/validators/dateGte.d.ts +3 -0
- package/content/plugins/validators/dateGte.js +37 -0
- package/content/plugins/validators/dateLte.d.ts +3 -0
- package/content/plugins/validators/dateLte.js +37 -0
- package/content/plugins/validators/gte.d.ts +3 -0
- package/content/plugins/validators/gte.js +32 -0
- package/content/plugins/validators/in.d.ts +3 -0
- package/content/plugins/validators/in.js +32 -0
- package/content/plugins/validators/index.d.ts +2 -0
- package/content/plugins/validators/index.js +36 -0
- package/content/plugins/validators/lte.d.ts +3 -0
- package/content/plugins/validators/lte.js +32 -0
- package/content/plugins/validators/maxLength.d.ts +3 -0
- package/content/plugins/validators/maxLength.js +32 -0
- package/content/plugins/validators/minLength.d.ts +3 -0
- package/content/plugins/validators/minLength.js +32 -0
- package/content/plugins/validators/pattern.d.ts +3 -0
- package/content/plugins/validators/pattern.js +47 -0
- package/content/plugins/validators/patternPlugins/email.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/email.js +17 -0
- package/content/plugins/validators/patternPlugins/index.d.ts +2 -0
- package/content/plugins/validators/patternPlugins/index.js +19 -0
- package/content/plugins/validators/patternPlugins/lowerCase.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/lowerCase.js +17 -0
- package/content/plugins/validators/patternPlugins/upperCase.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/upperCase.js +17 -0
- package/content/plugins/validators/patternPlugins/url.d.ts +3 -0
- package/content/plugins/validators/patternPlugins/url.js +17 -0
- package/content/plugins/validators/required.d.ts +3 -0
- package/content/plugins/validators/required.js +25 -0
- package/content/plugins/validators/timeGte.d.ts +3 -0
- package/content/plugins/validators/timeGte.js +32 -0
- package/content/plugins/validators/timeLte.d.ts +3 -0
- package/content/plugins/validators/timeLte.js +32 -0
- package/index.d.ts +12 -0
- package/index.js +66 -0
- package/migrateCMSPermissions.d.ts +17 -0
- package/migrateCMSPermissions.js +193 -0
- package/package.json +80 -0
- package/plugins/context.d.ts +4 -0
- package/plugins/context.js +34 -0
- package/plugins/crud/index.d.ts +6 -0
- package/plugins/crud/index.js +100 -0
- package/plugins/crud/settings.crud.d.ts +10 -0
- package/plugins/crud/settings.crud.js +93 -0
- package/plugins/crud/system.crud.d.ts +10 -0
- package/plugins/crud/system.crud.js +182 -0
- package/plugins/graphql/system.d.ts +17 -0
- package/plugins/graphql/system.js +72 -0
- package/plugins/graphql.d.ts +2 -0
- package/plugins/graphql.js +79 -0
- package/plugins/upgrades/index.d.ts +2 -0
- package/plugins/upgrades/index.js +14 -0
- package/plugins/upgrades/v5.5.0/helpers.d.ts +6 -0
- package/plugins/upgrades/v5.5.0/helpers.js +10 -0
- package/plugins/upgrades/v5.5.0/index.d.ts +4 -0
- package/plugins/upgrades/v5.5.0/index.js +129 -0
- package/transformers.d.ts +2 -0
- package/transformers.js +25 -0
- package/types.d.ts +2149 -0
- package/types.js +366 -0
- package/utils.d.ts +25 -0
- package/utils.js +251 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createContentEntryCrud = exports.STATUS_UNPUBLISHED = exports.STATUS_REVIEW_REQUESTED = exports.STATUS_PUBLISHED = exports.STATUS_DRAFT = exports.STATUS_CHANGES_REQUESTED = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
13
|
+
|
|
14
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
15
|
+
|
|
16
|
+
var utils = _interopRequireWildcard(require("../../../utils"));
|
|
17
|
+
|
|
18
|
+
var _entryDataValidation = require("./contentEntry/entryDataValidation");
|
|
19
|
+
|
|
20
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
21
|
+
|
|
22
|
+
var _pubsub = require("@webiny/pubsub");
|
|
23
|
+
|
|
24
|
+
var _beforeCreate = require("./contentEntry/beforeCreate");
|
|
25
|
+
|
|
26
|
+
var _beforeUpdate = require("./contentEntry/beforeUpdate");
|
|
27
|
+
|
|
28
|
+
var _utils2 = require("@webiny/utils");
|
|
29
|
+
|
|
30
|
+
var _entryStorage = require("../utils/entryStorage");
|
|
31
|
+
|
|
32
|
+
var _afterDelete = require("./contentEntry/afterDelete");
|
|
33
|
+
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
|
+
|
|
36
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
37
|
+
|
|
38
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
39
|
+
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
41
|
+
|
|
42
|
+
const STATUS_DRAFT = "draft";
|
|
43
|
+
exports.STATUS_DRAFT = STATUS_DRAFT;
|
|
44
|
+
const STATUS_PUBLISHED = "published";
|
|
45
|
+
exports.STATUS_PUBLISHED = STATUS_PUBLISHED;
|
|
46
|
+
const STATUS_UNPUBLISHED = "unpublished";
|
|
47
|
+
exports.STATUS_UNPUBLISHED = STATUS_UNPUBLISHED;
|
|
48
|
+
const STATUS_CHANGES_REQUESTED = "changesRequested";
|
|
49
|
+
exports.STATUS_CHANGES_REQUESTED = STATUS_CHANGES_REQUESTED;
|
|
50
|
+
const STATUS_REVIEW_REQUESTED = "reviewRequested";
|
|
51
|
+
exports.STATUS_REVIEW_REQUESTED = STATUS_REVIEW_REQUESTED;
|
|
52
|
+
|
|
53
|
+
const cleanInputData = (model, inputData) => {
|
|
54
|
+
return model.fields.reduce((acc, field) => {
|
|
55
|
+
acc[field.fieldId] = inputData[field.fieldId];
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const cleanUpdatedInputData = (model, input) => {
|
|
61
|
+
return model.fields.reduce((acc, field) => {
|
|
62
|
+
if (input[field.fieldId] === undefined) {
|
|
63
|
+
return acc;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
acc[field.fieldId] = input[field.fieldId];
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const createEntryId = version => {
|
|
72
|
+
const entryId = (0, _mdbid.default)();
|
|
73
|
+
return {
|
|
74
|
+
entryId,
|
|
75
|
+
version,
|
|
76
|
+
id: (0, _utils2.createIdentifier)({
|
|
77
|
+
id: entryId,
|
|
78
|
+
version
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const increaseEntryIdVersion = id => {
|
|
84
|
+
if (id.includes("#") === false) {
|
|
85
|
+
throw new _error.default("Cannot increase version on the ID without the version part.", "WRONG_ID", {
|
|
86
|
+
id
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const [entryId, version] = id.split("#");
|
|
91
|
+
const ver = parseInt(version) + 1;
|
|
92
|
+
return {
|
|
93
|
+
entryId,
|
|
94
|
+
version: ver,
|
|
95
|
+
id: (0, _utils2.createIdentifier)({
|
|
96
|
+
id: entryId,
|
|
97
|
+
version: ver
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const createContentEntryCrud = params => {
|
|
103
|
+
const {
|
|
104
|
+
storageOperations,
|
|
105
|
+
context,
|
|
106
|
+
getTenant,
|
|
107
|
+
getLocale,
|
|
108
|
+
getIdentity
|
|
109
|
+
} = params;
|
|
110
|
+
const onBeforeCreate = (0, _pubsub.createTopic)();
|
|
111
|
+
const onAfterCreate = (0, _pubsub.createTopic)();
|
|
112
|
+
const onBeforeCreateRevision = (0, _pubsub.createTopic)();
|
|
113
|
+
const onAfterCreateRevision = (0, _pubsub.createTopic)();
|
|
114
|
+
const onBeforeUpdate = (0, _pubsub.createTopic)();
|
|
115
|
+
const onAfterUpdate = (0, _pubsub.createTopic)();
|
|
116
|
+
const onBeforePublish = (0, _pubsub.createTopic)();
|
|
117
|
+
const onAfterPublish = (0, _pubsub.createTopic)();
|
|
118
|
+
const onBeforeUnpublish = (0, _pubsub.createTopic)();
|
|
119
|
+
const onAfterUnpublish = (0, _pubsub.createTopic)();
|
|
120
|
+
const onBeforeRequestChanges = (0, _pubsub.createTopic)();
|
|
121
|
+
const onAfterRequestChanges = (0, _pubsub.createTopic)();
|
|
122
|
+
const onBeforeRequestReview = (0, _pubsub.createTopic)();
|
|
123
|
+
const onAfterRequestReview = (0, _pubsub.createTopic)();
|
|
124
|
+
const onBeforeDelete = (0, _pubsub.createTopic)();
|
|
125
|
+
const onAfterDelete = (0, _pubsub.createTopic)();
|
|
126
|
+
const onBeforeDeleteRevision = (0, _pubsub.createTopic)();
|
|
127
|
+
const onAfterDeleteRevision = (0, _pubsub.createTopic)();
|
|
128
|
+
const onBeforeGet = (0, _pubsub.createTopic)();
|
|
129
|
+
const onBeforeList = (0, _pubsub.createTopic)();
|
|
130
|
+
/**
|
|
131
|
+
* We need to assign some default behaviors.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
(0, _beforeCreate.assignBeforeEntryCreate)({
|
|
135
|
+
context,
|
|
136
|
+
onBeforeCreate
|
|
137
|
+
});
|
|
138
|
+
(0, _beforeUpdate.assignBeforeEntryUpdate)({
|
|
139
|
+
context,
|
|
140
|
+
onBeforeUpdate
|
|
141
|
+
});
|
|
142
|
+
(0, _afterDelete.assignAfterEntryDelete)({
|
|
143
|
+
context,
|
|
144
|
+
onAfterDelete
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const checkEntryPermissions = check => {
|
|
148
|
+
return utils.checkPermissions(context, "cms.contentEntry", check);
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* A helper to delete the entire entry.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
const deleteEntry = async params => {
|
|
156
|
+
const {
|
|
157
|
+
model,
|
|
158
|
+
entry,
|
|
159
|
+
storageEntry
|
|
160
|
+
} = params;
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
await onBeforeDelete.publish({
|
|
164
|
+
entry,
|
|
165
|
+
model
|
|
166
|
+
});
|
|
167
|
+
await storageOperations.entries.delete(model, {
|
|
168
|
+
entry,
|
|
169
|
+
storageEntry
|
|
170
|
+
});
|
|
171
|
+
await onAfterDelete.publish({
|
|
172
|
+
entry,
|
|
173
|
+
model
|
|
174
|
+
});
|
|
175
|
+
} catch (ex) {
|
|
176
|
+
throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
|
|
177
|
+
entry
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* A helper to get entries by revision IDs
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
const getEntriesByIds = async (model, ids) => {
|
|
187
|
+
const permission = await checkEntryPermissions({
|
|
188
|
+
rwd: "r"
|
|
189
|
+
});
|
|
190
|
+
await utils.checkModelAccess(context, model);
|
|
191
|
+
const entries = await storageOperations.entries.getByIds(model, {
|
|
192
|
+
ids
|
|
193
|
+
});
|
|
194
|
+
return entries.filter(entry => utils.validateOwnership(context, permission, entry));
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
onBeforeEntryCreate: onBeforeCreate,
|
|
199
|
+
onAfterEntryCreate: onAfterCreate,
|
|
200
|
+
onBeforeEntryRevisionCreate: onBeforeCreateRevision,
|
|
201
|
+
onAfterEntryRevisionCreate: onAfterCreateRevision,
|
|
202
|
+
onBeforeEntryUpdate: onBeforeUpdate,
|
|
203
|
+
onAfterEntryUpdate: onAfterUpdate,
|
|
204
|
+
onBeforeEntryDelete: onBeforeDelete,
|
|
205
|
+
onAfterEntryDelete: onAfterDelete,
|
|
206
|
+
onBeforeEntryRevisionDelete: onBeforeDeleteRevision,
|
|
207
|
+
onAfterEntryRevisionDelete: onAfterDeleteRevision,
|
|
208
|
+
onBeforeEntryPublish: onBeforePublish,
|
|
209
|
+
onAfterEntryPublish: onAfterPublish,
|
|
210
|
+
onBeforeEntryUnpublish: onBeforeUnpublish,
|
|
211
|
+
onAfterEntryUnpublish: onAfterUnpublish,
|
|
212
|
+
onBeforeEntryRequestChanges: onBeforeRequestChanges,
|
|
213
|
+
onAfterEntryRequestChanges: onAfterRequestChanges,
|
|
214
|
+
onBeforeEntryRequestReview: onBeforeRequestReview,
|
|
215
|
+
onAfterEntryRequestReview: onAfterRequestReview,
|
|
216
|
+
onBeforeEntryGet: onBeforeGet,
|
|
217
|
+
onBeforeEntryList: onBeforeList,
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Get entries by exact revision IDs from the database.
|
|
221
|
+
*/
|
|
222
|
+
getEntriesByIds: getEntriesByIds,
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Get a single entry by revision ID from the database.
|
|
226
|
+
*/
|
|
227
|
+
getEntryById: async (model, id) => {
|
|
228
|
+
const where = {
|
|
229
|
+
id
|
|
230
|
+
};
|
|
231
|
+
await onBeforeGet.publish({
|
|
232
|
+
where,
|
|
233
|
+
model
|
|
234
|
+
});
|
|
235
|
+
const [entry] = await getEntriesByIds(model, [where.id]);
|
|
236
|
+
|
|
237
|
+
if (!entry) {
|
|
238
|
+
throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return entry;
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get published revisions by entry IDs.
|
|
246
|
+
*/
|
|
247
|
+
getPublishedEntriesByIds: async (model, ids) => {
|
|
248
|
+
const permission = await checkEntryPermissions({
|
|
249
|
+
rwd: "r"
|
|
250
|
+
});
|
|
251
|
+
await utils.checkModelAccess(context, model);
|
|
252
|
+
const entries = await storageOperations.entries.getPublishedByIds(model, {
|
|
253
|
+
ids
|
|
254
|
+
});
|
|
255
|
+
return entries.filter(entry => utils.validateOwnership(context, permission, entry));
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get latest revisions by entry IDs.
|
|
260
|
+
*/
|
|
261
|
+
getLatestEntriesByIds: async (model, ids) => {
|
|
262
|
+
const permission = await checkEntryPermissions({
|
|
263
|
+
rwd: "r"
|
|
264
|
+
});
|
|
265
|
+
await utils.checkModelAccess(context, model);
|
|
266
|
+
const entries = await storageOperations.entries.getLatestByIds(model, {
|
|
267
|
+
ids
|
|
268
|
+
});
|
|
269
|
+
return entries.filter(entry => utils.validateOwnership(context, permission, entry));
|
|
270
|
+
},
|
|
271
|
+
getEntryRevisions: async (model, entryId) => {
|
|
272
|
+
return storageOperations.entries.getRevisions(model, {
|
|
273
|
+
id: entryId
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
getEntry: async (model, params) => {
|
|
277
|
+
await checkEntryPermissions({
|
|
278
|
+
rwd: "r"
|
|
279
|
+
});
|
|
280
|
+
const {
|
|
281
|
+
where,
|
|
282
|
+
sort
|
|
283
|
+
} = params;
|
|
284
|
+
await onBeforeGet.publish({
|
|
285
|
+
where,
|
|
286
|
+
model
|
|
287
|
+
});
|
|
288
|
+
const [items] = await context.cms.listEntries(model, {
|
|
289
|
+
where,
|
|
290
|
+
sort,
|
|
291
|
+
limit: 1
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
if (items.length === 0) {
|
|
295
|
+
throw new _handlerGraphql.NotFoundError(`Entry not found!`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return items[0];
|
|
299
|
+
},
|
|
300
|
+
listEntries: async (model, params) => {
|
|
301
|
+
const permission = await checkEntryPermissions({
|
|
302
|
+
rwd: "r"
|
|
303
|
+
});
|
|
304
|
+
await utils.checkModelAccess(context, model);
|
|
305
|
+
const where = params.where || {};
|
|
306
|
+
/**
|
|
307
|
+
* Possibly only get records which are owned by current user.
|
|
308
|
+
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
312
|
+
|
|
313
|
+
const listWhere = _objectSpread(_objectSpread({}, where), {}, {
|
|
314
|
+
tenant: where.tenant || getTenant().id,
|
|
315
|
+
locale: where.locale || getLocale().code
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
if (ownedBy !== undefined) {
|
|
319
|
+
listWhere.ownedBy = ownedBy;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
await onBeforeList.publish({
|
|
323
|
+
where: listWhere,
|
|
324
|
+
model
|
|
325
|
+
});
|
|
326
|
+
const {
|
|
327
|
+
hasMoreItems,
|
|
328
|
+
totalCount,
|
|
329
|
+
cursor,
|
|
330
|
+
items
|
|
331
|
+
} = await storageOperations.entries.list(model, _objectSpread(_objectSpread({}, params), {}, {
|
|
332
|
+
where: listWhere
|
|
333
|
+
}));
|
|
334
|
+
const meta = {
|
|
335
|
+
hasMoreItems,
|
|
336
|
+
totalCount,
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Cursor should be null if there are no more items to load.
|
|
340
|
+
* Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
|
|
341
|
+
*/
|
|
342
|
+
cursor: hasMoreItems ? cursor : null
|
|
343
|
+
};
|
|
344
|
+
return [items, meta];
|
|
345
|
+
},
|
|
346
|
+
listLatestEntries: async function (model, params) {
|
|
347
|
+
const where = params ? params.where : {};
|
|
348
|
+
return context.cms.listEntries(model, _objectSpread(_objectSpread({
|
|
349
|
+
sort: ["createdOn_DESC"]
|
|
350
|
+
}, params || {}), {}, {
|
|
351
|
+
where: _objectSpread(_objectSpread({}, where), {}, {
|
|
352
|
+
latest: true
|
|
353
|
+
})
|
|
354
|
+
}));
|
|
355
|
+
},
|
|
356
|
+
listPublishedEntries: async function (model, params) {
|
|
357
|
+
const where = params ? params.where : {};
|
|
358
|
+
return context.cms.listEntries(model, _objectSpread(_objectSpread({
|
|
359
|
+
sort: ["createdOn_DESC"]
|
|
360
|
+
}, params || {}), {}, {
|
|
361
|
+
where: _objectSpread(_objectSpread({}, where), {}, {
|
|
362
|
+
published: true
|
|
363
|
+
})
|
|
364
|
+
}));
|
|
365
|
+
},
|
|
366
|
+
createEntry: async (model, inputData) => {
|
|
367
|
+
await checkEntryPermissions({
|
|
368
|
+
rwd: "w"
|
|
369
|
+
});
|
|
370
|
+
await utils.checkModelAccess(context, model);
|
|
371
|
+
/**
|
|
372
|
+
* Make sure we only work with fields that are defined in the model.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
const input = cleanInputData(model, inputData);
|
|
376
|
+
await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
|
|
377
|
+
const identity = context.security.getIdentity();
|
|
378
|
+
const locale = context.cms.getLocale();
|
|
379
|
+
const owner = {
|
|
380
|
+
id: identity.id,
|
|
381
|
+
displayName: identity.displayName,
|
|
382
|
+
type: identity.type
|
|
383
|
+
};
|
|
384
|
+
const {
|
|
385
|
+
id,
|
|
386
|
+
entryId,
|
|
387
|
+
version
|
|
388
|
+
} = createEntryId(1);
|
|
389
|
+
const entry = {
|
|
390
|
+
webinyVersion: context.WEBINY_VERSION,
|
|
391
|
+
tenant: context.tenancy.getCurrentTenant().id,
|
|
392
|
+
entryId,
|
|
393
|
+
id,
|
|
394
|
+
modelId: model.modelId,
|
|
395
|
+
locale: locale.code,
|
|
396
|
+
createdOn: new Date().toISOString(),
|
|
397
|
+
savedOn: new Date().toISOString(),
|
|
398
|
+
createdBy: owner,
|
|
399
|
+
ownedBy: owner,
|
|
400
|
+
version,
|
|
401
|
+
locked: false,
|
|
402
|
+
status: STATUS_DRAFT,
|
|
403
|
+
values: input
|
|
404
|
+
};
|
|
405
|
+
let storageEntry = null;
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
await onBeforeCreate.publish({
|
|
409
|
+
entry,
|
|
410
|
+
input,
|
|
411
|
+
model
|
|
412
|
+
});
|
|
413
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
414
|
+
const result = await storageOperations.entries.create(model, {
|
|
415
|
+
input,
|
|
416
|
+
entry,
|
|
417
|
+
storageEntry
|
|
418
|
+
});
|
|
419
|
+
await onAfterCreate.publish({
|
|
420
|
+
entry,
|
|
421
|
+
storageEntry: result,
|
|
422
|
+
model,
|
|
423
|
+
input
|
|
424
|
+
});
|
|
425
|
+
return result;
|
|
426
|
+
} catch (ex) {
|
|
427
|
+
throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
|
|
428
|
+
error: ex,
|
|
429
|
+
input,
|
|
430
|
+
entry,
|
|
431
|
+
storageEntry
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
createEntryRevisionFrom: async (model, sourceId, inputData = {}) => {
|
|
436
|
+
const permission = await checkEntryPermissions({
|
|
437
|
+
rwd: "w"
|
|
438
|
+
});
|
|
439
|
+
await utils.checkModelAccess(context, model);
|
|
440
|
+
/**
|
|
441
|
+
* Make sure we only work with fields that are defined in the model.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
const input = cleanUpdatedInputData(model, inputData);
|
|
445
|
+
/**
|
|
446
|
+
* Entries are identified by a common parent ID + Revision number.
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
const [uniqueId] = sourceId.split("#");
|
|
450
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
451
|
+
id: sourceId
|
|
452
|
+
});
|
|
453
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
454
|
+
id: uniqueId
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
if (!originalStorageEntry) {
|
|
458
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* We need to convert data from DB to its original form before using it further.
|
|
462
|
+
*/
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
466
|
+
|
|
467
|
+
const values = _objectSpread(_objectSpread({}, originalEntry.values), input);
|
|
468
|
+
|
|
469
|
+
await (0, _entryDataValidation.validateModelEntryData)(context, model, values);
|
|
470
|
+
utils.checkOwnership(context, permission, originalEntry);
|
|
471
|
+
const latestEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, latestStorageEntry);
|
|
472
|
+
const identity = context.security.getIdentity();
|
|
473
|
+
const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
|
|
474
|
+
const {
|
|
475
|
+
id,
|
|
476
|
+
version: nextVersion
|
|
477
|
+
} = increaseEntryIdVersion(latestId);
|
|
478
|
+
|
|
479
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
480
|
+
id,
|
|
481
|
+
version: nextVersion,
|
|
482
|
+
savedOn: new Date().toISOString(),
|
|
483
|
+
createdOn: new Date().toISOString(),
|
|
484
|
+
createdBy: {
|
|
485
|
+
id: identity.id,
|
|
486
|
+
displayName: identity.displayName,
|
|
487
|
+
type: identity.type
|
|
488
|
+
},
|
|
489
|
+
locked: false,
|
|
490
|
+
publishedOn: null,
|
|
491
|
+
status: STATUS_DRAFT,
|
|
492
|
+
values
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
let storageEntry = undefined;
|
|
496
|
+
|
|
497
|
+
try {
|
|
498
|
+
await onBeforeCreateRevision.publish({
|
|
499
|
+
entry,
|
|
500
|
+
model
|
|
501
|
+
});
|
|
502
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
503
|
+
const result = await storageOperations.entries.createRevisionFrom(model, {
|
|
504
|
+
entry,
|
|
505
|
+
storageEntry,
|
|
506
|
+
originalEntry,
|
|
507
|
+
originalStorageEntry,
|
|
508
|
+
latestEntry,
|
|
509
|
+
latestStorageEntry
|
|
510
|
+
});
|
|
511
|
+
await onAfterCreateRevision.publish({
|
|
512
|
+
entry,
|
|
513
|
+
model,
|
|
514
|
+
storageEntry: result
|
|
515
|
+
});
|
|
516
|
+
return result;
|
|
517
|
+
} catch (ex) {
|
|
518
|
+
throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
|
|
519
|
+
error: ex,
|
|
520
|
+
entry,
|
|
521
|
+
storageEntry,
|
|
522
|
+
originalEntry,
|
|
523
|
+
originalStorageEntry
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
updateEntry: async (model, id, inputData) => {
|
|
528
|
+
const permission = await checkEntryPermissions({
|
|
529
|
+
rwd: "w"
|
|
530
|
+
});
|
|
531
|
+
await utils.checkModelAccess(context, model);
|
|
532
|
+
/**
|
|
533
|
+
* Make sure we only work with fields that are defined in the model.
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
const input = cleanInputData(model, inputData);
|
|
537
|
+
/**
|
|
538
|
+
* Validate data early. We don't want to query DB if input data is invalid.
|
|
539
|
+
*/
|
|
540
|
+
|
|
541
|
+
await (0, _entryDataValidation.validateModelEntryData)(context, model, input);
|
|
542
|
+
/**
|
|
543
|
+
* The entry we are going to update.
|
|
544
|
+
*/
|
|
545
|
+
|
|
546
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
547
|
+
id
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
if (!originalStorageEntry) {
|
|
551
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (originalStorageEntry.locked) {
|
|
555
|
+
throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
559
|
+
utils.checkOwnership(context, permission, originalEntry);
|
|
560
|
+
/**
|
|
561
|
+
* We always send the full entry to the hooks and storage operations update.
|
|
562
|
+
*/
|
|
563
|
+
|
|
564
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
565
|
+
savedOn: new Date().toISOString(),
|
|
566
|
+
values: _objectSpread(_objectSpread({}, originalEntry.values), input)
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
let storageEntry = undefined;
|
|
570
|
+
|
|
571
|
+
try {
|
|
572
|
+
await onBeforeUpdate.publish({
|
|
573
|
+
entry,
|
|
574
|
+
model,
|
|
575
|
+
input,
|
|
576
|
+
original: originalEntry
|
|
577
|
+
});
|
|
578
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
579
|
+
const result = await storageOperations.entries.update(model, {
|
|
580
|
+
originalEntry,
|
|
581
|
+
originalStorageEntry,
|
|
582
|
+
entry,
|
|
583
|
+
storageEntry,
|
|
584
|
+
input
|
|
585
|
+
});
|
|
586
|
+
await onAfterUpdate.publish({
|
|
587
|
+
entry,
|
|
588
|
+
storageEntry: result,
|
|
589
|
+
model,
|
|
590
|
+
input,
|
|
591
|
+
original: originalEntry
|
|
592
|
+
});
|
|
593
|
+
return result;
|
|
594
|
+
} catch (ex) {
|
|
595
|
+
throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
|
|
596
|
+
error: ex,
|
|
597
|
+
entry,
|
|
598
|
+
storageEntry,
|
|
599
|
+
originalEntry,
|
|
600
|
+
input
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
deleteEntryRevision: async (model, revisionId) => {
|
|
605
|
+
const permission = await checkEntryPermissions({
|
|
606
|
+
rwd: "d"
|
|
607
|
+
});
|
|
608
|
+
await utils.checkModelAccess(context, model);
|
|
609
|
+
const {
|
|
610
|
+
id: entryId,
|
|
611
|
+
version
|
|
612
|
+
} = (0, _utils2.parseIdentifier)(revisionId);
|
|
613
|
+
const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
|
|
614
|
+
id: revisionId
|
|
615
|
+
});
|
|
616
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
617
|
+
id: entryId
|
|
618
|
+
});
|
|
619
|
+
const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
|
|
620
|
+
entryId,
|
|
621
|
+
version
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
if (!storageEntryToDelete) {
|
|
625
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
utils.checkOwnership(context, permission, storageEntryToDelete);
|
|
629
|
+
const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
|
|
630
|
+
const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
|
|
631
|
+
/**
|
|
632
|
+
* If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
|
|
633
|
+
* At this point deleteRevision hooks are not fired.
|
|
634
|
+
*/
|
|
635
|
+
|
|
636
|
+
if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
|
|
637
|
+
return await deleteEntry({
|
|
638
|
+
model,
|
|
639
|
+
entry: entryToDelete,
|
|
640
|
+
storageEntry: storageEntryToDelete
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* If targeted record is latest entry revision, set the previous one as the new latest
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
let entryToSetAsLatest = null;
|
|
649
|
+
let storageEntryToSetAsLatest = null;
|
|
650
|
+
|
|
651
|
+
if (entryToDelete.id === latestEntryRevisionId) {
|
|
652
|
+
entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
|
|
653
|
+
storageEntryToSetAsLatest = previousStorageEntry;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
try {
|
|
657
|
+
await onBeforeDeleteRevision.publish({
|
|
658
|
+
entry: entryToDelete,
|
|
659
|
+
model
|
|
660
|
+
});
|
|
661
|
+
await storageOperations.entries.deleteRevision(model, {
|
|
662
|
+
entryToDelete,
|
|
663
|
+
storageEntryToDelete,
|
|
664
|
+
entryToSetAsLatest,
|
|
665
|
+
storageEntryToSetAsLatest
|
|
666
|
+
});
|
|
667
|
+
await onAfterDeleteRevision.publish({
|
|
668
|
+
entry: entryToDelete,
|
|
669
|
+
model
|
|
670
|
+
});
|
|
671
|
+
} catch (ex) {
|
|
672
|
+
throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
|
|
673
|
+
error: ex,
|
|
674
|
+
entryToDelete,
|
|
675
|
+
storageEntryToDelete,
|
|
676
|
+
entryToSetAsLatest,
|
|
677
|
+
storageEntryToSetAsLatest
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
deleteEntry: async (model, entryId) => {
|
|
682
|
+
const permission = await checkEntryPermissions({
|
|
683
|
+
rwd: "d"
|
|
684
|
+
});
|
|
685
|
+
await utils.checkModelAccess(context, model);
|
|
686
|
+
const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
687
|
+
id: entryId
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
if (!storageEntry) {
|
|
691
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
utils.checkOwnership(context, permission, storageEntry);
|
|
695
|
+
const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
|
|
696
|
+
return await deleteEntry({
|
|
697
|
+
model,
|
|
698
|
+
entry,
|
|
699
|
+
storageEntry
|
|
700
|
+
});
|
|
701
|
+
},
|
|
702
|
+
publishEntry: async (model, id) => {
|
|
703
|
+
const permission = await checkEntryPermissions({
|
|
704
|
+
pw: "p"
|
|
705
|
+
});
|
|
706
|
+
await utils.checkModelAccess(context, model);
|
|
707
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
708
|
+
id
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
if (!originalStorageEntry) {
|
|
712
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
utils.checkOwnership(context, permission, originalStorageEntry);
|
|
716
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
717
|
+
const currentDate = new Date().toISOString();
|
|
718
|
+
|
|
719
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
720
|
+
status: STATUS_PUBLISHED,
|
|
721
|
+
locked: true,
|
|
722
|
+
savedOn: currentDate,
|
|
723
|
+
publishedOn: currentDate
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
let storageEntry = undefined;
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
await onBeforePublish.publish({
|
|
730
|
+
entry,
|
|
731
|
+
model
|
|
732
|
+
});
|
|
733
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
734
|
+
const result = await storageOperations.entries.publish(model, {
|
|
735
|
+
entry,
|
|
736
|
+
storageEntry,
|
|
737
|
+
originalEntry,
|
|
738
|
+
originalStorageEntry
|
|
739
|
+
});
|
|
740
|
+
await onAfterPublish.publish({
|
|
741
|
+
entry,
|
|
742
|
+
storageEntry: result,
|
|
743
|
+
model
|
|
744
|
+
});
|
|
745
|
+
return result;
|
|
746
|
+
} catch (ex) {
|
|
747
|
+
throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
|
|
748
|
+
error: ex,
|
|
749
|
+
entry,
|
|
750
|
+
storageEntry,
|
|
751
|
+
originalEntry,
|
|
752
|
+
originalStorageEntry
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
requestEntryChanges: async (model, id) => {
|
|
757
|
+
const permission = await checkEntryPermissions({
|
|
758
|
+
pw: "c"
|
|
759
|
+
});
|
|
760
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
761
|
+
id
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
if (!originalStorageEntry) {
|
|
765
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
769
|
+
|
|
770
|
+
if (originalEntry.status !== STATUS_REVIEW_REQUESTED) {
|
|
771
|
+
throw new _error.default("Cannot request changes on an entry that's not under review.", "ENTRY_NOT_UNDER_REVIEW");
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
const identity = context.security.getIdentity();
|
|
775
|
+
|
|
776
|
+
if (originalEntry.ownedBy.id === identity.id) {
|
|
777
|
+
throw new _error.default("You cannot request changes on your own entry.", "CANNOT_REQUEST_CHANGES_ON_OWN_ENTRY");
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
utils.checkOwnership(context, permission, originalEntry);
|
|
781
|
+
|
|
782
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
783
|
+
status: STATUS_CHANGES_REQUESTED
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
let storageEntry = undefined;
|
|
787
|
+
|
|
788
|
+
try {
|
|
789
|
+
await onBeforeRequestChanges.publish({
|
|
790
|
+
entry,
|
|
791
|
+
model
|
|
792
|
+
});
|
|
793
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
794
|
+
const result = await storageOperations.entries.requestChanges(model, {
|
|
795
|
+
originalEntry,
|
|
796
|
+
originalStorageEntry,
|
|
797
|
+
entry,
|
|
798
|
+
storageEntry
|
|
799
|
+
});
|
|
800
|
+
await onAfterRequestChanges.publish({
|
|
801
|
+
entry,
|
|
802
|
+
storageEntry: result,
|
|
803
|
+
model
|
|
804
|
+
});
|
|
805
|
+
return result;
|
|
806
|
+
} catch (ex) {
|
|
807
|
+
throw new _error.default(ex.message || "Could not request changes for the entry.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
808
|
+
entry,
|
|
809
|
+
originalEntry
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
requestEntryReview: async (model, id) => {
|
|
814
|
+
const permission = await checkEntryPermissions({
|
|
815
|
+
pw: "r"
|
|
816
|
+
});
|
|
817
|
+
const [entryId] = id.split("#");
|
|
818
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
819
|
+
id
|
|
820
|
+
});
|
|
821
|
+
const latestEntryRevision = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
822
|
+
id: entryId
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
if (!originalStorageEntry) {
|
|
826
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
827
|
+
} else if (!latestEntryRevision) {
|
|
828
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" does not have latest record`);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
832
|
+
const allowedStatuses = [STATUS_DRAFT, STATUS_CHANGES_REQUESTED];
|
|
833
|
+
|
|
834
|
+
if (!allowedStatuses.includes(originalEntry.status)) {
|
|
835
|
+
throw new _error.default("Cannot request review - entry is not a draft nor was a change request issued.", "REQUEST_REVIEW_ERROR", {
|
|
836
|
+
entry: originalEntry
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
utils.checkOwnership(context, permission, originalEntry);
|
|
841
|
+
|
|
842
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
843
|
+
status: STATUS_REVIEW_REQUESTED
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
let storageEntry = undefined;
|
|
847
|
+
|
|
848
|
+
try {
|
|
849
|
+
await onBeforeRequestReview.publish({
|
|
850
|
+
entry,
|
|
851
|
+
model
|
|
852
|
+
});
|
|
853
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
854
|
+
const result = await storageOperations.entries.requestReview(model, {
|
|
855
|
+
originalEntry,
|
|
856
|
+
originalStorageEntry,
|
|
857
|
+
entry,
|
|
858
|
+
storageEntry
|
|
859
|
+
});
|
|
860
|
+
await onAfterRequestReview.publish({
|
|
861
|
+
entry,
|
|
862
|
+
storageEntry: result,
|
|
863
|
+
model
|
|
864
|
+
});
|
|
865
|
+
return result;
|
|
866
|
+
} catch (ex) {
|
|
867
|
+
throw new _error.default(ex.message || "Could not request review on the entry.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
868
|
+
originalEntry,
|
|
869
|
+
entry
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
unpublishEntry: async (model, id) => {
|
|
874
|
+
const permission = await checkEntryPermissions({
|
|
875
|
+
pw: "u"
|
|
876
|
+
});
|
|
877
|
+
const [entryId] = id.split("#");
|
|
878
|
+
const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
|
|
879
|
+
id: entryId
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
if (!originalStorageEntry) {
|
|
883
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
if (originalStorageEntry.id !== id) {
|
|
887
|
+
throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
|
|
888
|
+
entry: originalStorageEntry
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
utils.checkOwnership(context, permission, originalStorageEntry);
|
|
893
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
894
|
+
|
|
895
|
+
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
896
|
+
status: STATUS_UNPUBLISHED
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
let storageEntry = undefined;
|
|
900
|
+
|
|
901
|
+
try {
|
|
902
|
+
await onBeforeUnpublish.publish({
|
|
903
|
+
entry,
|
|
904
|
+
model
|
|
905
|
+
});
|
|
906
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
907
|
+
const result = await storageOperations.entries.unpublish(model, {
|
|
908
|
+
originalEntry,
|
|
909
|
+
originalStorageEntry,
|
|
910
|
+
entry,
|
|
911
|
+
storageEntry
|
|
912
|
+
});
|
|
913
|
+
await onAfterUnpublish.publish({
|
|
914
|
+
entry,
|
|
915
|
+
storageEntry: result,
|
|
916
|
+
model
|
|
917
|
+
});
|
|
918
|
+
return result;
|
|
919
|
+
} catch (ex) {
|
|
920
|
+
throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
|
|
921
|
+
originalEntry,
|
|
922
|
+
originalStorageEntry,
|
|
923
|
+
entry,
|
|
924
|
+
storageEntry
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
exports.createContentEntryCrud = createContentEntryCrud;
|