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

Make ORCID regex more permissive (#500) #502

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- [500](https://github.com/thoth-pub/thoth/issues/500) - Update ORCID regex

## [[0.11.2]](https://github.com/thoth-pub/thoth/releases/tag/v0.11.2) - 2023-06-19
### Changed
Expand Down
6 changes: 6 additions & 0 deletions thoth-api/migrations/0.11.3/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Reinstate earlier version of ORCID validation

ALTER TABLE contributor
DROP CONSTRAINT contributor_orcid_check,
ADD CONSTRAINT contributor_orcid_check
CHECK (orcid ~ '^https:\/\/orcid\.org\/0000-000(1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX]$');
7 changes: 7 additions & 0 deletions thoth-api/migrations/0.11.3/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Make ORCID validation more permissive as the docs don't specify a strict pattern
-- Should be kept in line with Orcid::FromStr, although regex syntax differs slightly

ALTER TABLE contributor
DROP CONSTRAINT contributor_orcid_check,
ADD CONSTRAINT contributor_orcid_check
CHECK (orcid ~ '^https:\/\/orcid\.org\/\d{4}-\d{4}-\d{4}-\d{3}[\dX]$');
2 changes: 1 addition & 1 deletion thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ impl Work {
}

#[graphql(
description = "Indicates that the work contains a bibliogrpahy or other similar information"
description = "Indicates that the work contains a bibliography or other similar information"
)]
pub fn bibliography_note(&self) -> Option<&String> {
self.bibliography_note.as_ref()
Expand Down
7 changes: 4 additions & 3 deletions thoth-api/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct Isbn(String);
feature = "backend",
derive(DieselNewType, juniper::GraphQLScalarValue),
graphql(
description = r#"ORCID (Open Researcher and Contributor ID) identifier. Expressed as `^https:\/\/orcid\.org\/0000-000(1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX]$`"#
description = r#"ORCID (Open Researcher and Contributor ID) identifier. Expressed as `^https:\/\/orcid\.org\/\d{4}-\d{4}-\d{4}-\d{3}[\dX]$`"#
)
)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -193,10 +193,10 @@ impl FromStr for Orcid {
// (?:) = non-capturing group
// i = case-insensitive flag
// $ = end of string
// Matches strings of format "[[http[s]://][www.]orcid.org/]0000-000X-XXXX-XXXX"
// Matches strings of format "[[http[s]://][www.]orcid.org/]XXXX-XXXX-XXXX-XXXX"
// and captures the 16-digit identifier segment
// Corresponds to database constraints although regex syntax differs slightly
r#"^(?i:(?:https?://)?(?:www\.)?orcid\.org/)?(0000-000(?:1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX]$)"#).unwrap();
r#"^(?i:(?:https?://)?(?:www\.)?orcid\.org/)?(\d{4}-\d{4}-\d{4}-\d{3}[\dX]$)"#).unwrap();
}
if input.is_empty() {
Err(ThothError::OrcidEmptyError)
Expand Down Expand Up @@ -776,6 +776,7 @@ fn test_orcid_fromstr() {
assert!(Orcid::from_str("//orcid.org/0000-0002-1234-5678").is_err());
assert!(Orcid::from_str("https://orcid-org/0000-0002-1234-5678").is_err());
assert!(Orcid::from_str("0000-0002-1234-5678https://orcid.org/").is_err());
assert!(Orcid::from_str("0009-0002-1234-567X").is_ok());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions thoth-client/assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12250,7 +12250,7 @@
{
"args": [],
"deprecationReason": null,
"description": null,
"description": "A general-purpose field used to include information that does not have a specific designated field",
"isDeprecated": false,
"name": "generalNote",
"type": {
Expand All @@ -12262,7 +12262,7 @@
{
"args": [],
"deprecationReason": null,
"description": null,
"description": "Indicates that the work contains a bibliography or other similar information",
"isDeprecated": false,
"name": "bibliographyNote",
"type": {
Expand Down Expand Up @@ -22164,7 +22164,7 @@
"possibleTypes": null
},
{
"description": "ORCID (Open Researcher and Contributor ID) identifier. Expressed as `^https:\\/\\/orcid\\.org\\/0000-000(1-[5-9]|2-[0-9]|3-[0-4])\\d{3}-\\d{3}[\\dX]$`",
"description": "ORCID (Open Researcher and Contributor ID) identifier. Expressed as `^https:\\/\\/orcid\\.org\\/\\d{4}-\\d{4}-\\d{4}-\\d{3}[\\dX]$`",
"enumValues": null,
"fields": null,
"inputFields": null,
Expand Down
Loading