From 846e57dd4136164de2a7c2de6c28ba24ba3a9884 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 23 Dec 2025 11:37:51 +0330 Subject: [PATCH] import / fix --> unions list / paginate orgs list in rancher link --- apps/authentication/api/v1/api.py | 20 +++++++++++++++++++ .../services/rancher_org_link_services.py | 6 +++--- apps/herd/web/api/v1/api.py | 5 +++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/authentication/api/v1/api.py b/apps/authentication/api/v1/api.py index 2b1d14e..c215a2f 100644 --- a/apps/authentication/api/v1/api.py +++ b/apps/authentication/api/v1/api.py @@ -388,6 +388,26 @@ class OrganizationViewSet(BaseViewSet, ModelViewSet, DynamicSearchMixin): serializer = self.serializer_class(page, many=True) return self.get_paginated_response(serializer.data) + @action( + methods=['get'], + detail=False, + url_path='get_union_orgs', + url_name='get_union_orgs', + name='get_union_orgs', + ) + def get_union_orgs(self, request): + """ + list of unions + """ + + unions = self.get_queryset(visibility_by_org_scope=True) + + page = self.paginate_queryset(unions.filter(type__key='U')) + if page is not None: # noqa + serializer = self.serializer_class(page, many=True) + return self.get_paginated_response(serializer.data) + return Response(status=status.HTTP_200_OK) + @action( methods=['get'], detail=False, diff --git a/apps/herd/services/rancher_org_link_services.py b/apps/herd/services/rancher_org_link_services.py index 50354cc..7612a33 100644 --- a/apps/herd/services/rancher_org_link_services.py +++ b/apps/herd/services/rancher_org_link_services.py @@ -10,19 +10,19 @@ class RancherOrganizationService: different services of ranchers linked to organization """ - def orgs_linked_rancher(self, org: Organization = None): + def orgs_linked_rancher(self, org: Organization = None, org_type_key: str = None): """ list of organizations with their information of rancher, herd, .... """ if org.type.key != 'ADM': organizations = get_all_org_child(org) else: - organizations = Organization.objects.filter(type__key='CO') + organizations = Organization.objects.filter(type__key=org_type_key) linked_qs = RancherOrganizationLink.objects.select_related( 'rancher', 'organization' - ).filter(organization__in=organizations, organization__type__key='CO') + ).filter(organization__in=organizations, organization__type__key=org_type_key) organizations = organizations.annotate( rancher_count=Count( diff --git a/apps/herd/web/api/v1/api.py b/apps/herd/web/api/v1/api.py index 6c4df10..9d324a8 100644 --- a/apps/herd/web/api/v1/api.py +++ b/apps/herd/web/api/v1/api.py @@ -303,9 +303,10 @@ class RancherOrganizationLinkViewSet( list of organizations with rancher information """ org = get_organization_by_user(request.user) - result = self.orgs_linked_rancher(org=org) + result = self.orgs_linked_rancher(org=org, org_type_key='CO') - return Response(result) + page = self.paginate_queryset(result) # paginate queryset + return self.get_paginated_response(result) @action( methods=['get'],