feat(devops): public feature flag endpoint pagination limited to 20 results

ref: #673 closes #663
This commit is contained in:
2025-03-10 19:37:20 +09:30
parent a69e102432
commit 6cf6a23964
3 changed files with 30 additions and 3 deletions

View File

@ -20,5 +20,4 @@
"cSpell.language": "en-AU",
"jest.enable": false,
"pylint.enabled": true,
"pylint.importStrategy": "fromEnvironment",
}

View File

@ -1,7 +1,7 @@
import importlib
from django.utils.safestring import mark_safe
from rest_framework import viewsets
from rest_framework import viewsets, pagination
from rest_framework_json_api.metadata import JSONAPIMetadata
from rest_framework.exceptions import APIException
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly
@ -802,6 +802,20 @@ class IndexViewset(
]
class StaticPageNumbering(
pagination.PageNumberPagination
):
"""Enforce Page Numbering
Enfore results per page min/max to static value that cant be changed.
"""
page_size = 20
max_page_size = 20
class PublicReadOnlyViewSet(
ReadOnlyListModelViewSet
):
@ -817,6 +831,8 @@ class PublicReadOnlyViewSet(
ReadOnlyModelViewSet (ViewSet): Common Read-Only Viewset
"""
pagination_class = StaticPageNumbering
permission_classes = [
IsAuthenticatedOrReadOnly,
]

View File

@ -8,7 +8,8 @@ from rest_framework.reverse import reverse
from access.models.organization import Organization
from api.tests.abstract.viewsets import ViewSetModel
from api.viewsets.common import PublicReadOnlyViewSet
from api.viewsets.common import PublicReadOnlyViewSet, StaticPageNumbering
from devops.models.software_enable_feature_flag import SoftwareEnableFeatureFlag
from devops.viewsets.public_feature_flag import ViewSet
@ -115,3 +116,14 @@ class ViewsetList(
view_set = self.viewset()
assert view_set.metadata_class is JSONAPIMetadata
def test_view_attr_pagination_class_value(self):
"""Attribute Test
Attribute `pagination_class` must be metadata class `StaticPageNumbering`
"""
view_set = self.viewset()
assert view_set.pagination_class is StaticPageNumbering