role childs service add to BaseViewSet
This commit is contained in:
@@ -2,6 +2,7 @@ from rest_framework import viewsets
|
||||
|
||||
from apps.authentication.mixins.region_filter import RegionFilterMixin, get_organization_by_user
|
||||
from apps.authentication.services.service import get_all_org_child
|
||||
from apps.authorization.services.role_child import get_all_role_child
|
||||
from apps.core.models import MobileTest, SystemConfig
|
||||
from apps.core.serializers import MobileTestSerializer, SystemConfigSerializer
|
||||
|
||||
@@ -23,7 +24,8 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
|
||||
queryset = self.filter_by_region(queryset, org=True)
|
||||
|
||||
if user_relation.exists():
|
||||
if not user_relation.first().role.type.key == 'ADM':
|
||||
user_relation = user_relation.first()
|
||||
if not user_relation.role.type.key == 'ADM':
|
||||
# get all child orgs
|
||||
child_orgs = get_all_org_child(org)
|
||||
|
||||
@@ -35,6 +37,9 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
|
||||
elif model_name == 'organization':
|
||||
queryset = queryset.filter(id__in=[org.id for org in child_orgs])
|
||||
|
||||
elif model_name == 'role':
|
||||
queryset = queryset.filter(id__in=[role.id for role in get_all_role_child(user_relation.role)])
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user