Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update response to include pagination #2232

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions enterprise/api/v1/views/enterprise_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from urllib.parse import quote_plus, unquote
import uuid

import crum
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -124,17 +125,25 @@ def basic_list(self, request, *arg, **kwargs):
# pylint: disable=unused-argument
def support_tool(self, request, *arg, **kwargs):
"""
Enterprise Customer's detail data for the support tool
Enterprise Customer's detail data with pagination for the support tool

Supported query param:
- uuid: filter the enterprise customer uuid .
- user_query: filter the enterprise customer name.
"""
enterprise_uuid = request.GET.get('uuid')

user_query = self.request.query_params.get("user_query", None)
queryset = self.get_queryset().order_by('name')
if enterprise_uuid:
queryset = queryset.filter(uuid=enterprise_uuid)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)

if user_query:
try:
# check that the user query is a valid uuid, else, filter by slug or name
if uuid.UUID(str(user_query)):
queryset = queryset.filter(uuid=user_query)
except ValueError:
queryset = queryset.filter(Q(slug__icontains=user_query) | Q(name__icontains=user_query))
page = self.paginate_queryset(queryset)
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)

@has_any_permissions('enterprise.can_access_admin_dashboard',
ENTERPRISE_CUSTOMER_PROVISIONING_ADMIN_ACCESS_PERMISSION)
Expand Down
Loading