mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Update updatedBy on publish / unpublish actions in the CM
This commit is contained in:
parent
82740ef6f0
commit
58e4deadb6
@ -152,7 +152,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
async publish(ctx) {
|
||||
const { userAbility } = ctx.state;
|
||||
const { userAbility, user } = ctx.state;
|
||||
const { id, model } = ctx.params;
|
||||
|
||||
const entityManager = getService('entity-manager');
|
||||
@ -172,13 +172,17 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const result = await entityManager.publish(entity, model);
|
||||
const result = await entityManager.publish(
|
||||
entity,
|
||||
setCreatorFields({ user, isEdition: true })({}),
|
||||
model
|
||||
);
|
||||
|
||||
ctx.body = await permissionChecker.sanitizeOutput(result);
|
||||
},
|
||||
|
||||
async unpublish(ctx) {
|
||||
const { userAbility } = ctx.state;
|
||||
const { userAbility, user } = ctx.state;
|
||||
const { id, model } = ctx.params;
|
||||
|
||||
const entityManager = getService('entity-manager');
|
||||
@ -198,7 +202,11 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const result = await entityManager.unpublish(entity, model);
|
||||
const result = await entityManager.unpublish(
|
||||
entity,
|
||||
setCreatorFields({ user, isEdition: true })({}),
|
||||
model
|
||||
);
|
||||
|
||||
ctx.body = await permissionChecker.sanitizeOutput(result);
|
||||
},
|
||||
|
||||
@ -114,7 +114,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
async publish(ctx) {
|
||||
const { userAbility } = ctx.state;
|
||||
const { userAbility, user } = ctx.state;
|
||||
const { model } = ctx.params;
|
||||
const { query = {} } = ctx.request;
|
||||
|
||||
@ -135,13 +135,17 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const publishedEntity = await entityManager.publish(entity, model);
|
||||
const publishedEntity = await entityManager.publish(
|
||||
entity,
|
||||
setCreatorFields({ user, isEdition: true })({}),
|
||||
model
|
||||
);
|
||||
|
||||
ctx.body = await permissionChecker.sanitizeOutput(publishedEntity);
|
||||
},
|
||||
|
||||
async unpublish(ctx) {
|
||||
const { userAbility } = ctx.state;
|
||||
const { userAbility, user } = ctx.state;
|
||||
const { model } = ctx.params;
|
||||
const { query = {} } = ctx.request;
|
||||
|
||||
@ -162,7 +166,11 @@ module.exports = {
|
||||
return ctx.forbidden();
|
||||
}
|
||||
|
||||
const unpublishedEntity = await entityManager.unpublish(entity, model);
|
||||
const unpublishedEntity = await entityManager.unpublish(
|
||||
entity,
|
||||
setCreatorFields({ user, isEdition: true })({}),
|
||||
model
|
||||
);
|
||||
|
||||
ctx.body = await permissionChecker.sanitizeOutput(unpublishedEntity);
|
||||
},
|
||||
|
||||
@ -11,8 +11,8 @@ const { MANY_RELATIONS } = strapiUtils.relations.constants;
|
||||
|
||||
const omitPublishedAtField = omit(PUBLISHED_AT_ATTRIBUTE);
|
||||
|
||||
const wrapWithEmitEvent = (event, fn) => async (entity, model) => {
|
||||
const result = await fn(entity, model);
|
||||
const wrapWithEmitEvent = (event, fn) => async (entity, body, model) => {
|
||||
const result = await fn(entity, body, model);
|
||||
|
||||
const modelDef = strapi.getModel(model);
|
||||
const sanitizedEntity = await strapiUtils.sanitize.sanitizers.defaultSanitizeOutput(
|
||||
@ -206,7 +206,7 @@ module.exports = ({ strapi }) => ({
|
||||
return strapi.entityService.deleteMany(uid, params);
|
||||
},
|
||||
|
||||
publish: wrapWithEmitEvent(ENTRY_PUBLISH, async (entity, uid) => {
|
||||
publish: wrapWithEmitEvent(ENTRY_PUBLISH, async (entity, body = {}, uid) => {
|
||||
if (entity[PUBLISHED_AT_ATTRIBUTE]) {
|
||||
throw new ApplicationError('already.published');
|
||||
}
|
||||
@ -214,19 +214,19 @@ module.exports = ({ strapi }) => ({
|
||||
// validate the entity is valid for publication
|
||||
await strapi.entityValidator.validateEntityCreation(strapi.getModel(uid), entity);
|
||||
|
||||
const data = { [PUBLISHED_AT_ATTRIBUTE]: new Date() };
|
||||
const data = { ...body, [PUBLISHED_AT_ATTRIBUTE]: new Date() };
|
||||
|
||||
const params = { data, populate: getDeepPopulate(uid) };
|
||||
|
||||
return strapi.entityService.update(uid, entity.id, params);
|
||||
}),
|
||||
|
||||
unpublish: wrapWithEmitEvent(ENTRY_UNPUBLISH, (entity, uid) => {
|
||||
unpublish: wrapWithEmitEvent(ENTRY_UNPUBLISH, (entity, body = {}, uid) => {
|
||||
if (!entity[PUBLISHED_AT_ATTRIBUTE]) {
|
||||
throw new ApplicationError('already.draft');
|
||||
}
|
||||
|
||||
const data = { [PUBLISHED_AT_ATTRIBUTE]: null };
|
||||
const data = { ...body, [PUBLISHED_AT_ATTRIBUTE]: null };
|
||||
|
||||
const params = { data, populate: getDeepPopulate(uid) };
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user