From 67872f823c984627bd66e47c2cf32b66233701ae Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 19 Jun 2026 12:27:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=20=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98=20=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/utils.py b/backend/utils.py index 03603e1..4764fb0 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -61,6 +61,12 @@ def _record_abnormal(account_id, request, attempt_type, detail=''): logger.error(f"记录异常日志失败: {e}") +class _AllPermissions(list): + """拥有 000001 超级管理权限时使用,使任何权限码 in 检查都返回 True""" + def __contains__(self, item): + return True + + def verify_kefu_permission(request, username_from_frontend=None): """ 验证客服/管理员身份,并返回该用户的所有权限列表(基于新RBAC表) @@ -129,15 +135,10 @@ def verify_kefu_permission(request, username_from_frontend=None): if current_user.IsSuperuser and '000001' not in permissions: permissions.insert(0, '000001') - # 拥有 000001(超级管理权限)的用户自动获得所有功能权限码 + # 拥有 000001(超级管理权限)的用户自动获得所有功能权限 + # 使用 _AllPermissions 包装,使任何权限码检查都自动通过 if '000001' in permissions: - _ALL_FEATURE_PERMS = { - 'bankuai', 'caiwu', 'huiyuancaiwu', 'dingdancaiwu', - 'qtczcaiwu', 'kaohepeizhi', - } - for p in _ALL_FEATURE_PERMS: - if p not in permissions: - permissions.append(p) + permissions = _AllPermissions(permissions) if not permissions: logger.warning(f"用户 {current_user.Phone} 没有任何权限,请检查角色分配")