|
|
|
@ -6,12 +6,8 @@ from rbac.models import Role
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserFilter(BaseFilterSet): |
|
|
|
|
system_roles = filters.ModelChoiceFilter( |
|
|
|
|
queryset=Role.objects.filter(scope='system'), method='filter_system_roles' |
|
|
|
|
) |
|
|
|
|
org_roles = filters.ModelChoiceFilter( |
|
|
|
|
queryset=Role.objects.filter(scope='org'), method='filter_org_roles' |
|
|
|
|
) |
|
|
|
|
system_roles = filters.CharFilter(method='filter_system_roles') |
|
|
|
|
org_roles = filters.CharFilter(method='filter_org_roles') |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = User |
|
|
|
@ -22,16 +18,18 @@ class UserFilter(BaseFilterSet):
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def filter_system_roles(queryset, name, value): |
|
|
|
|
queryset = queryset.prefetch_related('role_bindings')\ |
|
|
|
|
.filter(role_bindings__role_id=value.id)\ |
|
|
|
|
.distinct() |
|
|
|
|
queryset = queryset.prefetch_related('role_bindings') \ |
|
|
|
|
.filter( |
|
|
|
|
role_bindings__role__name=value, |
|
|
|
|
role_bindings__role__scope='system' |
|
|
|
|
).distinct() |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def filter_org_roles(queryset, name, value): |
|
|
|
|
queryset = queryset.prefetch_related('role_bindings') \ |
|
|
|
|
.filter(role_bindings__role_id=value.id) \ |
|
|
|
|
.distinct() |
|
|
|
|
.filter( |
|
|
|
|
role_bindings__role__name=value, |
|
|
|
|
role_bindings__role__scope='org' |
|
|
|
|
).distinct() |
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|