fix - show org type by binary childs
This commit is contained in:
@@ -207,7 +207,7 @@ class ProvinceViewSet(SoftDeleteMixin, ModelViewSet):
|
||||
serializer_class = ProvinceSerializer
|
||||
|
||||
|
||||
class OrganizationTypeViewSet(SoftDeleteMixin, ModelViewSet):
|
||||
class OrganizationTypeViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet):
|
||||
""" Crud operations for Organization Type model """ #
|
||||
queryset = OrganizationType.objects.all()
|
||||
serializer_class = OrganizationTypeSerializer
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import typing
|
||||
|
||||
from apps.authentication.models import Organization
|
||||
from apps.authentication.models import Organization, OrganizationType
|
||||
|
||||
|
||||
def get_users_of_organization(org: Organization) -> typing.Any:
|
||||
@@ -28,3 +28,15 @@ def get_all_org_child(org: Organization = None) -> typing.Any:
|
||||
descendants.append(child)
|
||||
descendants.extend(get_all_org_child(child))
|
||||
return descendants
|
||||
|
||||
|
||||
def get_all_org_type_child(org_type: OrganizationType = None) -> typing.Any:
|
||||
"""
|
||||
get all child of an organization
|
||||
"""
|
||||
descendants = []
|
||||
children = org_type.children.all()
|
||||
for child in children:
|
||||
descendants.append(child)
|
||||
descendants.extend(get_all_org_type_child(child))
|
||||
return descendants
|
||||
|
||||
@@ -1,7 +1,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.authentication.services.service import get_all_org_child, get_all_org_type_child
|
||||
from apps.authentication.services.visibility_services import apply_visibility_filter
|
||||
from apps.authorization.services.role_child import get_all_role_child
|
||||
from apps.core.models import MobileTest, SystemConfig
|
||||
@@ -50,9 +50,12 @@ class BaseViewSet(RegionFilterMixin, viewsets.ModelViewSet):
|
||||
elif model_name == 'organization':
|
||||
queryset = queryset.filter(id__in=[org.id for org in child_orgs])
|
||||
|
||||
elif model_name == 'organizationtype': # noqa
|
||||
|
||||
queryset = queryset.filter(id__in=[org_type.id for org_type in get_all_org_type_child(org.type)])
|
||||
|
||||
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