Compare commits
3 Commits
5a34b11720
...
feat/next-
| Author | SHA1 | Date | |
|---|---|---|---|
| f2c95985cf | |||
| ac3abc3c84 | |||
| 3a7e52360c |
@@ -1094,6 +1094,9 @@ def delete_user(user_id: int, user=Depends(require_role("admin"))):
|
|||||||
@app.put("/api/users/{user_id}")
|
@app.put("/api/users/{user_id}")
|
||||||
def update_user(user_id: int, body: UserUpdate, user=Depends(require_role("admin"))):
|
def update_user(user_id: int, body: UserUpdate, user=Depends(require_role("admin"))):
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
target = conn.execute("SELECT role, display_name, username FROM users WHERE id = ?", (user_id,)).fetchone()
|
||||||
|
old_role = target["role"] if target else "unknown"
|
||||||
|
target_name = (target["display_name"] or target["username"]) if target else "unknown"
|
||||||
if body.role is not None:
|
if body.role is not None:
|
||||||
if body.role == "admin":
|
if body.role == "admin":
|
||||||
conn.close()
|
conn.close()
|
||||||
@@ -1101,8 +1104,15 @@ def update_user(user_id: int, body: UserUpdate, user=Depends(require_role("admin
|
|||||||
conn.execute("UPDATE users SET role = ?, role_changed_at = datetime('now') WHERE id = ?", (body.role, user_id))
|
conn.execute("UPDATE users SET role = ?, role_changed_at = datetime('now') WHERE id = ?", (body.role, user_id))
|
||||||
if body.display_name is not None:
|
if body.display_name is not None:
|
||||||
conn.execute("UPDATE users SET display_name = ? WHERE id = ?", (body.display_name, user_id))
|
conn.execute("UPDATE users SET display_name = ? WHERE id = ?", (body.display_name, user_id))
|
||||||
log_audit(conn, user["id"], "update_user", "user", user_id, None,
|
role_labels = {"admin": "管理员", "senior_editor": "高级编辑", "editor": "编辑", "viewer": "查看者"}
|
||||||
json.dumps({"role": body.role, "display_name": body.display_name}))
|
detail = {}
|
||||||
|
if body.role is not None and body.role != old_role:
|
||||||
|
detail["from_role"] = role_labels.get(old_role, old_role)
|
||||||
|
detail["to_role"] = role_labels.get(body.role, body.role)
|
||||||
|
if body.display_name is not None:
|
||||||
|
detail["display_name"] = body.display_name
|
||||||
|
log_audit(conn, user["id"], "update_user", "user", user_id, target_name,
|
||||||
|
json.dumps(detail, ensure_ascii=False))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|||||||
@@ -153,9 +153,10 @@ function parsedDetail(log) {
|
|||||||
try {
|
try {
|
||||||
const d = JSON.parse(log.detail)
|
const d = JSON.parse(log.detail)
|
||||||
const parts = []
|
const parts = []
|
||||||
|
if (d.from_role && d.to_role) parts.push(`${d.from_role} → ${d.to_role}`)
|
||||||
if (d.from_user) parts.push(`来自: ${d.from_user}`)
|
if (d.from_user) parts.push(`来自: ${d.from_user}`)
|
||||||
if (d.reason) parts.push(`原因: ${d.reason}`)
|
if (d.reason) parts.push(`原因: ${d.reason}`)
|
||||||
if (d.role) parts.push(`角色: ${d.role}`)
|
if (d.business_name) parts.push(`商户: ${d.business_name}`)
|
||||||
if (d.display_name) parts.push(`显示名: ${d.display_name}`)
|
if (d.display_name) parts.push(`显示名: ${d.display_name}`)
|
||||||
if (d.original_log_id) parts.push(`恢复自 #${d.original_log_id}`)
|
if (d.original_log_id) parts.push(`恢复自 #${d.original_log_id}`)
|
||||||
if (parts.length) return parts.join(' · ')
|
if (parts.length) return parts.join(' · ')
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
<span v-if="!auth.isAdmin" class="contrib-tag">已贡献 {{ sharedCount.adopted }}/{{ sharedCount.total }} 条</span>
|
<span v-if="!auth.isAdmin" class="contrib-tag">已贡献 {{ sharedCount.adopted }}/{{ sharedCount.total }} 条</span>
|
||||||
<span class="toggle-icon">{{ showMyRecipes ? '▾' : '▸' }}</span>
|
<span class="toggle-icon">{{ showMyRecipes ? '▾' : '▸' }}</span>
|
||||||
</h3>
|
</h3>
|
||||||
<template v-if="showMyRecipes || manageSearch">
|
<template v-if="showMyRecipes || manageSearch || selectedTags.length">
|
||||||
<div class="recipe-list">
|
<div class="recipe-list">
|
||||||
<div
|
<div
|
||||||
v-for="d in myFilteredRecipes"
|
v-for="d in myFilteredRecipes"
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
<span>🌿 公共配方库 ({{ publicRecipes.length }})</span>
|
<span>🌿 公共配方库 ({{ publicRecipes.length }})</span>
|
||||||
<span class="toggle-icon">{{ showPublicRecipes ? '▾' : '▸' }}</span>
|
<span class="toggle-icon">{{ showPublicRecipes ? '▾' : '▸' }}</span>
|
||||||
</h3>
|
</h3>
|
||||||
<div v-if="showPublicRecipes || manageSearch" class="recipe-list">
|
<div v-if="showPublicRecipes || manageSearch || selectedTags.length" class="recipe-list">
|
||||||
<div
|
<div
|
||||||
v-for="r in publicFilteredRecipes"
|
v-for="r in publicFilteredRecipes"
|
||||||
:key="r._id"
|
:key="r._id"
|
||||||
@@ -601,15 +601,22 @@ async function applyBatchTags() {
|
|||||||
for (const id of pubIds) {
|
for (const id of pubIds) {
|
||||||
const recipe = recipeStore.recipes.find(r => r._id === id)
|
const recipe = recipeStore.recipes.find(r => r._id === id)
|
||||||
if (!recipe) continue
|
if (!recipe) continue
|
||||||
|
let newTags = [...recipe.tags]
|
||||||
let changed = false
|
let changed = false
|
||||||
for (const t of tagsToAdd) {
|
for (const t of tagsToAdd) {
|
||||||
if (!recipe.tags.includes(t)) { recipe.tags.push(t); changed = true }
|
if (!newTags.includes(t)) { newTags.push(t); changed = true }
|
||||||
}
|
}
|
||||||
for (const t of tagsToRemove) {
|
for (const t of tagsToRemove) {
|
||||||
const idx = recipe.tags.indexOf(t)
|
const idx = newTags.indexOf(t)
|
||||||
if (idx >= 0) { recipe.tags.splice(idx, 1); changed = true }
|
if (idx >= 0) { newTags.splice(idx, 1); changed = true }
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
await api(`/api/recipes/${recipe._id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ tags: newTags }),
|
||||||
|
})
|
||||||
|
recipe.tags = newTags
|
||||||
}
|
}
|
||||||
if (changed) await recipeStore.saveRecipe(recipe)
|
|
||||||
}
|
}
|
||||||
for (const id of diaryIds) {
|
for (const id of diaryIds) {
|
||||||
const d = diaryStore.userDiary.find(r => r.id === id)
|
const d = diaryStore.userDiary.find(r => r.id === id)
|
||||||
|
|||||||
Reference in New Issue
Block a user