From 1b1cb9f899e8213a99bc96ff3124bde67462d34a Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Mon, 15 May 2023 10:27:51 +0200 Subject: [PATCH] feat: validate workflow assignedCT update --- .../admin/ee/server/validation/review-workflows.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/core/admin/ee/server/validation/review-workflows.js b/packages/core/admin/ee/server/validation/review-workflows.js index e374cab291..f60121ff33 100644 --- a/packages/core/admin/ee/server/validation/review-workflows.js +++ b/packages/core/admin/ee/server/validation/review-workflows.js @@ -15,6 +15,14 @@ const validateUpdateStageOnEntity = yup }) .required(); +const validateAssignedContentTypes = yup.array().of( + yup.string().test({ + name: 'content-type-exists', + message: (value) => `Content type ${value.originalValue} does not exist`, + test: (uid) => strapi.getModel(uid), + }) +); + const validateWorkflowCreateSchema = yup.object().shape({ name: yup.string().max(255).required(), stages: yup @@ -23,6 +31,7 @@ const validateWorkflowCreateSchema = yup.object().shape({ .min(1, 'Can not create a workflow without stages') .max(200, 'Can not have more than 200 stages') .required(), + assignedContentTypes: validateAssignedContentTypes, }); const validateWorkflowUpdateSchema = yup.object().shape({ @@ -30,8 +39,9 @@ const validateWorkflowUpdateSchema = yup.object().shape({ stages: yup .array() .of(stageObject) - .min(1, 'Can not create a workflow without stages') + .min(1, 'Can not update a workflow without stages') .max(200, 'Can not have more than 200 stages'), + assignedContentTypes: validateAssignedContentTypes, }); module.exports = {