fix: 角色操作按俱乐部解析避免同名Role冲突

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-06 18:17:37 +08:00
parent 2573db1bbf
commit 2bbe166d63

View File

@@ -218,15 +218,17 @@ class ModifyRolePermissionView(APIView):
if '000001' not in permissions:
return Response({'code': 403, 'msg': '您无权进行此操作'})
# 获取角色(需要角色名称
# 获取角色(按当前俱乐部解析,避免多俱乐部同名角色冲突
role_code = request.data.get('role_code')
if not role_code:
return Response({'code': 400, 'msg': '缺少角色编码'})
try:
role = Role.objects.get(RoleName=role_code)
except Role.DoesNotExist:
return Response({'code': 404, 'msg': '角色不存在'})
from jituan.services.club_rbac import resolve_role_by_name, resolve_role_club_id
explicit_club = (request.data.get('target_club_id') or request.data.get('club_id') or '').strip() or None
bind_club_id = resolve_role_club_id(request, explicit_club)
role = resolve_role_by_name(role_code, bind_club_id)
if not role:
return Response({'code': 404, 'msg': '角色不存在或与当前俱乐部不匹配'})
# 超级管理员角色的特殊限制
if role.RoleName == '管理员':
@@ -285,8 +287,11 @@ class ModifyRolePermissionView(APIView):
if role.RoleName == '管理员':
role_name = role.RoleName
elif role_name and role_name != role.RoleName:
if Role.objects.filter(RoleName=role_name).exclude(RoleUUID=role.RoleUUID).exists():
return Response({'code': 400, 'msg': '角色名称已存在'})
role_club_id = getattr(role, 'ClubID', '') or ''
if Role.objects.filter(
RoleName=role_name, ClubID=role_club_id,
).exclude(RoleUUID=role.RoleUUID).exists():
return Response({'code': 400, 'msg': '该俱乐部下角色名称已存在'})
with transaction.atomic():
if role.RoleName != '管理员':
if role_name:
@@ -432,7 +437,9 @@ class GetAdminUserListView(APIView):
# 关键修正:先求值为列表,再传入 phone__in
if role_code:
target_role = Role.objects.filter(RoleName=role_code).first()
from jituan.services.club_rbac import resolve_role_by_name, resolve_role_club_id
filter_club_id = resolve_role_club_id(request)
target_role = resolve_role_by_name(role_code, filter_club_id)
if target_role:
user_uuids = list(
UserRole.objects.filter(RoleUUID=target_role.RoleUUID)