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