Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-1977] Add environment variable to disable custom validators during Strapi's data transfer #1209

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-coats-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-cms": patch
---

Add environment variable to disable custom validators during Strapi's data transfer
2 changes: 2 additions & 0 deletions apps/strapi-cms/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
marcobottaro marked this conversation as resolved.
Show resolved Hide resolved
DISABLE_CUSTOM_VALIDATORS=False

#DB CONFIG
DATABASE_CLIENT=sqlite
Expand Down
8 changes: 8 additions & 0 deletions apps/strapi-cms/src/utils/validateProductPresence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { errors } from '@strapi/utils';

const validatorsAreDisabled = process.env.DISABLE_CUSTOM_VALIDATORS === 'True';

export interface IEventWithProduct {
readonly params: {
readonly data: {
Expand All @@ -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 &&
Expand All @@ -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');
Expand Down
Loading