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