mirror of
https://github.com/strapi/strapi.git
synced 2025-12-13 07:55:33 +00:00
feature(ee): emit workflow stage change webhook event
This commit is contained in:
parent
7ec5466c22
commit
0f15960636
5
packages/core/admin/ee/server/constants/webhookEvents.js
Normal file
5
packages/core/admin/ee/server/constants/webhookEvents.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
WORKFLOW_UPDATE_STAGE: 'workflow.updateEntryStage',
|
||||||
|
};
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const { isNil, isNull } = require('lodash/fp');
|
const { isNil, isNull } = require('lodash/fp');
|
||||||
const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
|
const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
|
||||||
|
const { WORKFLOW_UPDATE_STAGE } = require('../../constants/webhookEvents');
|
||||||
const { hasReviewWorkflow, getDefaultWorkflow } = require('../../utils/review-workflows');
|
const { hasReviewWorkflow, getDefaultWorkflow } = require('../../utils/review-workflows');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,18 @@ const decorator = (service) => ({
|
|||||||
delete data[ENTITY_STAGE_ATTRIBUTE];
|
delete data[ENTITY_STAGE_ATTRIBUTE];
|
||||||
}
|
}
|
||||||
|
|
||||||
return service.update.call(this, uid, entityId, { ...opts, data });
|
const entity = await service.findOne.call(this, uid, entityId, {
|
||||||
|
populate: [ENTITY_STAGE_ATTRIBUTE],
|
||||||
|
});
|
||||||
|
const previousStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id ?? null;
|
||||||
|
|
||||||
|
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
||||||
|
|
||||||
|
if (previousStageId && previousStageId !== data[ENTITY_STAGE_ATTRIBUTE]) {
|
||||||
|
await service.emitEvent.call(this, uid, WORKFLOW_UPDATE_STAGE, updatedEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedEntity;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
|
|||||||
|
|
||||||
const { getDefaultWorkflow } = require('../../utils/review-workflows');
|
const { getDefaultWorkflow } = require('../../utils/review-workflows');
|
||||||
const { persistTables, removePersistedTablesWithSuffix } = require('../../utils/persisted-tables');
|
const { persistTables, removePersistedTablesWithSuffix } = require('../../utils/persisted-tables');
|
||||||
|
const webhookEvents = require('../../constants/webhookEvents');
|
||||||
|
|
||||||
async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) {
|
async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) {
|
||||||
const wfCount = await workflowsService.count();
|
const wfCount = await workflowsService.count();
|
||||||
@ -109,7 +110,9 @@ function persistStagesJoinTables({ strapi }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const registerWebhookEvents = async ({ strapi }) =>
|
const registerWebhookEvents = async ({ strapi }) =>
|
||||||
strapi.webhookStore.addAllowedEvent('WORKFLOW_UPDATE_STAGE', 'workflow.updateEntryStage');
|
Object.entries(webhookEvents).forEach(([eventKey, event]) =>
|
||||||
|
strapi.webhookStore.addAllowedEvent(eventKey, event)
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = ({ strapi }) => {
|
module.exports = ({ strapi }) => {
|
||||||
const workflowsService = getService('workflows', { strapi });
|
const workflowsService = getService('workflows', { strapi });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user