summaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-02-14 16:24:16 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-02-14 16:24:16 -0800
commitb9699e27936573271506dbf6a3af744f7b454c03 (patch)
treea5ec41bf27f844fad32ca7f6aa1c254bd5c424ae /rust
parent70b4bc18b13f59c9d42c8e44ef872dfd2e1abef3 (diff)
downloadfatcat-b9699e27936573271506dbf6a3af744f7b454c03.tar.gz
fatcat-b9699e27936573271506dbf6a3af744f7b454c03.zip
verify release_status field
Diffstat (limited to 'rust')
-rw-r--r--rust/src/entity_crud.rs3
-rw-r--r--rust/src/identifiers.rs32
2 files changed, 35 insertions, 0 deletions
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index 743d451a..faf4b496 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -1964,6 +1964,9 @@ impl EntityCrud for ReleaseEntity {
if let Some(ref release_type) = entity.release_type {
check_release_type(release_type)?;
}
+ if let Some(ref release_status) = entity.release_status {
+ check_release_status(release_status)?;
+ }
if let Some(ref abstracts) = entity.abstracts {
if abstracts.len() > 200 {
return Err(FatcatError::BadRequest(
diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs
index 1c859269..ed88939d 100644
--- a/rust/src/identifiers.rs
+++ b/rust/src/identifiers.rs
@@ -342,6 +342,38 @@ fn test_check_release_type() {
assert!(check_release_type("book ").is_err());
}
+pub fn check_release_status(raw: &str) -> Result<()> {
+ let valid_types = vec![
+ // DRIVER types (minus "version" suffix)
+ "draft",
+ "submitted",
+ "accepted",
+ "published",
+ "updated",
+ // fatcat-specific extensions
+ "retraction",
+ ];
+ for good in valid_types {
+ if raw == good {
+ return Ok(());
+ }
+ }
+ Err(FatcatError::NotInControlledVocabulary(
+ "release_status".to_string(),
+ raw.to_string(),
+ ))?
+}
+
+#[test]
+fn test_check_release_status() {
+ assert!(check_release_status("draft").is_ok());
+ assert!(check_release_status("retraction").is_ok());
+ assert!(check_release_status("published").is_ok());
+ assert!(check_release_status("pre-print").is_err());
+ assert!(check_release_status("DRAFT").is_err());
+ assert!(check_release_status("draft ").is_err());
+}
+
pub fn check_contrib_role(raw: &str) -> Result<()> {
let valid_types = vec![
// Citation Style Language official role types