diff --git a/Cargo.lock b/Cargo.lock index 539303b..0a1e888 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1307,7 +1307,7 @@ dependencies = [ [[package]] name = "qb_api" -version = "1.1.0" +version = "1.1.1" dependencies = [ "anyhow", "argon2", diff --git a/Cargo.toml b/Cargo.toml index f038703..63fc6b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qb_api" -version = "1.1.0" +version = "1.1.1" edition = "2021" [dependencies] diff --git a/docs/API.md b/docs/API.md index 9a7eea4..5cc975e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -411,7 +411,7 @@ Bot 账号不会自动生成;管理员创建或轮换 bot 账号时,接口 - "非 used" 指 `status != 'used'` 的题目 - "被分配的" 指在 `question_reviews` 表中被 leader 分配为审阅人的题目(user 和 leader 均可被分配) - reviewer 进行任意操作时,自动将其 display_name 加入 `questions.reviewers` 数组(去重) -- 替换文件时,后端自动重置 difficulty(清空)、status(`none`)、author(创建者 display_name)、reviewers(`[]`) +- 替换文件时,后端仅更新题目文件、`source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at` - 上传时,后端自动设置 difficulty 为空、status 为 `none`、author 为上传者 display_name、reviewers 为 `[]` - 后端自动维护 `created_by`、`created_at`、`updated_at` - 题目创建者(`created_by`)始终可修改自己题目的 description、category、tags 和 file,不受 status 限制 @@ -582,7 +582,7 @@ Bot 账号不会自动生成;管理员创建或轮换 bot 账号时,接口 - **Content-Type**:`multipart/form-data` - **字段**:`file`(binary zip) -**自动重置**:`difficulty`(清空所有条目)、`status` → `"none"`、`author` → 创建者当前 display_name、`reviewers` → `[]`。 +**后端行为**:仅替换题目文件,并更新 `source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`;不会改动 `status`、`author`、`reviewers`、`difficulty`。 **成功响应** `200`:`{ "question_id", "file_name", "source_tex_path", "imported_assets", "status": "replaced" }` diff --git a/src/api/questions/API.md b/src/api/questions/API.md index 63428d4..6a8b44a 100644 --- a/src/api/questions/API.md +++ b/src/api/questions/API.md @@ -29,7 +29,7 @@ - "非 used" 指 `status != 'used'` 的题目 - "被分配的" 指在 `question_reviews` 表中被 leader 分配为审阅人的题目(user 和 leader 均可被分配) - reviewer 进行任意操作时,自动将其 display_name 加入 `questions.reviewers` 数组(去重) -- 替换文件时,后端自动重置 difficulty(清空)、status(`none`)、author(创建者 display_name)、reviewers(`[]`) +- 替换文件时,后端仅更新题目文件、`source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at` - 上传时,后端自动设置 difficulty 为空、status 为 `none`、author 为上传者 display_name、reviewers 为 `[]` - 后端自动维护 `created_by`、`created_at`、`updated_at` - 题目创建者(`created_by`)始终可修改自己题目的 description、category、tags 和 file,不受 status 限制 @@ -200,7 +200,7 @@ - **Content-Type**:`multipart/form-data` - **字段**:`file`(binary zip) -**自动重置**:`difficulty`(清空所有条目)、`status` → `"none"`、`author` → 创建者当前 display_name、`reviewers` → `[]`。 +**后端行为**:仅替换题目文件,并更新 `source_tex_path`、从 TeX 提取出的 `score`、以及 `updated_at`;不会改动 `status`、`author`、`reviewers`、`difficulty`。 **成功响应** `200`:`{ "question_id", "file_name", "source_tex_path", "imported_assets", "status": "replaced" }` diff --git a/src/api/questions/handlers.rs b/src/api/questions/handlers.rs index 415abe9..b9fceb8 100644 --- a/src/api/questions/handlers.rs +++ b/src/api/questions/handlers.rs @@ -225,27 +225,12 @@ pub(crate) async fn replace_question_file( let (file_name, bytes) = read_uploaded_file(&mut multipart).await?; validate_upload_size(&bytes, MAX_UPLOAD_BYTES)?; - // Look up the creator's current display_name for resetting the author field. - let creator_display_name = if let Some(ref created_by) = access.created_by { - query("SELECT display_name FROM users WHERE user_id = $1::uuid") - .bind(created_by) - .fetch_optional(&state.pool) - .await - .context("look up creator display_name failed") - .map_err(ApiError::from)? - .map(|r| r.get::("display_name")) - .unwrap_or_default() - } else { - String::new() - }; - Ok(Json( replace_question_zip( &state.pool, &question_id, file_name.as_deref(), bytes, - &creator_display_name, ) .await .map_err(ApiError::from)?, @@ -790,7 +775,6 @@ async fn fetch_question_detail( struct QuestionAccessInfo { #[allow(dead_code)] status: String, - created_by: Option, is_admin_or_bot: bool, is_leader: bool, is_owner: bool, @@ -838,7 +822,6 @@ async fn load_question_access( Ok(QuestionAccessInfo { status, - created_by, is_admin_or_bot, is_leader, is_owner, diff --git a/src/api/questions/imports.rs b/src/api/questions/imports.rs index 0bc7edf..b3181ee 100644 --- a/src/api/questions/imports.rs +++ b/src/api/questions/imports.rs @@ -102,7 +102,6 @@ pub(crate) async fn replace_question_zip( question_id: &str, file_name: Option<&str>, zip_bytes: Vec, - creator_display_name: &str, ) -> Result { if zip_bytes.is_empty() { return Err(ValidationError("uploaded file is empty".into()).into()); @@ -132,22 +131,12 @@ pub(crate) async fn replace_question_zip( replace_question_files_tx(&mut tx, question_id, &loaded).await?; - // Reset difficulty, status, author, reviewers to creation state. - query("DELETE FROM question_difficulties WHERE question_id = $1::uuid") - .bind(question_id) - .execute(&mut *tx) - .await - .context("clear question difficulties on file replace failed")?; - - let empty_reviewers: Vec = vec![]; query( - "UPDATE questions SET source_tex_path = $2, score = $3, status = 'none', author = $4, reviewers = $5, updated_at = NOW() WHERE question_id = $1::uuid", + "UPDATE questions SET source_tex_path = $2, score = $3, updated_at = NOW() WHERE question_id = $1::uuid", ) .bind(question_id) .bind(&loaded.tex_file.path) .bind(loaded.score) - .bind(creator_display_name) - .bind(&empty_reviewers) .execute(&mut *tx) .await .context("update question on file replace failed")?;