feat(review-workflows): add default workflow

This commit is contained in:
nathan-pichon 2023-01-27 18:30:29 +01:00
parent 2ef020de1c
commit e661450b01
No known key found for this signature in database
5 changed files with 70 additions and 2 deletions

View File

@ -25,11 +25,16 @@ const SSO_ACTIONS = [
];
module.exports = async () => {
const { actionProvider } = getService('permission');
if (features.isEnabled('sso')) {
const { actionProvider } = getService('permission');
await actionProvider.registerMany(SSO_ACTIONS);
}
if (features.isEnabled('review-workflows')) {
const { bootstrap: rwBootstrap } = getService('review-workflows');
await rwBootstrap();
}
await executeCEBootstrap();
};

View File

@ -0,0 +1,11 @@
[
{
"name": "To do"
},
{
"name": "In progress"
},
{
"name": "Done"
}
]

View File

@ -0,0 +1,3 @@
{
"uid": "cjld2cjxh0000qzrmn831i7rn"
}

View File

@ -5,4 +5,5 @@ module.exports = {
role: require('./role'),
workflows: require('./review-workflows/workflows'),
stages: require('./review-workflows/stages'),
'review-workflows': require('./review-workflows/review-workflows'),
};

View File

@ -0,0 +1,48 @@
'use strict';
const { WORKFLOW_MODEL_UID, STAGE_MODEL_UID } = require('../../constants/workflows');
module.exports = ({ strapi }) => ({
async bootstrap() {
const wfCount = await strapi.entityService.count(WORKFLOW_MODEL_UID);
const stagesCount = await strapi.entityService.count(STAGE_MODEL_UID);
if (wfCount + stagesCount === 0) {
const defaultStages = require('../../constants/default-stages.json');
const defaultWorkflow = require('../../constants/default-workflow.json');
await strapi.query('admin::workflow-stage').createMany({ data: defaultStages });
const stages = await strapi
.query('admin::workflow-stage')
.findMany({ limit: 3, select: ['id'] });
const workflow = {
...defaultWorkflow,
stages: {
connect: [
{
id: stages[0].id,
position: {
start: true,
},
},
{
id: stages[1].id,
position: {
after: stages[0].id,
},
},
{
id: stages[2].id,
position: {
after: stages[1].id,
},
},
],
},
};
await strapi.query('admin::workflow').create({ data: workflow });
}
},
});