organization limit for quota - get org childs
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import typing
|
||||
from rest_framework.permissions import AllowAny
|
||||
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
||||
from rest_framework.decorators import action, permission_classes
|
||||
from apps.authentication import permissions as auth_permissions
|
||||
@@ -16,7 +14,9 @@ from apps.core.pagination import CustomPageNumberPagination
|
||||
from apps.authorization.api.v1 import api as authorize_view
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from apps.authentication.tools import get_token_jti
|
||||
from common.helpers import get_organization_by_user
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.permissions import AllowAny
|
||||
from apps.authentication.models import (
|
||||
User,
|
||||
City,
|
||||
@@ -35,6 +35,7 @@ from rest_framework import status
|
||||
from django.db import transaction
|
||||
from common.sms import send_sms
|
||||
import random
|
||||
import typing
|
||||
|
||||
|
||||
class CustomizedTokenObtainPairView(TokenObtainPairView):
|
||||
@@ -197,6 +198,14 @@ class OrganizationViewSet(ModelViewSet):
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrganizationSerializer
|
||||
|
||||
def get_all_org_child(self, org):
|
||||
descendants = []
|
||||
children = org.parents.all()
|
||||
for child in children:
|
||||
descendants.append(child)
|
||||
descendants.extend(self.get_all_org_child(child))
|
||||
return descendants
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
@@ -274,6 +283,24 @@ class OrganizationViewSet(ModelViewSet):
|
||||
serializer = self.serializer_class(queryset, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
url_path='child_organizations',
|
||||
url_name='child_organizations',
|
||||
name='child_organizations'
|
||||
)
|
||||
@transaction.atomic
|
||||
def get_child_organizations(self, request):
|
||||
organization = get_organization_by_user(request.user)
|
||||
child_organizations = self.get_all_org_child(organization)
|
||||
|
||||
page = self.paginate_queryset(child_organizations) # paginate queryset
|
||||
|
||||
if page is not None:
|
||||
serializer = self.serializer_class(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
class BankAccountViewSet(ModelViewSet):
|
||||
""" Crud operations for bank account model """ #
|
||||
|
||||
Reference in New Issue
Block a user