diff --git a/packages/core/admin/ee/server/constants/workflows.js b/packages/core/admin/ee/server/constants/workflows.js index 12c0940900..07a79c0090 100644 --- a/packages/core/admin/ee/server/constants/workflows.js +++ b/packages/core/admin/ee/server/constants/workflows.js @@ -14,5 +14,6 @@ module.exports = { 'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.', STAGES_LIMIT: 'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.', + DUPLICATED_STAGE_NAME: 'Stage names must be unique.', }, }; diff --git a/packages/core/admin/ee/server/services/review-workflows/validation.js b/packages/core/admin/ee/server/services/review-workflows/validation.js index c65c0f06e0..6382b53f6a 100644 --- a/packages/core/admin/ee/server/services/review-workflows/validation.js +++ b/packages/core/admin/ee/server/services/review-workflows/validation.js @@ -1,5 +1,6 @@ 'use strict'; +const { uniq } = require('lodash/fp'); const { ValidationError } = require('@strapi/utils').errors; const { getService } = require('../../utils'); const { ERRORS, MAX_WORKFLOWS, MAX_STAGES_PER_WORKFLOW } = require('../../constants/workflows'); @@ -32,6 +33,11 @@ module.exports = ({ strapi }) => { if (stages.length > this.limits.stagesPerWorkflow) { throw new ValidationError(ERRORS.STAGES_LIMIT); } + // Validate stage names are not duplicated + const stageNames = stages.map((stage) => stage.name); + if (uniq(stageNames).length !== stageNames.length) { + throw new ValidationError(ERRORS.DUPLICATED_STAGE_NAME); + } }, async validateWorkflowCountStages(workflowId, countAddedStages = 0) {