fix: SUPERVISOR不能修改/删除SUPER_ADMIN账号, 不能删自己
This commit is contained in:
@ -308,6 +308,10 @@ class AuthService:
|
|||||||
if not user:
|
if not user:
|
||||||
raise Exception("用户不存在")
|
raise Exception("用户不存在")
|
||||||
|
|
||||||
|
# 主管不能修改超级管理员
|
||||||
|
if operator_role_upper == UserRole.SUPERVISOR and (user.role or '').upper() == UserRole.SUPER_ADMIN:
|
||||||
|
raise Exception("权限不足:主管无法修改超级管理员账号")
|
||||||
|
|
||||||
# 1. 更新基本信息
|
# 1. 更新基本信息
|
||||||
if 'role' in data:
|
if 'role' in data:
|
||||||
valid_roles = [
|
valid_roles = [
|
||||||
@ -378,6 +382,17 @@ class AuthService:
|
|||||||
if not user:
|
if not user:
|
||||||
raise Exception("用户不存在")
|
raise Exception("用户不存在")
|
||||||
|
|
||||||
|
# 任何人都不能删除自己
|
||||||
|
from flask_jwt_extended import get_jwt
|
||||||
|
claims = get_jwt()
|
||||||
|
current_user_id = claims.get('sub')
|
||||||
|
if str(current_user_id) == str(user_id):
|
||||||
|
raise Exception("不能删除自己的账号")
|
||||||
|
|
||||||
|
# 主管不能删除超级管理员
|
||||||
|
if operator_role_upper == UserRole.SUPERVISOR and (user.role or '').upper() == UserRole.SUPER_ADMIN:
|
||||||
|
raise Exception("权限不足:主管无法删除超级管理员账号")
|
||||||
|
|
||||||
# 权限校验
|
# 权限校验
|
||||||
if operator_role_upper == UserRole.SUPER_ADMIN:
|
if operator_role_upper == UserRole.SUPER_ADMIN:
|
||||||
pass # 超管可删除任何人
|
pass # 超管可删除任何人
|
||||||
|
|||||||
Reference in New Issue
Block a user