chore: add debug logs and temp whitelist to permission decorator
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -67,6 +67,12 @@ def permission_required(permission_code):
|
|||||||
if user_role == 'super_admin':
|
if user_role == 'super_admin':
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
|
|
||||||
|
# TODO: 临时开发白名单 - 在数据库权限配置完备后,请删除此段代码
|
||||||
|
# 允许 admin 和 manager 角色直接访问所有接口,避免开发阶段阻塞
|
||||||
|
if user_role in ['admin', 'manager']:
|
||||||
|
logging.info(f"临时白名单放行: 角色 {user_role} 访问需要权限 {permission_code}")
|
||||||
|
return fn(*args, **kwargs)
|
||||||
|
|
||||||
# 根据角色查询数据库中的权限
|
# 根据角色查询数据库中的权限
|
||||||
try:
|
try:
|
||||||
from app.services.auth_service import AuthService
|
from app.services.auth_service import AuthService
|
||||||
@ -78,8 +84,9 @@ def permission_required(permission_code):
|
|||||||
# 合并菜单和元素权限
|
# 合并菜单和元素权限
|
||||||
all_perms = perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
all_perms = perm_dict.get('menus', []) + perm_dict.get('elements', [])
|
||||||
if permission_code not in all_perms:
|
if permission_code not in all_perms:
|
||||||
|
# 详细的调试日志
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f'Permission check failed for {permission_code}, user role {user_role}.')
|
f"权限检查失败: 角色={user_role}, 所需权限={permission_code}, 实际权限列表={all_perms}")
|
||||||
return jsonify(msg='权限不足:您没有访问此资源的权限'), 403
|
return jsonify(msg='权限不足:您没有访问此资源的权限'), 403
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
return decorator
|
return decorator
|
||||||
|
|||||||
Reference in New Issue
Block a user