@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,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.validateModelEntryData = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const validateValue = async (args, fieldValidators, value) => {
|
|
13
|
+
if (!fieldValidators) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
validatorList,
|
|
19
|
+
context,
|
|
20
|
+
field,
|
|
21
|
+
contentModel
|
|
22
|
+
} = args;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
for (const fieldValidator of fieldValidators) {
|
|
26
|
+
const name = fieldValidator.name;
|
|
27
|
+
const validations = validatorList[name];
|
|
28
|
+
|
|
29
|
+
if (!validations || validations.length === 0) {
|
|
30
|
+
return `There are no "${name}" validators defined.`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const validate of validations) {
|
|
34
|
+
const result = await validate({
|
|
35
|
+
value,
|
|
36
|
+
context,
|
|
37
|
+
validator: fieldValidator,
|
|
38
|
+
field,
|
|
39
|
+
contentModel
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!result) {
|
|
43
|
+
return fieldValidator.message;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} catch (ex) {
|
|
48
|
+
return ex.message;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const validatePredefinedValue = (field, value) => {
|
|
55
|
+
const {
|
|
56
|
+
enabled = false,
|
|
57
|
+
values: predefinedValues = []
|
|
58
|
+
} = field.predefinedValues || {};
|
|
59
|
+
|
|
60
|
+
if (!enabled) {
|
|
61
|
+
return null;
|
|
62
|
+
} else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {
|
|
63
|
+
return "Missing predefined values to validate against.";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const predefinedValue of predefinedValues) {
|
|
67
|
+
// console.log(field.fieldId, predefinedValue.value, value, predefinedValue.value == value);
|
|
68
|
+
if (predefinedValue.value == value) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return "Value sent does not match any of the available predefined values.";
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* When multiple values is selected we must run validations on the array containing the values
|
|
77
|
+
* And then on each value in the array
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const runFieldMultipleValuesValidations = async args => {
|
|
82
|
+
const {
|
|
83
|
+
field,
|
|
84
|
+
data
|
|
85
|
+
} = args;
|
|
86
|
+
const values = data[field.fieldId];
|
|
87
|
+
|
|
88
|
+
if (Array.isArray(values) === false) {
|
|
89
|
+
return `Value of the field "${field.fieldId}" is not an array.`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const valuesError = await validateValue(args, field.listValidation || [], values);
|
|
93
|
+
|
|
94
|
+
if (valuesError) {
|
|
95
|
+
return valuesError;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const value of values) {
|
|
99
|
+
const valueError = await validateValue(args, field.validation || [], value);
|
|
100
|
+
|
|
101
|
+
if (valueError) {
|
|
102
|
+
return valueError;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const predefinedValueError = validatePredefinedValue(field, value);
|
|
106
|
+
|
|
107
|
+
if (predefinedValueError) {
|
|
108
|
+
return predefinedValueError;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Runs validation on given value.
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const runFieldValueValidations = async args => {
|
|
120
|
+
const {
|
|
121
|
+
data,
|
|
122
|
+
field
|
|
123
|
+
} = args;
|
|
124
|
+
const value = data[field.fieldId];
|
|
125
|
+
const error = await validateValue(args, field.validation, value);
|
|
126
|
+
|
|
127
|
+
if (error) {
|
|
128
|
+
return error;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return validatePredefinedValue(field, value);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const execValidation = async args => {
|
|
135
|
+
if (args.field.multipleValues) {
|
|
136
|
+
return await runFieldMultipleValuesValidations(args);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return await runFieldValueValidations(args);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const validateModelEntryData = async (context, contentModel, data) => {
|
|
143
|
+
/**
|
|
144
|
+
* To later simplify searching for the validations we map them to a name.
|
|
145
|
+
* @see CmsModelFieldValidatorPlugin.validator.validate
|
|
146
|
+
*/
|
|
147
|
+
const validatorList = context.plugins.byType("cms-model-field-validator").reduce((acc, plugin) => {
|
|
148
|
+
const name = plugin.validator.name;
|
|
149
|
+
|
|
150
|
+
if (!acc[name]) {
|
|
151
|
+
acc[name] = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
acc[name].push(plugin.validator.validate);
|
|
155
|
+
return acc;
|
|
156
|
+
}, {});
|
|
157
|
+
/**
|
|
158
|
+
* Loop through model fields and validate the corresponding data.
|
|
159
|
+
* Run validation only if the field has validation configured.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
const invalidFields = [];
|
|
163
|
+
|
|
164
|
+
for (const field of contentModel.fields) {
|
|
165
|
+
const error = await execValidation({
|
|
166
|
+
contentModel,
|
|
167
|
+
validatorList,
|
|
168
|
+
field,
|
|
169
|
+
data,
|
|
170
|
+
context
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!error) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
invalidFields.push({
|
|
178
|
+
fieldId: field.fieldId,
|
|
179
|
+
error
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (invalidFields.length > 0) {
|
|
184
|
+
throw new _error.default("Validation failed.", "VALIDATION_FAILED", invalidFields);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
exports.validateModelEntryData = validateModelEntryData;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CmsEntry, CmsModel, CmsContext } from "../../../../types";
|
|
2
|
+
export interface MarkLockedFieldsParams {
|
|
3
|
+
model: CmsModel;
|
|
4
|
+
entry: CmsEntry;
|
|
5
|
+
context: CmsContext;
|
|
6
|
+
}
|
|
7
|
+
export declare const markLockedFields: (params: MarkLockedFieldsParams) => Promise<void>;
|
|
8
|
+
export interface MarkFieldsUnlockedParams {
|
|
9
|
+
context: CmsContext;
|
|
10
|
+
model: CmsModel;
|
|
11
|
+
}
|
|
12
|
+
export declare const markUnlockedFields: (params: MarkFieldsUnlockedParams) => Promise<void>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.markUnlockedFields = exports.markLockedFields = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _CmsModelPlugin = require("../../CmsModelPlugin");
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const markLockedFields = async params => {
|
|
21
|
+
const {
|
|
22
|
+
model,
|
|
23
|
+
context
|
|
24
|
+
} = params;
|
|
25
|
+
/**
|
|
26
|
+
* If the model is registered via a plugin, we don't need do process anything.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
30
|
+
|
|
31
|
+
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
|
|
36
|
+
const existingLockedFields = model.lockedFields || [];
|
|
37
|
+
const lockedFields = [];
|
|
38
|
+
|
|
39
|
+
for (const field of model.fields) {
|
|
40
|
+
const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.fieldId);
|
|
41
|
+
|
|
42
|
+
if (alreadyLocked) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let lockedFieldData = {};
|
|
47
|
+
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === field.type);
|
|
48
|
+
|
|
49
|
+
for (const plugin of lockedFieldPlugins) {
|
|
50
|
+
if (typeof plugin.getLockedFieldData !== "function") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const data = plugin.getLockedFieldData({
|
|
55
|
+
field
|
|
56
|
+
});
|
|
57
|
+
lockedFieldData = _objectSpread(_objectSpread({}, lockedFieldData), data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
lockedFields.push(_objectSpread({
|
|
61
|
+
fieldId: field.fieldId,
|
|
62
|
+
multipleValues: field.multipleValues,
|
|
63
|
+
type: field.type
|
|
64
|
+
}, lockedFieldData));
|
|
65
|
+
} // no need to update anything if no locked fields were added
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (lockedFields.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const newLockedFields = existingLockedFields.concat(lockedFields);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await context.cms.updateModelDirect({
|
|
76
|
+
original: model,
|
|
77
|
+
model: _objectSpread(_objectSpread({}, model), {}, {
|
|
78
|
+
lockedFields: newLockedFields
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
model.lockedFields = newLockedFields;
|
|
82
|
+
} catch (ex) {
|
|
83
|
+
throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", ex);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
exports.markLockedFields = markLockedFields;
|
|
88
|
+
|
|
89
|
+
const markUnlockedFields = async params => {
|
|
90
|
+
const {
|
|
91
|
+
context,
|
|
92
|
+
model
|
|
93
|
+
} = params;
|
|
94
|
+
/**
|
|
95
|
+
* If the model is registered via a plugin, we don't need do process anything.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
99
|
+
|
|
100
|
+
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
await context.cms.updateModelDirect({
|
|
106
|
+
original: model,
|
|
107
|
+
model: _objectSpread(_objectSpread({}, model), {}, {
|
|
108
|
+
lockedFields: []
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
model.lockedFields = [];
|
|
112
|
+
} catch (ex) {
|
|
113
|
+
throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", ex);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.markUnlockedFields = markUnlockedFields;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CmsEntryContext, CmsContext, HeadlessCmsStorageOperations } from "../../../types";
|
|
2
|
+
import { I18NLocale } from "@webiny/api-i18n/types";
|
|
3
|
+
import { Tenant } from "@webiny/api-tenancy/types";
|
|
4
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
5
|
+
export declare const STATUS_DRAFT = "draft";
|
|
6
|
+
export declare const STATUS_PUBLISHED = "published";
|
|
7
|
+
export declare const STATUS_UNPUBLISHED = "unpublished";
|
|
8
|
+
export declare const STATUS_CHANGES_REQUESTED = "changesRequested";
|
|
9
|
+
export declare const STATUS_REVIEW_REQUESTED = "reviewRequested";
|
|
10
|
+
export interface Params {
|
|
11
|
+
storageOperations: HeadlessCmsStorageOperations;
|
|
12
|
+
context: CmsContext;
|
|
13
|
+
getTenant: () => Tenant;
|
|
14
|
+
getLocale: () => I18NLocale;
|
|
15
|
+
getIdentity: () => SecurityIdentity;
|
|
16
|
+
}
|
|
17
|
+
export declare const createContentEntryCrud: (params: Params) => CmsEntryContext;
|