From 5cd64bb1f95282968c5e112930093173d22b5c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Kr=C3=A4gelin?= <8436596+karkraeg@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:46:09 +0100 Subject: [PATCH] awards/schema.py: read app config for alternate funding validation (#429) --- .../src/contrib/forms/Funding/FundingModal.js | 30 ++----------------- invenio_vocabularies/contrib/awards/schema.py | 6 ++-- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/invenio_vocabularies/assets/semantic-ui/js/invenio_vocabularies/src/contrib/forms/Funding/FundingModal.js b/invenio_vocabularies/assets/semantic-ui/js/invenio_vocabularies/src/contrib/forms/Funding/FundingModal.js index 57b39da6..45822fbe 100644 --- a/invenio_vocabularies/assets/semantic-ui/js/invenio_vocabularies/src/contrib/forms/Funding/FundingModal.js +++ b/invenio_vocabularies/assets/semantic-ui/js/invenio_vocabularies/src/contrib/forms/Funding/FundingModal.js @@ -52,37 +52,13 @@ const CustomFundingSchema = Yup.object().shape({ id: Yup.string().required(i18next.t("Funder is required.")), }), award: Yup.object().shape({ - title: Yup.string().test({ - name: "testTitle", - message: i18next.t("Title must be set alongside number."), - test: function testTitle(value) { - const { number } = this.parent; - - if (number && !value) { - return false; - } - - return true; - }, - }), - number: Yup.string().test({ - name: "testNumber", - message: i18next.t("Number must be set alongside title."), - test: function testNumber(value) { - const { title } = this.parent; - - if (title && !value) { - return false; - } - - return true; - }, - }), + title: Yup.string(), + number: Yup.string(), url: Yup.string() .url(i18next.t("URL must be valid.")) .test({ name: "validateUrlDependencies", - message: i18next.t("URL must be set alongside title and number."), + message: i18next.t("URL must be set alongside title or number."), test: function testUrl(value) { const { title, number } = this.parent; diff --git a/invenio_vocabularies/contrib/awards/schema.py b/invenio_vocabularies/contrib/awards/schema.py index 99a919d0..ad4a0f79 100644 --- a/invenio_vocabularies/contrib/awards/schema.py +++ b/invenio_vocabularies/contrib/awards/schema.py @@ -94,9 +94,11 @@ def validate_data(self, data, **kwargs): id_ = data.get("id") number = data.get("number") title = data.get("title") - if not id_ and not (number and title): + + if not id_ and not (number or title): raise ValidationError( - _("An existing id or number/title must be present."), "award" + _("An existing id or either number or title must be present."), + "award", )