diff --git a/thoth-api/src/model/work/crud.rs b/thoth-api/src/model/work/crud.rs index 343f424f..5a9961dc 100644 --- a/thoth-api/src/model/work/crud.rs +++ b/thoth-api/src/model/work/crud.rs @@ -408,6 +408,7 @@ where Self: WorkProperties, { fn validate(&self) -> ThothResult<()> { + self.active_no_publication_date_error()?; self.withdrawn_date_error()?; self.no_withdrawn_date_error()?; self.withdrawn_date_before_publication_date_error() diff --git a/thoth-api/src/model/work/mod.rs b/thoth-api/src/model/work/mod.rs index f24536da..873571bb 100644 --- a/thoth-api/src/model/work/mod.rs +++ b/thoth-api/src/model/work/mod.rs @@ -326,6 +326,9 @@ impl WorkStatus { fn is_withdrawn(&self) -> bool { matches!(self, WorkStatus::WithdrawnFromSale) } + fn is_active(&self) -> bool { + matches!(self, WorkStatus::Active) + } } pub trait WorkProperties { @@ -337,10 +340,25 @@ pub trait WorkProperties { self.work_status().is_withdrawn() } + fn is_active(&self) -> bool { + self.work_status().is_active() + } + fn has_withdrawn_date(&self) -> bool { self.withdrawn_date().is_some() } + fn has_publication_date(&self) -> bool { + self.publication_date().is_some() + } + + fn active_no_publication_date_error(&self) -> ThothResult<()> { + if self.is_active() && self.has_publication_date() { + return Err(ThothError::PublicationDateError); + } + Ok(()) + } + fn withdrawn_date_error(&self) -> ThothResult<()> { if !self.is_withdrawn() && self.has_withdrawn_date() { return Err(ThothError::WithdrawnDateError); diff --git a/thoth-app/src/component/new_work.rs b/thoth-app/src/component/new_work.rs index 1bd28e60..4400d664 100644 --- a/thoth-app/src/component/new_work.rs +++ b/thoth-app/src/component/new_work.rs @@ -459,6 +459,8 @@ impl Component for NewWorkComponent { let is_chapter = self.work.work_type == WorkType::BookChapter; let is_not_withdrawn = self.work.work_status != WorkStatus::WithdrawnFromSale; + let is_active = self.work.work_status + == WorkStatus::Active; html! { <>