fix(health): 允许已发布文章重新提交审核 — published → pending_review
状态机新增 published → pending_review 转换, 已发布文章编辑后可直接提交审核,无需先撤回。 审核期间旧版本继续对外展示,审核通过后覆盖发布。
This commit is contained in:
@@ -119,6 +119,20 @@ pub async fn list_articles(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 获取已发布文章详情(公开端点,无需认证)
|
||||||
|
pub async fn get_public_article(state: &HealthState, id: Uuid) -> HealthResult<ArticleResp> {
|
||||||
|
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(
|
pub async fn get_article(
|
||||||
state: &HealthState,
|
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(
|
pub async fn submit_article(
|
||||||
state: &HealthState,
|
state: &HealthState,
|
||||||
tenant_id: Uuid,
|
tenant_id: Uuid,
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ pub fn validate_article_status_transition(current: &str, new: &str) -> HealthRes
|
|||||||
"draft" => matches!(new, "pending_review"),
|
"draft" => matches!(new, "pending_review"),
|
||||||
"pending_review" => matches!(new, "published" | "rejected"),
|
"pending_review" => matches!(new, "published" | "rejected"),
|
||||||
"rejected" => matches!(new, "pending_review"),
|
"rejected" => matches!(new, "pending_review"),
|
||||||
"published" => matches!(new, "draft"),
|
"published" => matches!(new, "draft" | "pending_review"),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
if allowed {
|
if allowed {
|
||||||
@@ -570,8 +570,8 @@ mod tests {
|
|||||||
assert!(validate_article_status_transition("published", "draft").is_ok());
|
assert!(validate_article_status_transition("published", "draft").is_ok());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn art_published_to_pending_fails() {
|
fn art_published_to_pending_ok() {
|
||||||
assert!(validate_article_status_transition("published", "pending_review").is_err());
|
assert!(validate_article_status_transition("published", "pending_review").is_ok());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn art_same_status_ok() {
|
fn art_same_status_ok() {
|
||||||
|
|||||||
Reference in New Issue
Block a user