diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 97bbc56091..2c12178aaa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,6 +7,7 @@ Changelog * Fix: "Open Link in New Tab" on a right arrow in page explorer should open page list (Emily Horsman) * Fix: Using `order_by_relevance=False` when searching with PostgreSQL now works (Mitchel Cabuloy) * Fix: Inline panel first and last sorting arrows correctly hidden in non-default tabs (Matt Westcott) + * Fix: `WAGTAILAPI_LIMIT_MAX` now accepts None to disable limiting (jcronyn) 1.12 LTS (21.08.2017) ~~~~~~~~~~~~~~~~~~~~~ diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index e7ff6bdd61..23be70ab8b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -250,6 +250,7 @@ Contributors * Edwar Baron * Tomasz Knapik * Emily Horsman +* jcronyn Translators =========== diff --git a/docs/advanced_topics/api/v2/configuration.rst b/docs/advanced_topics/api/v2/configuration.rst index 6e755c828d..50eaa913d1 100644 --- a/docs/advanced_topics/api/v2/configuration.rst +++ b/docs/advanced_topics/api/v2/configuration.rst @@ -274,4 +274,4 @@ endpoints. (default: 20) This allows you to change the maximum number of results a user can request at a -time. This applies to all endpoints. +time. This applies to all endpoints. Set to ``None`` for no limit. diff --git a/docs/reference/contrib/api/configuration.rst b/docs/reference/contrib/api/configuration.rst index 5726fcb113..71677a86f1 100644 --- a/docs/reference/contrib/api/configuration.rst +++ b/docs/reference/contrib/api/configuration.rst @@ -18,7 +18,7 @@ Setting this to false will disable full text search. This applies to all endpoin ``WAGTAILAPI_LIMIT_MAX`` (default: 20) -This allows you to change the maximum number of results a user can request at a time. This applies to all endpoints. +This allows you to change the maximum number of results a user can request at a time. This applies to all endpoints. Set to ``None`` to remove maximum. Adding more fields to the pages endpoint diff --git a/docs/reference/contrib/api/usage.rst b/docs/reference/contrib/api/usage.rst index 1d21301dd0..e3a774997c 100644 --- a/docs/reference/contrib/api/usage.rst +++ b/docs/reference/contrib/api/usage.rst @@ -417,7 +417,7 @@ Like filtering, it is also possible to order on database fields. The endpoint ac Pagination ^^^^^^^^^^ -Pagination is done using two query parameters called ``limit`` and ``offset``. ``limit`` sets the number of results to return and ``offset`` is the index of the first result to return. The default and maximum value for ``limit`` is ``20``. The maximum value can be changed using the ``WAGTAILAPI_LIMIT_MAX`` setting. +Pagination is done using two query parameters called ``limit`` and ``offset``. ``limit`` sets the number of results to return and ``offset`` is the index of the first result to return. The default and maximum value for ``limit`` is ``20``. The maximum value can be changed using the ``WAGTAILAPI_LIMIT_MAX`` setting. Set ``WAGTAILAPI_LIMIT_MAX`` to ``None`` for no maximum value. .. code-block:: text @@ -745,7 +745,8 @@ The images endpoint also accepts the ``order`` parameter which should be set to Pagination ^^^^^^^^^^ -Pagination is done using two query parameters called ``limit`` and ``offset``. ``limit`` sets the number of results to return and ``offset`` is the index of the first result to return. The default and maximum value for ``limit`` is ``20``. The maximum value can be changed using the ``WAGTAILAPI_LIMIT_MAX`` setting. +Pagination is done using two query parameters called ``limit`` and ``offset``. ``limit`` sets the number of results to return and ``offset`` is the index of the first result to return. The default and maximum value for ``limit`` is ``20``. The maximum value can be changed using the ``WAGTAILAPI_LIMIT_MAX`` setting. Set ``WAGTAILAPI_LIMIT_MAX`` to ``None`` for no maximum value. + .. code-block:: text diff --git a/docs/releases/1.13.rst b/docs/releases/1.13.rst index 0aa05cab9d..cc46442ef8 100644 --- a/docs/releases/1.13.rst +++ b/docs/releases/1.13.rst @@ -21,6 +21,8 @@ Bug fixes * "Open Link in New Tab" on a right arrow in page explorer should open page list (Emily Horsman) * Using ``order_by_relevance=False`` when searching with PostgreSQL now works (Mitchel Cabuloy) * Inline panel first and last sorting arrows correctly hidden in non-default tabs (Matt Westcott) + * ``WAGTAILAPI_LIMIT_MAX`` now accepts None to disable limiting (jcronyn) + Upgrade considerations ====================== diff --git a/wagtail/api/v2/pagination.py b/wagtail/api/v2/pagination.py index 8dfd3b573e..4e27d8a874 100644 --- a/wagtail/api/v2/pagination.py +++ b/wagtail/api/v2/pagination.py @@ -20,9 +20,10 @@ class WagtailPagination(BasePagination): raise BadRequestError("offset must be a positive integer") try: - limit = int(request.GET.get('limit', min(20, limit_max))) + limit_default = 20 if not limit_max else min(20, limit_max) + limit = int(request.GET.get('limit', limit_default)) - if limit > limit_max: + if limit_max and limit > limit_max: raise BadRequestError("limit cannot be higher than %d" % limit_max) assert limit >= 0 diff --git a/wagtail/api/v2/tests/test_documents.py b/wagtail/api/v2/tests/test_documents.py index da739ebb58..6aaa76df80 100644 --- a/wagtail/api/v2/tests/test_documents.py +++ b/wagtail/api/v2/tests/test_documents.py @@ -271,6 +271,14 @@ class TestDocumentListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['items']), get_document_model().objects.count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20) diff --git a/wagtail/api/v2/tests/test_images.py b/wagtail/api/v2/tests/test_images.py index e5cf4a4892..c12986401b 100644 --- a/wagtail/api/v2/tests/test_images.py +++ b/wagtail/api/v2/tests/test_images.py @@ -270,6 +270,14 @@ class TestImageListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['items']), get_image_model().objects.count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20) diff --git a/wagtail/api/v2/tests/test_pages.py b/wagtail/api/v2/tests/test_pages.py index a84bc265b3..ef4f9fdcaa 100644 --- a/wagtail/api/v2/tests/test_pages.py +++ b/wagtail/api/v2/tests/test_pages.py @@ -633,6 +633,14 @@ class TestPageListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['items']), get_total_page_count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20) diff --git a/wagtail/contrib/wagtailapi/pagination.py b/wagtail/contrib/wagtailapi/pagination.py index d30e61e044..505f564bdf 100644 --- a/wagtail/contrib/wagtailapi/pagination.py +++ b/wagtail/contrib/wagtailapi/pagination.py @@ -20,9 +20,10 @@ class WagtailPagination(BasePagination): raise BadRequestError("offset must be a positive integer") try: - limit = int(request.GET.get('limit', min(20, limit_max))) + limit_default = 20 if not limit_max else min(20, limit_max) + limit = int(request.GET.get('limit', limit_default)) - if limit > limit_max: + if limit_max and limit > limit_max: raise BadRequestError("limit cannot be higher than %d" % limit_max) assert limit >= 0 diff --git a/wagtail/contrib/wagtailapi/tests/test_documents.py b/wagtail/contrib/wagtailapi/tests/test_documents.py index 9488ec81de..00aa50ad62 100644 --- a/wagtail/contrib/wagtailapi/tests/test_documents.py +++ b/wagtail/contrib/wagtailapi/tests/test_documents.py @@ -207,6 +207,14 @@ class TestDocumentListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['documents']), get_document_model().objects.count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20) diff --git a/wagtail/contrib/wagtailapi/tests/test_images.py b/wagtail/contrib/wagtailapi/tests/test_images.py index 1922e32659..ccc791abc4 100644 --- a/wagtail/contrib/wagtailapi/tests/test_images.py +++ b/wagtail/contrib/wagtailapi/tests/test_images.py @@ -208,6 +208,14 @@ class TestImageListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['images']), get_image_model().objects.count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20) diff --git a/wagtail/contrib/wagtailapi/tests/test_pages.py b/wagtail/contrib/wagtailapi/tests/test_pages.py index 980746a22f..896477c728 100644 --- a/wagtail/contrib/wagtailapi/tests/test_pages.py +++ b/wagtail/contrib/wagtailapi/tests/test_pages.py @@ -446,6 +446,14 @@ class TestPageListing(TestCase): self.assertEqual(response.status_code, 400) self.assertEqual(content, {'message': "limit cannot be higher than 20"}) + @override_settings(WAGTAILAPI_LIMIT_MAX=None) + def test_limit_max_none_gives_no_errors(self): + response = self.get_response(limit=1000000) + content = json.loads(response.content.decode('UTF-8')) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(content['pages']), get_total_page_count()) + @override_settings(WAGTAILAPI_LIMIT_MAX=10) def test_limit_maximum_can_be_changed(self): response = self.get_response(limit=20)