Skip to content

Commit

Permalink
awards/schema.py: read app config for alternate funding validation (#429
Browse files Browse the repository at this point in the history
)
  • Loading branch information
karkraeg authored Nov 25, 2024
1 parent d0ecfbc commit 5cd64bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions invenio_vocabularies/contrib/awards/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)


Expand Down

0 comments on commit 5cd64bb

Please sign in to comment.