]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Add new setting for maximum API page size
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>
Tue, 30 Apr 2019 06:03:00 +0000 (16:03 +1000)
committerStephen Finucane <stephen@that.guru>
Tue, 30 Apr 2019 17:36:37 +0000 (11:36 -0600)
In 41790caf59ad ("REST: Limit max page size") we limited the maximum page
size to the default page size in the settings.

This turns out to be rather restrictive, as we usually want to keep the
default page size low, but an administrator may want to allow API clients
to fetch more than that per request.

Add a new setting, MAX_REST_RESULTS_PER_PAGE, to set the maximum page size.

Closes: #202 ("Separate max API page size and default API page size into different settings")
Suggested-by: Stewart Smith <stewart@linux.ibm.com>
Suggested-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
[dja: set to 250 as per mailing list discussion]
Signed-off-by: Daniel Axtens <dja@axtens.net>
(cherry picked from commit 8fe11180a1a59f6e8e5a4441b21a3d9831f0b69d)

docs/deployment/configuration.rst
patchwork/api/base.py
patchwork/settings/base.py

index 347485636d472bc22058df97fdf155ce0a4dd504..e599522a412b0921e9cef5cb2354e4b044f09e7e 100644 (file)
@@ -88,7 +88,13 @@ Enable the :doc:`REST API <../api/rest>`.
 The number of items to include in REST API responses by default. This can be
 overridden by the ``per_page`` parameter for some endpoints.
 
-.. versionadded:: 2.0
+``MAX_REST_RESULTS_PER_PAGE``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The maximum number of items that can be requested in a REST API request using
+the ``per_page`` parameter.
+
+.. versionadded:: 2.2
 
 ``COMPAT_REDIR``
 ~~~~~~~~~~~~~~~~
index 8c38d5a1d5f4920d47e46b6a3aaad4916b3ddd8e..bf452f78b39082df2548f8f91aed800ec3422664 100644 (file)
@@ -36,7 +36,8 @@ class LinkHeaderPagination(PageNumberPagination):
        https://tools.ietf.org/html/rfc5988#section-5
        https://developer.github.com/guides/traversing-with-pagination
     """
-    page_size = max_page_size = settings.REST_RESULTS_PER_PAGE
+    page_size = settings.REST_RESULTS_PER_PAGE
+    max_page_size = settings.MAX_REST_RESULTS_PER_PAGE
     page_size_query_param = 'per_page'
 
     def get_paginated_response(self, data):
index 4b0d5513895aa5af0f266a5c0da362d493fad899..45c66da79e67723bfdc426f0794dd72c1b3b84f4 100644 (file)
@@ -220,6 +220,7 @@ ENABLE_XMLRPC = False
 ENABLE_REST_API = True
 
 REST_RESULTS_PER_PAGE = 30
+MAX_REST_RESULTS_PER_PAGE = 250
 
 # Set to True to enable redirections or URLs from previous versions
 # of patchwork