fix: clearer no-perm message with bound roles
This commit is contained in:
@@ -60,3 +60,28 @@ def count_role_users_in_scope(role, request, kefu_user_uuids):
|
||||
|
||||
def role_name_exists(role_name, club_id):
|
||||
return Role.objects.filter(RoleName=role_name, ClubID=club_id or '').exists()
|
||||
|
||||
|
||||
def resolve_role_by_name(role_name, club_id=None):
|
||||
"""按角色名解析 Role;优先匹配用户俱乐部,其次集团全局角色(club_id 为空)。"""
|
||||
name = (role_name or '').strip()
|
||||
if not name:
|
||||
return None
|
||||
qs = Role.objects.filter(RoleName=name, RoleStatus=1)
|
||||
cid = (club_id or '').strip()
|
||||
if cid:
|
||||
hit = qs.filter(ClubID=cid).first()
|
||||
if hit:
|
||||
return hit
|
||||
return qs.filter(ClubID='').first() or qs.first()
|
||||
|
||||
|
||||
def user_bound_role_names(user):
|
||||
uuids = list(
|
||||
UserRole.objects.filter(UserUUID=user.UserUUID).values_list('RoleUUID', flat=True)
|
||||
)
|
||||
if not uuids:
|
||||
return []
|
||||
return list(
|
||||
Role.objects.filter(RoleUUID__in=uuids, RoleStatus=1).values_list('RoleName', flat=True)
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ from jituan.services.admin_context import (
|
||||
can_manage_admin_assignments,
|
||||
is_system_super_admin,
|
||||
)
|
||||
from jituan.services.club_rbac import user_bound_role_names
|
||||
from jituan.services.kefu_menu_definitions import KEFU_MENU_ROW_DEFS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -132,6 +133,7 @@ def build_menu_access_payload(request, username=None):
|
||||
'visible_page_ids': sorted(set(visible_ids)),
|
||||
'visible_paths': visible_paths,
|
||||
'permission_codes': _permission_codes_list(permissions),
|
||||
'role_names': user_bound_role_names(request.user),
|
||||
'can_switch_club': bool(club_ctx.get('can_switch_club')),
|
||||
'is_group_admin': bool(club_ctx.get('is_group_admin')),
|
||||
'menu_ready': True,
|
||||
|
||||
@@ -170,6 +170,7 @@ class ClubKefuLoginView(APIView):
|
||||
'visible_page_ids': [],
|
||||
'visible_paths': [],
|
||||
'permission_codes': [],
|
||||
'role_names': [],
|
||||
'can_switch_club': False,
|
||||
'is_group_admin': False,
|
||||
'menu_ready': False,
|
||||
|
||||
Reference in New Issue
Block a user