1
This commit is contained in:
@@ -218,7 +218,21 @@ async def update_user_menus(
|
||||
raise HTTPException(status_code=404, detail="用户不存在")
|
||||
user.allowed_menus = req.allowed_menus
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, f"更新菜单权限", "PUT", f"/admin/users/{user_id}/menus")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"更新菜单权限",
|
||||
"PUT",
|
||||
f"/admin/users/{user_id}/menus",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"allowed_menus": req.allowed_menus,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
@@ -259,7 +273,22 @@ async def adjust_credits(
|
||||
f"您的积分已{'增加' if req.amount > 0 else '扣除'}{abs(req.amount)}积分。原因:{req.description}",
|
||||
"credit",
|
||||
)
|
||||
await log_operation(db, admin.id, admin.username, f"调整积分 {'+' if req.amount > 0 else ''}{req.amount}", "POST", f"/admin/users/{user_id}/credits")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"调整积分 {'+' if req.amount > 0 else ''}{req.amount}",
|
||||
"POST",
|
||||
f"/admin/users/{user_id}/credits",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"amount": req.amount,
|
||||
"description": req.description,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
@@ -275,7 +304,21 @@ async def update_user_status(
|
||||
update(User).where(User.id == user_id).values(is_active=is_active)
|
||||
)
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, f"{'启用' if is_active else '禁用'}用户", "PUT", f"/admin/users/{user_id}/status")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"{'启用' if is_active else '禁用'}用户",
|
||||
"PUT",
|
||||
f"/admin/users/{user_id}/status",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"is_active": is_active,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
@@ -295,7 +338,21 @@ async def update_user_admin_status(
|
||||
raise HTTPException(status_code=400, detail="仅后台用户支持设置超级管理员状态")
|
||||
user.is_admin = is_admin
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, f"{is_admin and '设为' or '取消'}超级管理员", "PUT", f"/admin/users/{user_id}/admin-status")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"{is_admin and '设为' or '取消'}超级管理员",
|
||||
"PUT",
|
||||
f"/admin/users/{user_id}/admin-status",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"is_admin": is_admin,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
@@ -314,7 +371,21 @@ async def update_user_frontend_kind(
|
||||
raise HTTPException(status_code=400, detail="仅前台用户支持设置内部/外部归类")
|
||||
user.frontend_user_kind = req.frontend_user_kind or FrontendUserKind.EXTERNAL.value
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, f"设置前台用户归类为 {user.frontend_user_kind}", "PUT", f"/admin/users/{user_id}/frontend-kind")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"设置前台用户归类为 {user.frontend_user_kind}",
|
||||
"PUT",
|
||||
f"/admin/users/{user_id}/frontend-kind",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"frontend_user_kind": user.frontend_user_kind,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return user
|
||||
|
||||
|
||||
@@ -354,7 +425,21 @@ async def reset_user_password(
|
||||
raise HTTPException(status_code=404, detail="用户不存在")
|
||||
user.hashed_password = hash_password(req.new_password)
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, f"重置密码", "PUT", f"/admin/users/{user_id}/reset-password")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
f"重置密码",
|
||||
"PUT",
|
||||
f"/admin/users/{user_id}/reset-password",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"new_password": "***",
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
@@ -372,7 +457,21 @@ async def admin_change_password(
|
||||
raise HTTPException(status_code=400, detail="密码至少6位")
|
||||
admin.hashed_password = hash_password(new_password)
|
||||
await db.flush()
|
||||
await log_operation(db, admin.id, admin.username, "修改密码", "POST", "/admin/change-password")
|
||||
await log_operation(
|
||||
db,
|
||||
admin.id,
|
||||
admin.username,
|
||||
"修改密码",
|
||||
"POST",
|
||||
"/admin/change-password",
|
||||
detail=json.dumps(
|
||||
{
|
||||
"old_password": "***",
|
||||
"new_password": "***",
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
return {"message": "密码修改成功"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user