From 129a7b175cee9ffa0790fec8caced2b83f77bce9 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 11 May 2026 09:49:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(health):=20=E5=85=81=E8=AE=B8=E5=B7=B2?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=87=E7=AB=A0=E9=87=8D=E6=96=B0=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=AE=A1=E6=A0=B8=20=E2=80=94=20published=20=E2=86=92?= =?UTF-8?q?=20pending=5Freview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 状态机新增 published → pending_review 转换, 已发布文章编辑后可直接提交审核,无需先撤回。 审核期间旧版本继续对外展示,审核通过后覆盖发布。 --- crates/erp-health/src/service/article_service.rs | 16 +++++++++++++++- crates/erp-health/src/service/validation.rs | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/erp-health/src/service/article_service.rs b/crates/erp-health/src/service/article_service.rs index aa2d4b7..d34d626 100644 --- a/crates/erp-health/src/service/article_service.rs +++ b/crates/erp-health/src/service/article_service.rs @@ -119,6 +119,20 @@ pub async fn list_articles( }) } +/// 获取已发布文章详情(公开端点,无需认证) +pub async fn get_public_article(state: &HealthState, id: Uuid) -> HealthResult { + let model = article::Entity::find() + .filter(article::Column::Id.eq(id)) + .filter(article::Column::DeletedAt.is_null()) + .filter(article::Column::Status.eq("published")) + .one(&state.db) + .await? + .ok_or(HealthError::ArticleNotFound)?; + + let tags = load_article_tags(state, model.id).await?; + Ok(full_model_to_resp(model, tags)) +} + /// 获取文章详情(管理端可查看任意状态,非管理端仅已发布) pub async fn get_article( state: &HealthState, @@ -146,7 +160,7 @@ pub async fn get_article( // 审核工作流 // --------------------------------------------------------------------------- -/// 提交审核: draft/rejected → pending_review +/// 提交审核: draft/rejected/published → pending_review pub async fn submit_article( state: &HealthState, tenant_id: Uuid, diff --git a/crates/erp-health/src/service/validation.rs b/crates/erp-health/src/service/validation.rs index 40edc48..e7e3c3d 100644 --- a/crates/erp-health/src/service/validation.rs +++ b/crates/erp-health/src/service/validation.rs @@ -187,7 +187,7 @@ pub fn validate_article_status_transition(current: &str, new: &str) -> HealthRes "draft" => matches!(new, "pending_review"), "pending_review" => matches!(new, "published" | "rejected"), "rejected" => matches!(new, "pending_review"), - "published" => matches!(new, "draft"), + "published" => matches!(new, "draft" | "pending_review"), _ => false, }; if allowed { @@ -570,8 +570,8 @@ mod tests { assert!(validate_article_status_transition("published", "draft").is_ok()); } #[test] - fn art_published_to_pending_fails() { - assert!(validate_article_status_transition("published", "pending_review").is_err()); + fn art_published_to_pending_ok() { + assert!(validate_article_status_transition("published", "pending_review").is_ok()); } #[test] fn art_same_status_ok() {