fix: 多俱乐部下单 openid;集团超管可切俱乐部

This commit is contained in:
XingQue
2026-06-24 20:45:40 +08:00
parent 08fc8f50f3
commit a693e35177
4 changed files with 81 additions and 25 deletions

View File

@@ -8,6 +8,12 @@ from jituan.constants import (
)
from jituan.models import AdminAssignment, Club
GROUP_MANAGE_ROLES = frozenset({
'GROUP_OWNER',
'GROUP_SUPER_ADMIN',
})
def build_admin_club_context(user):
"""
根据 admin_assignment + 超管推断后台登录后的俱乐部上下文。
@@ -30,16 +36,21 @@ def build_admin_club_context(user):
for c in clubs_qs
]
if is_super and not assignments:
# 系统超管:始终集团视角 + 全部俱乐部(不受任职记录限制)
if is_super:
role_code = 'GROUP_SUPER_ADMIN'
if assignments:
primary = next((a for a in assignments if a.is_primary), assignments[0])
role_code = primary.role_code or role_code
return _pack(
scope=DATA_SCOPE_ALL,
club_id=CLUB_ID_DEFAULT,
is_group_admin=True,
assignments=[],
assignments=assignments,
clubs=all_clubs,
can_switch_club=True,
role_code='GROUP_SUPER_ADMIN',
role_name=ADMIN_ROLE_LABELS['GROUP_SUPER_ADMIN'],
role_code=role_code,
role_name=ADMIN_ROLE_LABELS.get(role_code, role_code),
)
if not assignments:
@@ -55,7 +66,10 @@ def build_admin_club_context(user):
)
primary = next((a for a in assignments if a.is_primary), assignments[0])
has_group = any(a.club_id is None or a.data_scope == DATA_SCOPE_ALL for a in assignments)
has_group = any(
a.club_id is None or a.data_scope == DATA_SCOPE_ALL
for a in assignments
)
allowed_club_ids = {a.club_id for a in assignments if a.club_id}
if has_group:
@@ -82,6 +96,26 @@ def build_admin_club_context(user):
)
def can_manage_admin_assignments(user, permissions=None):
"""是否可维护数据范围任职(超管 / 000001 / 集团超管任职)。"""
permissions = permissions or []
is_super = (
bool(user.IsSuperuser)
or user.UserType == 'admin'
or getattr(user, 'Phone', '') in SUPER_ADMIN_PHONES
)
if is_super or '000001' in permissions:
return True
ctx = build_admin_club_context(user)
if ctx.get('is_group_admin') and ctx.get('role_code') in GROUP_MANAGE_ROLES:
return True
return any(
a.role_code in GROUP_MANAGE_ROLES
and (a.club_id is None or a.data_scope == DATA_SCOPE_ALL)
for a in AdminAssignment.query.filter(yonghuid=user.UserUID, status=1)
)
def _pack(scope, club_id, is_group_admin, assignments, clubs, can_switch_club,
role_code, role_name):
return {
@@ -91,7 +125,10 @@ def _pack(scope, club_id, is_group_admin, assignments, clubs, can_switch_club,
'role_code': role_code,
'role_name': role_name,
'perm_source': 'gvsdsdk',
'perm_note': '功能菜单权限仍由 gvsdsdk UserRole→Permission 控制;本表仅管数据范围',
'perm_note': (
'【功能权限】在「角色管理」绑 gvsdsdk 角色(如 caiwu、dingdan、000001'
'【数据范围】在「数据范围配置」维护任职(能看/管哪个俱乐部)。两套独立。'
),
'assignments': [
{
'club_id': a.club_id,