From fb8f3641a8bc69cf48c1b7086fc5220f6a697afe Mon Sep 17 00:00:00 2001 From: Katrina Nguyen <71999631+katrinan029@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:09:41 -0700 Subject: [PATCH] feat: add pagination to the support tool customer list (#2252) --- CHANGELOG.rst | 4 ++++ enterprise/__init__.py | 2 +- enterprise/api/v1/views/enterprise_customer.py | 11 ++++++++--- tests/test_enterprise/api/test_views.py | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4bddf28a4..4b9a5aea7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * nothing unreleased +[4.25.17] +--------- +* feat: add pagination to the support tool customer list + [4.25.16] --------- * feat: add a waffle flag for enterprise groups v2 feature diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 6eb243c9f..a2b9cf09d 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.25.16" +__version__ = "4.25.17" diff --git a/enterprise/api/v1/views/enterprise_customer.py b/enterprise/api/v1/views/enterprise_customer.py index bfa4d63a5..cd4660dbe 100644 --- a/enterprise/api/v1/views/enterprise_customer.py +++ b/enterprise/api/v1/views/enterprise_customer.py @@ -124,17 +124,22 @@ 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 = request.GET.get("user_query", None) queryset = self.get_queryset().order_by('name') + if user_query: + queryset = queryset.filter(Q(slug__icontains=user_query) | Q(name__icontains=user_query)) if enterprise_uuid: queryset = queryset.filter(uuid=enterprise_uuid) - serializer = self.get_serializer(queryset, many=True) - return Response(serializer.data) + 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) diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index d01490120..aa61af33d 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -1946,7 +1946,7 @@ def test_enterprise_customer_support_tool( self.create_items(factory, model_items) response = self.client.get(settings.TEST_SERVER + url) response = self.load_json(response.content) - assert sorted(expected_json, key=sorting_key) == sorted(response, key=sorting_key) + assert sorted(expected_json, key=sorting_key) == sorted(response['results'], key=sorting_key) @ddt.data( # Request missing required permissions query param.