From db5939edf2dae6a98e6531f21cc562cd170ec21d Mon Sep 17 00:00:00 2001 From: Marco Bottaro Date: Fri, 18 Oct 2024 13:21:57 +0200 Subject: [PATCH 1/2] Add environment variable to disable custom validators during Strapi's data transfer --- .changeset/wet-coats-train.md | 5 +++++ apps/strapi-cms/.env.default | 2 ++ apps/strapi-cms/src/utils/validateProductPresence.ts | 8 ++++++++ 3 files changed, 15 insertions(+) create mode 100644 .changeset/wet-coats-train.md diff --git a/.changeset/wet-coats-train.md b/.changeset/wet-coats-train.md new file mode 100644 index 0000000000..977cbbd3d1 --- /dev/null +++ b/.changeset/wet-coats-train.md @@ -0,0 +1,5 @@ +--- +"strapi-cms": patch +--- + +Add environment variable to disable custom validators during Strapi's data transfer diff --git a/apps/strapi-cms/.env.default b/apps/strapi-cms/.env.default index 917f22e76c..4c76e62aa4 100644 --- a/apps/strapi-cms/.env.default +++ b/apps/strapi-cms/.env.default @@ -5,6 +5,8 @@ API_TOKEN_SALT=tobemodified ADMIN_JWT_SECRET=tobemodified TRANSFER_TOKEN_SALT=tobemodified JWT_SECRET=tobemodified +# Set this variable to True to disable custom validators during data transfer +DISABLE_CUSTOM_VALIDATORS=False #DB CONFIG DATABASE_CLIENT=sqlite diff --git a/apps/strapi-cms/src/utils/validateProductPresence.ts b/apps/strapi-cms/src/utils/validateProductPresence.ts index 82216648ed..54dab1b9f3 100644 --- a/apps/strapi-cms/src/utils/validateProductPresence.ts +++ b/apps/strapi-cms/src/utils/validateProductPresence.ts @@ -1,5 +1,7 @@ import { errors } from '@strapi/utils'; +const validatorsAreDisabled = process.env.DISABLE_CUSTOM_VALIDATORS === 'True'; + export interface IEventWithProduct { readonly params: { readonly data: { @@ -21,6 +23,9 @@ export interface IEventWithProduct { export const validateAssociatedProductPresenceOnUpdate = ( event: IEventWithProduct ): boolean => { + if (validatorsAreDisabled) { + return true; + } // if there's only disconnect and no connect, throw error if ( (event.params.data.product?.disconnect?.length ?? 0) > 0 && @@ -35,6 +40,9 @@ export const validateAssociatedProductPresenceOnUpdate = ( export const validateAssociatedProductPresenceOnCreate = ( event: IEventWithProduct ): boolean => { + if (validatorsAreDisabled) { + return true; + } // if theres no connect inside connect elements throw error if ((event.params.data.product?.connect?.length ?? 0) === 0) { throw new errors.ApplicationError('Product is required'); From 60da8db8b36e483ab6606776bc438a3f3c8dd3eb Mon Sep 17 00:00:00 2001 From: marcobottaro <39835990+marcobottaro@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:46:33 +0200 Subject: [PATCH 2/2] Update apps/strapi-cms/.env.default comment Co-authored-by: tommaso1 --- apps/strapi-cms/.env.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/strapi-cms/.env.default b/apps/strapi-cms/.env.default index 4c76e62aa4..e07819a056 100644 --- a/apps/strapi-cms/.env.default +++ b/apps/strapi-cms/.env.default @@ -5,7 +5,7 @@ API_TOKEN_SALT=tobemodified ADMIN_JWT_SECRET=tobemodified TRANSFER_TOKEN_SALT=tobemodified JWT_SECRET=tobemodified -# Set this variable to True to disable custom validators during data transfer +# Set this variable to True to disable custom validators during data transfer. Allowed values: True, False DISABLE_CUSTOM_VALIDATORS=False #DB CONFIG