chore: move stage transition UID to constants

This commit is contained in:
Jamie Howard 2023-08-14 15:12:48 +01:00
parent b9a706cb08
commit ec1176b582
4 changed files with 17 additions and 11 deletions

View File

@ -4,6 +4,7 @@
module.exports = {
WORKFLOW_MODEL_UID: 'admin::workflow',
STAGE_MODEL_UID: 'admin::workflow-stage',
STAGE_TRANSITION_UID: 'admin::review-workflows.stage.transition',
STAGE_DEFAULT_COLOR: '#4945FF',
ENTITY_STAGE_ATTRIBUTE: 'strapi_stage',
MAX_WORKFLOWS: 200,
@ -20,12 +21,12 @@ module.exports = {
stages: {
populate: {
permissions: {
fields: ["action", "actionParameters"],
fields: ['action', 'actionParameters'],
populate: {
role: { fields: ["id", "name"] },
}
}
}
}
role: { fields: ['id', 'name'] },
},
},
},
},
},
};

View File

@ -3,7 +3,11 @@
const { mapAsync } = require('@strapi/utils');
const { getService } = require('../../../utils');
const { validateUpdateStageOnEntity } = require('../../../validation/review-workflows');
const { STAGE_MODEL_UID, ENTITY_STAGE_ATTRIBUTE } = require('../../../constants/workflows');
const {
STAGE_MODEL_UID,
ENTITY_STAGE_ATTRIBUTE,
STAGE_TRANSITION_UID,
} = require('../../../constants/workflows');
/**
*
@ -97,7 +101,7 @@ module.exports = {
// Validate if entity stage can be updated
const canTransition = stagePermissions.can(
'admin::review-workflows.stage.transition',
STAGE_TRANSITION_UID,
entity[ENTITY_STAGE_ATTRIBUTE]?.id
);

View File

@ -6,9 +6,9 @@ const {
errors: { ApplicationError },
} = require('@strapi/utils');
const { getService } = require('../../utils');
const { STAGE_TRANSITION_UID } = require('../../constants/workflows');
// TODO: This should use constants
const validActions = ['admin::review-workflows.stage.transition'];
const validActions = [STAGE_TRANSITION_UID];
module.exports = ({ strapi }) => {
const roleService = getService('role');

View File

@ -4,6 +4,7 @@
const { yup, validateYupSchema } = require('@strapi/utils');
const { hasStageAttribute } = require('../utils/review-workflows');
const { STAGE_TRANSITION_UID } = require('../constants/workflows');
const stageObject = yup.object().shape({
id: yup.number().integer().min(1),
@ -12,7 +13,7 @@ const stageObject = yup.object().shape({
permissions: yup.array().of(
yup.object().shape({
role: yup.number().integer().min(1).required(),
action: yup.string().oneOf(['admin::review-workflows.stage.transition']).required(),
action: yup.string().oneOf([STAGE_TRANSITION_UID]).required(),
actionParameters: yup.object().shape({
from: yup.number().integer().min(1).required(),
to: yup.number().integer().min(1),