@webiny/api-headless-cms 6.5.2-beta.3 → 6.5.2-beta.5
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/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/package.json +18 -18
|
@@ -140,7 +140,7 @@ class CreateEntryRevisionFromDataFactoryImpl {
|
|
|
140
140
|
createdOn: getDate(metaInput.createdOn, latestStorageEntry.createdOn),
|
|
141
141
|
savedOn: getDate(metaInput.savedOn, entryLevelSaved.savedOn),
|
|
142
142
|
modifiedOn: getDate(metaInput.modifiedOn, entryLevelSaved.modifiedOn),
|
|
143
|
-
createdBy:
|
|
143
|
+
createdBy: latestStorageEntry.createdBy,
|
|
144
144
|
savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy),
|
|
145
145
|
modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),
|
|
146
146
|
...entryLevelPublishingMetaFields,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { canOverrideMetaFields } from \"../canOverrideMetaFields.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly accessControl: AccessControl.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestStorageEntry = latestResult.value;\n\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, initialValues);\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n // Security: meta field overrides (createdBy, ...) are ignored for identities limited to\n // their own entries, otherwise they could take over (or hand over) an entry.\n const metaInput: Partial<CreateCmsEntryInput<TValues>> = (await canOverrideMetaFields({\n identityContext: this.identityContext,\n accessControl: this.accessControl,\n model\n }))\n ? rawInput\n : {};\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(metaInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(metaInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(metaInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(metaInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n metaInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n metaInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n metaInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n metaInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(\n metaInput.revisionLastPublishedOn,\n currentDateTime\n ),\n revisionFirstPublishedBy: getIdentity(\n metaInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n metaInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n metaInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n metaInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(metaInput.lastPublishedBy, currentIdentity)\n };\n }\n\n /**\n * Creating a revision without changing the entry's content (e.g. \"New revision\" in the\n * revisions list, or saving a published entry without editing anything) is not a\n * modification, so the entry-level saved/modified meta fields are kept. The new revision\n * is compared with the latest revision, not the source revision: creating a revision from\n * an older one reverts the content, which is a change. Explicitly provided meta field\n * values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: latestStorageEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestStorageEntry.savedOn,\n modifiedOn: latestStorageEntry.modifiedOn,\n savedBy: latestStorageEntry.savedBy,\n modifiedBy: latestStorageEntry.modifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(metaInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(metaInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(metaInput.modifiedOn, entryLevelSaved.modifiedOn),\n createdBy: getIdentity(metaInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(metaInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(metaInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(metaInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(metaInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(metaInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(metaInput.revisionModifiedBy, null),\n revisionDescription: undefined,\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n AccessControl,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase\n ]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","accessControl","modelToAstConverter","getLatestRevision","sourceId","model","rawInput","originalEntry","options","latestResult","Result","latestStorageEntry","initialValues","mapAndCleanUpdatedInputData","modelAst","ensureItemIds","invalidFields","validateModelEntryData","EntryValidationError","values","referenceFieldsMapping","latestId","nextVersion","metaInput","canOverrideMetaFields","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","contentChanged","hasEntryContentChanged","entryLevelSaved","entry","undefined","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","AccessControl","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAE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AAe,EAAEG;YACpD,oBAAoBW,QAAQd,UAAU,kBAAkB,EAAE;YAC1D,mBAAmBe,YAAYf,UAAU,iBAAiB,EAAEE;YAC5D,iBAAiBa,YAAYf,UAAU,eAAe,EAAEE;YACxD,oBAAoBa,YAAYf,UAAU,kBAAkB,EAAE;YAC9D,qBAAqBqB;YACrB,GAAGR,iCAAiC;YACpCD;YACAP;YACAT;YACA,QAAQ0B,UAAU;gBACd,OAAOvC;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAOG,OAAO,EAAE,CAAC;YACbiC;YACA,OAAO;gBACH,GAAGrC,QAAQ;gBACX,QAAQwC,gBAAgB3B;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAM4B,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBnD;IAChB,cAAc;QACVoD;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { canOverrideMetaFields } from \"../canOverrideMetaFields.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly accessControl: AccessControl.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestStorageEntry = latestResult.value;\n\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, initialValues);\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n // Security: meta field overrides (createdBy, ...) are ignored for identities limited to\n // their own entries, otherwise they could take over (or hand over) an entry.\n const metaInput: Partial<CreateCmsEntryInput<TValues>> = (await canOverrideMetaFields({\n identityContext: this.identityContext,\n accessControl: this.accessControl,\n model\n }))\n ? rawInput\n : {};\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(metaInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(metaInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(metaInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(metaInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n metaInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n metaInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n metaInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n metaInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(\n metaInput.revisionLastPublishedOn,\n currentDateTime\n ),\n revisionFirstPublishedBy: getIdentity(\n metaInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n metaInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n metaInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n metaInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(metaInput.lastPublishedBy, currentIdentity)\n };\n }\n\n /**\n * Creating a revision without changing the entry's content (e.g. \"New revision\" in the\n * revisions list, or saving a published entry without editing anything) is not a\n * modification, so the entry-level saved/modified meta fields are kept. The new revision\n * is compared with the latest revision, not the source revision: creating a revision from\n * an older one reverts the content, which is a change. Explicitly provided meta field\n * values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: latestStorageEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestStorageEntry.savedOn,\n modifiedOn: latestStorageEntry.modifiedOn,\n savedBy: latestStorageEntry.savedBy,\n modifiedBy: latestStorageEntry.modifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(metaInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(metaInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(metaInput.modifiedOn, entryLevelSaved.modifiedOn),\n // The entry owner cannot be changed through a new revision.\n createdBy: latestStorageEntry.createdBy,\n savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(metaInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(metaInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(metaInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(metaInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(metaInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(metaInput.revisionModifiedBy, null),\n revisionDescription: undefined,\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n AccessControl,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase\n ]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","accessControl","modelToAstConverter","getLatestRevision","sourceId","model","rawInput","originalEntry","options","latestResult","Result","latestStorageEntry","initialValues","mapAndCleanUpdatedInputData","modelAst","ensureItemIds","invalidFields","validateModelEntryData","EntryValidationError","values","referenceFieldsMapping","latestId","nextVersion","metaInput","canOverrideMetaFields","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","contentChanged","hasEntryContentChanged","entryLevelSaved","entry","undefined","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","AccessControl","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAEA,MAAMI;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,aAAsC,EACtCC,mBAAkD,EAClDC,iBAA8D,CACjF;aALmBJ,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;aACAC,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,QAAgB,EAChBC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAo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AAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAOG,OAAO,EAAE,CAAC;YACbiC;YACA,OAAO;gBACH,GAAGrC,QAAQ;gBACX,QAAQwC,gBAAgB3B;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAM4B,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBnD;IAChB,cAAc;QACVoD;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js
CHANGED
|
@@ -112,7 +112,7 @@ class UpdateEntryDataFactoryImpl {
|
|
|
112
112
|
restoredOn: getDate(metaInput.restoredOn, latestEntry.restoredOn),
|
|
113
113
|
firstPublishedOn: getDate(metaInput.firstPublishedOn, latestEntry.firstPublishedOn),
|
|
114
114
|
lastPublishedOn: getDate(metaInput.lastPublishedOn, latestEntry.lastPublishedOn),
|
|
115
|
-
createdBy:
|
|
115
|
+
createdBy: latestEntry.createdBy,
|
|
116
116
|
savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy),
|
|
117
117
|
modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),
|
|
118
118
|
deletedBy: getIdentity(metaInput.deletedBy, latestEntry.deletedBy),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { canOverrideMetaFields } from \"../canOverrideMetaFields.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestEntry = latestResult.value;\n\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, mergedValues);\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n // Security: meta field overrides (createdBy, ...) are ignored for identities limited to\n // their own entries, otherwise they could take over (or hand over) an entry.\n const metaInput: Partial<UpdateCmsEntryInput<TValues>> = (await canOverrideMetaFields({\n identityContext: this.identityContext,\n accessControl: this.accessControl,\n model\n }))\n ? rawInput\n : {};\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n /**\n * Saving without changing the content (e.g. clicking \"Save\" without editing anything) is\n * not a modification, so the saved/modified meta fields are kept. Entry-level values are\n * then taken from the latest revision, because storage copies them onto the latest\n * revision when a non-latest revision is updated. Revision-level values are this\n * revision's own. Explicitly provided meta field values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: originalEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestEntry.savedOn,\n modifiedOn: latestEntry.modifiedOn,\n savedBy: latestEntry.savedBy,\n modifiedBy: latestEntry.modifiedBy\n };\n\n const revisionLevelSaved = contentChanged\n ? {\n revisionSavedOn: currentDateTime,\n revisionModifiedOn: currentDateTime,\n revisionSavedBy: currentIdentity,\n revisionModifiedBy: currentIdentity\n }\n : {\n revisionSavedOn: originalEntry.revisionSavedOn,\n revisionModifiedOn: originalEntry.revisionModifiedOn,\n revisionSavedBy: originalEntry.revisionSavedBy,\n revisionModifiedBy: originalEntry.revisionModifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(\n metaInput.revisionCreatedOn,\n originalEntry.revisionCreatedOn\n ),\n revisionModifiedOn: getDate(\n metaInput.revisionModifiedOn,\n revisionLevelSaved.revisionModifiedOn\n ),\n revisionSavedOn: getDate(metaInput.revisionSavedOn, revisionLevelSaved.revisionSavedOn),\n revisionDeletedOn: getDate(\n metaInput.revisionDeletedOn,\n originalEntry.revisionDeletedOn\n ),\n revisionRestoredOn: getDate(\n metaInput.revisionRestoredOn,\n originalEntry.revisionRestoredOn\n ),\n revisionFirstPublishedOn: getDate(\n metaInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n metaInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n metaInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(\n metaInput.revisionModifiedBy,\n revisionLevelSaved.revisionModifiedBy\n ),\n revisionSavedBy: getIdentity(\n metaInput.revisionSavedBy,\n revisionLevelSaved.revisionSavedBy\n )!,\n revisionDeletedBy: getIdentity(\n metaInput.revisionDeletedBy,\n originalEntry.revisionDeletedBy\n ),\n revisionRestoredBy: getIdentity(\n metaInput.revisionRestoredBy,\n originalEntry.revisionRestoredBy\n ),\n revisionFirstPublishedBy: getIdentity(\n metaInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n metaInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(metaInput.createdOn, latestEntry.createdOn),\n savedOn: getDate(metaInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(metaInput.modifiedOn, entryLevelSaved.modifiedOn),\n deletedOn: getDate(metaInput.deletedOn, latestEntry.deletedOn),\n restoredOn: getDate(metaInput.restoredOn, latestEntry.restoredOn),\n firstPublishedOn: getDate(metaInput.firstPublishedOn, latestEntry.firstPublishedOn),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, latestEntry.lastPublishedOn),\n createdBy: getIdentity(metaInput.createdBy, latestEntry.createdBy)!,\n savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),\n deletedBy: getIdentity(metaInput.deletedBy, latestEntry.deletedBy),\n restoredBy: getIdentity(metaInput.restoredBy, latestEntry.restoredBy),\n firstPublishedBy: getIdentity(metaInput.firstPublishedBy, latestEntry.firstPublishedBy),\n lastPublishedBy: getIdentity(metaInput.lastPublishedBy, latestEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase,\n AccessControl\n ]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","modelToAstConverter","getLatestRevision","accessControl","model","rawInput","originalEntry","options","latestResult","Result","latestEntry","cleanedValues","mapAndCleanUpdatedInputData","invalidFields","validateModelEntryData","EntryValidationError","mergedValues","modelAst","ensureItemIds","values","referenceFieldsMapping","metaInput","canOverrideMetaFields","currentIdentity","currentDateTime","Date","contentChanged","hasEntryContentChanged","entryLevelSaved","revisionLevelSaved","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase","AccessControl"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBAAmB,QAAQ,CAACE,UAAWA,SAA4B;AAG9E,MAAMC;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,mBAAkD,EAClDC,iBAA8D,EAC9DC,aAAsC,CACzD;aALmBJ,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAoC,EACO;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUJ,OAAO;YACtE,IAAIE,cAAc,OAAO;QAC7B;QACA,IAAIE,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,cAAcF,aAAa,KAAK;QAEtC,MAAMG,gBAAgBC,4BAClBR,OACAC,UAAU,UAAW,CAAC;QAG1B,MAAMQ,gBAAgB,MAAMC,uBAAuB;YAC/C,SAAS,IAAI,CAAC,UAAU;YACxBV;YACA,QAAQO;YACR,OAAOL;YACP,gBAAgBC,SAAS;QAC7B;QACA,IAAIM,cAAc,MAAM,GAAG,GACvB,OAAOJ,OAAO,IAAI,CAAC,IAAIM,qBAAqB,sBAAsBF;QAGtE,MAAMG,eAAwB;YAC1B,GAAGV,cAAc,MAAM;YACvB,GAAGK,aAAa;QACpB;QAEA,MAAMM,WAAW,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAACb;QAChD,MAAMc,cA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AYX,UAAU,eAAe,EAAEX,YAAY,eAAe;YACnFS;YACA,QAAQvB,qBAAqBU,cAAc,MAAM;YACjD,QAAQ2B,UAAU;gBACd,OAAO5B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW4B,aAAa;gBAAE,WAAW7B,SAAS,SAAS;YAAC,GAAGC;QAC/D;QAEA,MAAM6B,WAAW9B,SAAS,eAAe,EAAE;QAC3C,IAAI8B,UACAL,MAAM,QAAQ,GAAG;YACbK;QACJ;QAGJ,OAAO1B,OAAO,EAAE,CAAC;YACbqB;YACA,OAAO;gBACH,GAAGzB,QAAQ;gBACX,QAAQ+B,gBAAgBjB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMkB,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { canOverrideMetaFields } from \"../canOverrideMetaFields.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestEntry = latestResult.value;\n\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, mergedValues);\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n // Security: meta field overrides (createdBy, ...) are ignored for identities limited to\n // their own entries, otherwise they could take over (or hand over) an entry.\n const metaInput: Partial<UpdateCmsEntryInput<TValues>> = (await canOverrideMetaFields({\n identityContext: this.identityContext,\n accessControl: this.accessControl,\n model\n }))\n ? rawInput\n : {};\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n /**\n * Saving without changing the content (e.g. clicking \"Save\" without editing anything) is\n * not a modification, so the saved/modified meta fields are kept. Entry-level values are\n * then taken from the latest revision, because storage copies them onto the latest\n * revision when a non-latest revision is updated. Revision-level values are this\n * revision's own. Explicitly provided meta field values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: originalEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestEntry.savedOn,\n modifiedOn: latestEntry.modifiedOn,\n savedBy: latestEntry.savedBy,\n modifiedBy: latestEntry.modifiedBy\n };\n\n const revisionLevelSaved = contentChanged\n ? {\n revisionSavedOn: currentDateTime,\n revisionModifiedOn: currentDateTime,\n revisionSavedBy: currentIdentity,\n revisionModifiedBy: currentIdentity\n }\n : {\n revisionSavedOn: originalEntry.revisionSavedOn,\n revisionModifiedOn: originalEntry.revisionModifiedOn,\n revisionSavedBy: originalEntry.revisionSavedBy,\n revisionModifiedBy: originalEntry.revisionModifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(\n metaInput.revisionCreatedOn,\n originalEntry.revisionCreatedOn\n ),\n revisionModifiedOn: getDate(\n metaInput.revisionModifiedOn,\n revisionLevelSaved.revisionModifiedOn\n ),\n revisionSavedOn: getDate(metaInput.revisionSavedOn, revisionLevelSaved.revisionSavedOn),\n revisionDeletedOn: getDate(\n metaInput.revisionDeletedOn,\n originalEntry.revisionDeletedOn\n ),\n revisionRestoredOn: getDate(\n metaInput.revisionRestoredOn,\n originalEntry.revisionRestoredOn\n ),\n revisionFirstPublishedOn: getDate(\n metaInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n metaInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n metaInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(\n metaInput.revisionModifiedBy,\n revisionLevelSaved.revisionModifiedBy\n ),\n revisionSavedBy: getIdentity(\n metaInput.revisionSavedBy,\n revisionLevelSaved.revisionSavedBy\n )!,\n revisionDeletedBy: getIdentity(\n metaInput.revisionDeletedBy,\n originalEntry.revisionDeletedBy\n ),\n revisionRestoredBy: getIdentity(\n metaInput.revisionRestoredBy,\n originalEntry.revisionRestoredBy\n ),\n revisionFirstPublishedBy: getIdentity(\n metaInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n metaInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(metaInput.createdOn, latestEntry.createdOn),\n savedOn: getDate(metaInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(metaInput.modifiedOn, entryLevelSaved.modifiedOn),\n deletedOn: getDate(metaInput.deletedOn, latestEntry.deletedOn),\n restoredOn: getDate(metaInput.restoredOn, latestEntry.restoredOn),\n firstPublishedOn: getDate(metaInput.firstPublishedOn, latestEntry.firstPublishedOn),\n lastPublishedOn: getDate(metaInput.lastPublishedOn, latestEntry.lastPublishedOn),\n // The entry owner cannot be changed through an update.\n createdBy: latestEntry.createdBy,\n savedBy: getIdentity(metaInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(metaInput.modifiedBy, entryLevelSaved.modifiedBy),\n deletedBy: getIdentity(metaInput.deletedBy, latestEntry.deletedBy),\n restoredBy: getIdentity(metaInput.restoredBy, latestEntry.restoredBy),\n firstPublishedBy: getIdentity(metaInput.firstPublishedBy, latestEntry.firstPublishedBy),\n lastPublishedBy: getIdentity(metaInput.lastPublishedBy, latestEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase,\n AccessControl\n ]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","modelToAstConverter","getLatestRevision","accessControl","model","rawInput","originalEntry","options","latestResult","Result","latestEntry","cleanedValues","mapAndCleanUpdatedInputData","invalidFields","validateModelEntryData","EntryValidationError","mergedValues","modelAst","ensureItemIds","values","referenceFieldsMapping","metaInput","canOverrideMetaFields","currentIdentity","currentDateTime","Date","contentChanged","hasEntryContentChanged","entryLevelSaved","revisionLevelSaved","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase","AccessControl"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CA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,IAAI8B,UACAL,MAAM,QAAQ,GAAG;YACbK;QACJ;QAGJ,OAAO1B,OAAO,EAAE,CAAC;YACbqB;YACA,OAAO;gBACH,GAAGzB,QAAQ;gBACX,QAAQ+B,gBAAgBjB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMkB,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@babel/code-frame": "8.0.6",
|
|
26
26
|
"@graphql-tools/merge": "10.0.9",
|
|
27
27
|
"@graphql-tools/schema": "11.0.9",
|
|
28
|
-
"@webiny/api": "6.5.2-beta.
|
|
29
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
28
|
+
"@webiny/api": "6.5.2-beta.5",
|
|
29
|
+
"@webiny/api-core": "6.5.2-beta.5",
|
|
30
30
|
"@webiny/di": "1.1.0",
|
|
31
|
-
"@webiny/error": "6.5.2-beta.
|
|
32
|
-
"@webiny/feature": "6.5.2-beta.
|
|
33
|
-
"@webiny/handler": "6.5.2-beta.
|
|
34
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
35
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
36
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
37
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
38
|
-
"@webiny/project": "6.5.2-beta.
|
|
39
|
-
"@webiny/utils": "6.5.2-beta.
|
|
40
|
-
"@webiny/validation": "6.5.2-beta.
|
|
31
|
+
"@webiny/error": "6.5.2-beta.5",
|
|
32
|
+
"@webiny/feature": "6.5.2-beta.5",
|
|
33
|
+
"@webiny/handler": "6.5.2-beta.5",
|
|
34
|
+
"@webiny/handler-aws": "6.5.2-beta.5",
|
|
35
|
+
"@webiny/handler-db": "6.5.2-beta.5",
|
|
36
|
+
"@webiny/handler-graphql": "6.5.2-beta.5",
|
|
37
|
+
"@webiny/plugins": "6.5.2-beta.5",
|
|
38
|
+
"@webiny/project": "6.5.2-beta.5",
|
|
39
|
+
"@webiny/utils": "6.5.2-beta.5",
|
|
40
|
+
"@webiny/validation": "6.5.2-beta.5",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
42
|
"graphql": "16.15.0",
|
|
43
43
|
"graphql-tag": "2.12.7",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/pluralize": "0.0.33",
|
|
53
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
54
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
55
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
56
|
-
"@webiny/sdk": "6.5.2-beta.
|
|
57
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
53
|
+
"@webiny/build-tools": "6.5.2-beta.5",
|
|
54
|
+
"@webiny/handler-db": "6.5.2-beta.5",
|
|
55
|
+
"@webiny/project-utils": "6.5.2-beta.5",
|
|
56
|
+
"@webiny/sdk": "6.5.2-beta.5",
|
|
57
|
+
"@webiny/wcp": "6.5.2-beta.5",
|
|
58
58
|
"apollo-graphql": "0.9.7",
|
|
59
59
|
"graphql": "16.15.0",
|
|
60
60
|
"oxfmt": "0.78.0",
|