From d1e3fa9afa61ae1dbab670d854bb57f122d8933c Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 1 Nov 2022 18:00:07 +0300 Subject: [PATCH] Checking for google drive links (#1757) * checking for google drive links * Removing unused function * Update src/components/Publish/_validation.ts Co-authored-by: Matthias Kretschmann * CHecking for google drive URLs on the edit form Co-authored-by: Matthias Kretschmann --- src/components/Asset/Edit/_validation.ts | 20 ++++++++++++++++++-- src/components/Publish/_validation.ts | 22 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/components/Asset/Edit/_validation.ts b/src/components/Asset/Edit/_validation.ts index 52b9faf07..8d81768fe 100644 --- a/src/components/Asset/Edit/_validation.ts +++ b/src/components/Asset/Edit/_validation.ts @@ -10,7 +10,15 @@ export const validationSchema = Yup.object().shape({ files: Yup.array() .of( Yup.object().shape({ - url: Yup.string().url('Must be a valid URL.'), + url: Yup.string() + .url('Must be a valid URL.') + .test( + 'GoogleNotSupported', + 'Google Drive is not a supported hosting service. Please use an alternative.', + (value) => { + return !value?.toString().includes('drive.google') + } + ), valid: Yup.boolean().isTrue() }) ) @@ -18,7 +26,15 @@ export const validationSchema = Yup.object().shape({ links: Yup.array() .of( Yup.object().shape({ - url: Yup.string().url('Must be a valid URL.'), + url: Yup.string() + .url('Must be a valid URL.') + .test( + 'GoogleNotSupported', + 'Google Drive is not a supported hosting service. Please use an alternative.', + (value) => { + return !value?.toString().includes('drive.google') + } + ), valid: Yup.boolean().isTrue() }) ) diff --git a/src/components/Publish/_validation.ts b/src/components/Publish/_validation.ts index 3454f50ba..7d76bdcc6 100644 --- a/src/components/Publish/_validation.ts +++ b/src/components/Publish/_validation.ts @@ -32,7 +32,17 @@ const validationService = { files: Yup.array() .of( Yup.object().shape({ - url: Yup.string().url('Must be a valid URL.').required('Required'), + url: Yup.string() + .test( + 'GoogleNotSupported', + 'Google Drive is not a supported hosting service. Please use an alternative.', + (value) => { + return !value?.toString().includes('drive.google') + } + ) + .url('Must be a valid URL.') + .required('Required'), + valid: Yup.boolean().isTrue().required('File must be valid.') }) ) @@ -41,7 +51,15 @@ const validationService = { links: Yup.array() .of( Yup.object().shape({ - url: Yup.string().url('Must be a valid URL.'), + url: Yup.string() + .url('Must be a valid URL.') + .test( + 'GoogleNotSupported', + 'Google Drive is not a supported hosting service. Please use an alternative.', + (value) => { + return !value?.toString().includes('drive.google') + } + ), // TODO: require valid file only when URL is given valid: Yup.boolean() // valid: Yup.boolean().isTrue('File must be valid.')