diff --git a/backend/main.py b/backend/main.py index 54ce768..6dd3136 100644 --- a/backend/main.py +++ b/backend/main.py @@ -781,15 +781,14 @@ def create_recipe(recipe: RecipeIn, user=Depends(get_current_user)): c.execute("INSERT OR IGNORE INTO tags (name) VALUES (?)", (tag,)) c.execute("INSERT OR IGNORE INTO recipe_tags (recipe_id, tag_name) VALUES (?, ?)", (rid, tag)) log_audit(conn, user["id"], "create_recipe", "recipe", rid, recipe.name) - # Notify admin and senior editors when non-admin creates a recipe - if user["role"] not in ("admin", "senior_editor"): + # Notify admin only when non-admin creates a recipe + if user["role"] != "admin": who = user.get("display_name") or user["username"] - for role in ("admin", "senior_editor"): - conn.execute( - "INSERT INTO notifications (target_role, title, body) VALUES (?, ?, ?)", - (role, "📝 新配方待审核", - f"{who} 共享了配方「{recipe.name}」,请到管理配方查看。\n[recipe_id:{rid}]") - ) + conn.execute( + "INSERT INTO notifications (target_role, title, body) VALUES (?, ?, ?)", + ("admin", "📝 新配方待审核", + f"{who} 共享了配方「{recipe.name}」,请到管理配方查看。\n[recipe_id:{rid}]") + ) conn.commit() conn.close() return {"id": rid} @@ -925,6 +924,31 @@ def reject_recipe(recipe_id: int, body: dict = None, user=Depends(require_role(" return {"ok": True} +@app.post("/api/recipes/{recipe_id}/assign-review") +def assign_recipe_review(recipe_id: int, body: dict, user=Depends(require_role("admin"))): + reviewer_id = body.get("user_id") + if not reviewer_id: + raise HTTPException(400, "请选择审核人") + conn = get_db() + recipe = conn.execute("SELECT name FROM recipes WHERE id = ?", (recipe_id,)).fetchone() + if not recipe: + conn.close() + raise HTTPException(404, "配方不存在") + reviewer = conn.execute("SELECT role, display_name, username FROM users WHERE id = ?", (reviewer_id,)).fetchone() + if not reviewer: + conn.close() + raise HTTPException(404, "用户不存在") + conn.execute( + "INSERT INTO notifications (target_role, title, body, target_user_id) VALUES (?, ?, ?, ?)", + (reviewer["role"], "📋 请审核配方", + f"管理员指派你审核配方「{recipe['name']}」,请到管理配方页面查看并反馈意见。\n[recipe_id:{recipe_id}]", + reviewer_id) + ) + conn.commit() + conn.close() + return {"ok": True} + + @app.post("/api/recipes/adopt-batch") def adopt_batch(body: dict, user=Depends(require_role("admin"))): ids = body.get("ids", []) diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index d72ff52..116f4a3 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -130,7 +130,7 @@ function isSearchMissing(n) { } function isReviewable(n) { - if (!n.title) return false + if (!auth.isAdmin || !n.title) return false return n.title.includes('待审核') || n.title.includes('商业认证') || n.title.includes('申请') } diff --git a/frontend/src/views/RecipeManager.vue b/frontend/src/views/RecipeManager.vue index ad6fce4..c3b19ab 100644 --- a/frontend/src/views/RecipeManager.vue +++ b/frontend/src/views/RecipeManager.vue @@ -11,6 +11,14 @@ {{ r._owner_name }} + +