Skip to content

Commit

Permalink
[fc] Repository: plone.restapi
Browse files Browse the repository at this point in the history
Branch: refs/heads/main
Date: 2025-01-21T19:01:56-08:00
Author: Faakhir Zahid (Faakhir30) <110815427+Faakhir30@users.noreply.github.com>
Commit: plone/plone.restapi@88f2bc9

add query param to search registry records. (#1861)

* add query param to search registry records.

* refactor serializer.

* format using black.

* use tmp registry isntead of seperate serializer class.

* udpate http resp files

* update docs.

* update docs.

* version added

* Update docs/source/endpoints/registry.md

* Apply suggestions from code review

---------

Co-authored-by: Steve Piercy &lt;web@stevepiercy.com&gt;
Co-authored-by: David Glick &lt;david@glicksoftware.com&gt;

Files changed:
A news/1861.feature
A src/plone/restapi/tests/http-examples/registry_get_list_filtered.req
A src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp
M docs/source/endpoints/registry.md
M src/plone/restapi/services/registry/get.py
M src/plone/restapi/tests/test_documentation.py
M src/plone/restapi/tests/test_registry.py
  • Loading branch information
davisagli committed Jan 22, 2025
1 parent 64b6a88 commit 3c108e2
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions last_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@ Repository: plone.restapi


Branch: refs/heads/main
Date: 2025-01-21T18:54:28-08:00
Author: David Glick (davisagli) <david@glicksoftware.com>
Commit: https://github.com/plone/plone.restapi/commit/b8f1594a968fb33c78205980e4414d1c4b429e2f
Date: 2025-01-21T19:01:56-08:00
Author: Faakhir Zahid (Faakhir30) <110815427+Faakhir30@users.noreply.github.com>
Commit: https://github.com/plone/plone.restapi/commit/88f2bc9cba9d2f3057813f8e0b4bc029ddcee117

Update Plone test versions, and pin twine (#1865)
add query param to search registry records. (#1861)

* Update Plone test versions, and pin twine
* add query param to search registry records.

* Avoid overriding version pins
* refactor serializer.

* Remove Python 3.8 from the test matrix for Plone 6.0, where it is no longer supported
* format using black.

* update test output for new minor Plone version
* use tmp registry isntead of seperate serializer class.

* udpate http resp files

* update docs.

* update docs.

* version added

* Update docs/source/endpoints/registry.md

* Apply suggestions from code review

---------

Co-authored-by: Steve Piercy &lt;web@stevepiercy.com&gt;
Co-authored-by: David Glick &lt;david@glicksoftware.com&gt;

Files changed:
A news/1685.internal
M .github/workflows/tests.yml
M plone-6.0.x-python3.8.cfg
M plone-6.0.x.cfg
M plone-6.1.x.cfg
M requirements-6.0.txt
M requirements-6.1.txt
M src/plone/restapi/tests/http-examples/registry_get_list.resp
M src/plone/restapi/tests/http-examples/site_get.resp
A news/1861.feature
A src/plone/restapi/tests/http-examples/registry_get_list_filtered.req
A src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp
M docs/source/endpoints/registry.md
M src/plone/restapi/services/registry/get.py
M src/plone/restapi/tests/test_documentation.py
M src/plone/restapi/tests/test_registry.py

b'diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml\nindex 72d7ada3f..bd31daf00 100644\n--- a/.github/workflows/tests.yml\n+++ b/.github/workflows/tests.yml\n@@ -10,8 +10,6 @@ jobs:\n include:\n - python-version: "3.8"\n plone-version: "5.2"\n- - python-version: "3.8"\n- plone-version: "6.0"\n - python-version: "3.9"\n plone-version: "6.0"\n - python-version: "3.10"\ndiff --git a/news/1685.internal b/news/1685.internal\nnew file mode 100644\nindex 000000000..6fe9f0e0d\n--- /dev/null\n+++ b/news/1685.internal\n@@ -0,0 +1 @@\n+Update CI. @davisagli\ndiff --git a/plone-6.0.x-python3.8.cfg b/plone-6.0.x-python3.8.cfg\nindex 2bd12daf3..c093e3296 100644\n--- a/plone-6.0.x-python3.8.cfg\n+++ b/plone-6.0.x-python3.8.cfg\n@@ -1,6 +1,6 @@\n [buildout]\n extends =\n- https://dist.plone.org/release/6.0.12/versions.cfg\n+ https://dist.plone.org/release/6.0.14/versions.cfg\n base.cfg\n \n [instance]\n@@ -15,3 +15,4 @@ robotframework-assertion-engine = 2.0.0\n robotframework-debuglibrary = 2.3.0\n robotframework-pythonlibcore = 4.2.0\n grpcio-tools = 1.59.0\n+twine = 5.1.1\ndiff --git a/plone-6.0.x.cfg b/plone-6.0.x.cfg\nindex 26373fac8..eba5ea414 100644\n--- a/plone-6.0.x.cfg\n+++ b/plone-6.0.x.cfg\n@@ -1,24 +1,11 @@\n [buildout]\n extends =\n- https://dist.plone.org/release/6.0.12/versions.cfg\n+ https://dist.plone.org/release/6.0.14/versions.cfg\n base.cfg\n \n-[buildout:python37]\n-parts =\n- test\n- code-analysis\n-\n [instance]\n recipe = plone.recipe.zope2instance\n zodb-temporary-storage = off\n \n [versions]\n-# Override pin from Zope. https://github.com/zopefoundation/Zope/issues/1220\n-docutils = 0.21.2\n-pygments = 2.14.0\n-plone.app.linkintegrity = 4.0.3\n-robotframework-browser = 17.5.2\n-robotframework-assertion-engine = 2.0.0\n-robotframework-debuglibrary = 2.3.0\n-robotframework-pythonlibcore = 4.2.0\n-grpcio-tools = 1.59.0\n+twine = 5.1.1\ndiff --git a/plone-6.1.x.cfg b/plone-6.1.x.cfg\nindex 54716fa95..10bfe2830 100644\n--- a/plone-6.1.x.cfg\n+++ b/plone-6.1.x.cfg\n@@ -1,17 +1,10 @@\n [buildout]\n extends =\n- https://dist.plone.org/release/6.1.0a3/versions.cfg\n+ https://dist.plone.org/release/6.1.0b2/versions.cfg\n base.cfg\n \n-[buildout:python37]\n-parts =\n- test\n- code-analysis\n-\n [instance]\n recipe = plone.recipe.zope2instance\n zodb-temporary-storage = off\n \n [versions]\n-# Override pin from Zope. https://github.com/zopefoundation/Zope/issues/1220\n-docutils = 0.21.2\ndiff --git a/requirements-6.0.txt b/requirements-6.0.txt\nindex b654a46a9..d75ea5cca 100644\n--- a/requirements-6.0.txt\n+++ b/requirements-6.0.txt\n@@ -1 +1 @@\n--r https://dist.plone.org/release/6.0.12/requirements.txt\n+-r https://dist.plone.org/release/6.0.14/requirements.txt\ndiff --git a/requirements-6.1.txt b/requirements-6.1.txt\nindex 7ce0be7bb..1abfefefc 100644\n--- a/requirements-6.1.txt\n+++ b/requirements-6.1.txt\n@@ -1 +1 @@\n--r https://dist.plone.org/release/6.1.0a3/requirements.txt\n+-r https://dist.plone.org/release/6.1.0b2/requirements.txt\ndiff --git a/src/plone/restapi/tests/http-examples/registry_get_list.resp b/src/plone/restapi/tests/http-examples/registry_get_list.resp\nindex f172b2c8d..213ccce06 100644\n--- a/src/plone/restapi/tests/http-examples/registry_get_list.resp\n+++ b/src/plone/restapi/tests/http-examples/registry_get_list.resp\n@@ -423,5 +423,5 @@ Content-Type: application/json\n "value": "The person that created an item"\n }\n ],\n- "items_total": 2973\n+ "items_total": 2974\n }\ndiff --git a/src/plone/restapi/tests/http-examples/site_get.resp b/src/plone/restapi/tests/http-examples/site_get.resp\nindex 43a502cc1..417c0cbf8 100644\n--- a/src/plone/restapi/tests/http-examples/site_get.resp\n+++ b/src/plone/restapi/tests/http-examples/site_get.resp\n@@ -4,7 +4,7 @@ Content-Type: application/json\n {\n "@id": "http://localhost:55001/plone/@site",\n "features": {\n- "filter_aliases_by_date": false\n+ "filter_aliases_by_date": true\n },\n "plone.allowed_sizes": [\n "huge 1600:65536",\n'
b'diff --git a/docs/source/endpoints/registry.md b/docs/source/endpoints/registry.md\nindex 57fb9f3426..1a5e0a9c7f 100644\n--- a/docs/source/endpoints/registry.md\n+++ b/docs/source/endpoints/registry.md\n@@ -52,6 +52,25 @@ Example response:\n :language: http\n ```\n \n+## Filter list of registry records\n+\n+```{versionadded} plone.restapi 9.10.0\n+```\n+\n+You can filter a list of registry records and batch the results.\n+To do so, append a query string to the listing endpoint with a `q` parameter and its value set to the prefix of the desired record name.\n+See {doc}`../usage/batching` for details of how to work with batched results.\n+\n+```{eval-rst}\n+.. http:example:: curl httpie python-requests\n+ :request: ../../../src/plone/restapi/tests/http-examples/registry_get_list_filtered.req\n+```\n+\n+Example response:\n+\n+```{literalinclude} ../../../src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp\n+:language: http\n+```\n \n ## Updating registry records\n \ndiff --git a/news/1861.feature b/news/1861.feature\nnew file mode 100644\nindex 0000000000..5e3538d612\n--- /dev/null\n+++ b/news/1861.feature\n@@ -0,0 +1 @@\n+In the `@registry` endpoint, added support for filtering the list of registry records. @Faakhir30\n\\ No newline at end of file\ndiff --git a/src/plone/restapi/services/registry/get.py b/src/plone/restapi/services/registry/get.py\nindex b75ecc07a4..689d712da3 100644\n--- a/src/plone/restapi/services/registry/get.py\n+++ b/src/plone/restapi/services/registry/get.py\n@@ -1,3 +1,4 @@\n+from plone.registry import Registry\n from plone.registry.interfaces import IRegistry\n from plone.restapi.interfaces import ISerializeToJson\n from plone.restapi.serializer.converters import json_compatible\n@@ -35,5 +36,15 @@ def reply(self):\n value = registry[self._get_record_name]\n return json_compatible(value)\n else: # batched listing\n- serializer = getMultiAdapter((registry, self.request), ISerializeToJson)\n+ if q := self.request.form.get("q"):\n+\n+ tmp_registry = Registry()\n+ for key in registry.records.keys():\n+ if key.startswith(q):\n+ tmp_registry.records[key] = registry.records[key]\n+ registry = tmp_registry\n+ serializer = getMultiAdapter(\n+ (registry, self.request),\n+ ISerializeToJson,\n+ )\n return serializer()\ndiff --git a/src/plone/restapi/tests/http-examples/registry_get_list_filtered.req b/src/plone/restapi/tests/http-examples/registry_get_list_filtered.req\nnew file mode 100644\nindex 0000000000..f9cfd8b3c8\n--- /dev/null\n+++ b/src/plone/restapi/tests/http-examples/registry_get_list_filtered.req\n@@ -0,0 +1,3 @@\n+GET /plone/@registry?q=Products.CMFPlone HTTP/1.1\n+Accept: application/json\n+Authorization: Basic YWRtaW46c2VjcmV0\ndiff --git a/src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp b/src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp\nnew file mode 100644\nindex 0000000000..8962fb5d70\n--- /dev/null\n+++ b/src/plone/restapi/tests/http-examples/registry_get_list_filtered.resp\n@@ -0,0 +1,57 @@\n+HTTP/1.1 200 OK\n+Content-Type: application/json\n+\n+{\n+ "@id": "http://localhost:55001/plone/@registry?q=Products.CMFPlone",\n+ "items": [\n+ {\n+ "name": "Products.CMFPlone.i18nl10n.override_dateformat.Enabled",\n+ "schema": {\n+ "properties": {\n+ "description": "Override the translation machinery",\n+ "factory": "Yes/No",\n+ "title": "Enabled",\n+ "type": "boolean"\n+ }\n+ },\n+ "value": false\n+ },\n+ {\n+ "name": "Products.CMFPlone.i18nl10n.override_dateformat.date_format_long",\n+ "schema": {\n+ "properties": {\n+ "description": "Default value: %Y-%m-%d %H:%M (2038-01-19 03:14)",\n+ "factory": "Text line (String)",\n+ "title": "old ZMI property: localLongTimeFormat",\n+ "type": "string"\n+ }\n+ },\n+ "value": "%Y-%m-%d %H:%M"\n+ },\n+ {\n+ "name": "Products.CMFPlone.i18nl10n.override_dateformat.date_format_short",\n+ "schema": {\n+ "properties": {\n+ "description": "Default value: %Y-%m-%d (2038-01-19)",\n+ "factory": "Text line (String)",\n+ "title": "old ZMI property: localTimeFormat",\n+ "type": "string"\n+ }\n+ },\n+ "value": "%Y-%m-%d"\n+ },\n+ {\n+ "name": "Products.CMFPlone.i18nl10n.override_dateformat.time_format",\n+ "schema": {\n+ "properties": {\n+ "description": "Default value: %H:%M (03:14)",\n+ "factory": "Text line (String)",\n+ "title": "old ZMI property: localTimeOnlyFormat",\n+ "type": "string"\n+ }\n+ },\n+ "value": "%H:%M"\n+ }\n+ ],\n+ "items_total": 4\n+}\ndiff --git a/src/plone/restapi/tests/test_documentation.py b/src/plone/restapi/tests/test_documentation.py\nindex 574873ce6e..916f654b2a 100644\n--- a/src/plone/restapi/tests/test_documentation.py\n+++ b/src/plone/restapi/tests/test_documentation.py\n@@ -549,6 +549,10 @@ def test_documentation_registry_get_list(self):\n response = self.api_session.get("/@registry")\n save_request_and_response_for_docs("registry_get_list", response)\n \n+ def test_documentation_registry_get_list_filtered(self):\n+ response = self.api_session.get("/@registry?q=Products.CMFPlone")\n+ save_request_and_response_for_docs("registry_get_list_filtered", response)\n+\n def test_documentation_types(self):\n response = self.api_session.get("/@types")\n save_request_and_response_for_docs("types", response)\ndiff --git a/src/plone/restapi/tests/test_registry.py b/src/plone/restapi/tests/test_registry.py\nindex 61a266b644..069ca363cb 100644\n--- a/src/plone/restapi/tests/test_registry.py\n+++ b/src/plone/restapi/tests/test_registry.py\n@@ -107,3 +107,12 @@ def test_get_listing(self):\n self.assertIn("items", response)\n self.assertIn("batching", response)\n self.assertIn("next", response["batching"])\n+\n+ def test_get_filtered_listing(self):\n+ response = self.api_session.get("/@registry?q=foo.bar1")\n+ self.assertEqual(response.status_code, 200)\n+ response = response.json()\n+ # 10 records from foo.bar10 to foo.bar19 and 1 record foo.bar1\n+ self.assertEqual(len(response["items"]), 11)\n+ self.assertEqual(response["items"][0]["name"], "foo.bar1")\n+ self.assertEqual(response["items"][0]["value"], "Lorem Ipsum")\n'

0 comments on commit 3c108e2

Please sign in to comment.