From 4197534d322203dac447e379c0aaf2c54dd4223a Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 7 Nov 2023 16:34:26 +0100 Subject: [PATCH 01/12] Implementation (without test) --- src/plone/api/content.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plone/api/content.py b/src/plone/api/content.py index f85790ee..69143496 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -652,4 +652,7 @@ def find(context=None, depth=None, **kwargs): if not valid_indexes: return [] - return catalog(**query) + if kwargs.get('unrestricted'): + return catalog.unrestrictedSearchResults(**query) + else: + return catalog(**query) From 77316c29a15cd14f75e396a2e1fe624a581393bc Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 7 Nov 2023 16:42:20 +0100 Subject: [PATCH 02/12] Adding documentation for unrestricted find --- docs/content.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/content.md b/docs/content.md index 5228dd2a..4b3e4acf 100644 --- a/docs/content.md +++ b/docs/content.md @@ -195,6 +195,21 @@ documents = api.content.find( % % self.assertGreater(len(documents), 0) +Find all Documents, and use unrestrictedSearchResults: + +```python +from plone import api +documents = api.content.find( + context=api.portal.get(), + portal_type='Document', + unrestricted=True, +) +``` + +% invisible-code-block: python +% +% self.assertGreater(len(documents), 0) + More information about how to use the catalog may be found in the [Plone Documentation](https://5.docs.plone.org/develop/plone/searching_and_indexing/index.html). From d8b09ef50a99bf7157dafb5cf2dcb6842b7aca62 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 7 Nov 2023 16:48:28 +0100 Subject: [PATCH 03/12] Adding news entry for unrestricted find --- news/312.implementation | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/312.implementation diff --git a/news/312.implementation b/news/312.implementation new file mode 100644 index 00000000..227d93ea --- /dev/null +++ b/news/312.implementation @@ -0,0 +1 @@ +Implemented unrestricted find. \ No newline at end of file From 39747f413be2d42dab484d338f169be27058eb4f Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 7 Nov 2023 16:50:51 +0100 Subject: [PATCH 04/12] Adding basic test for unrestricted find --- src/plone/api/tests/test_content.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index 7123667c..7738a328 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -912,6 +912,13 @@ def test_find(self): documents = api.content.find(portal_type="Document") self.assertEqual(len(documents), 2) + def test_find(self): + """Test the finding of content in various ways.""" + + # Find documents + documents = api.content.find(portal_type="Document", unrestricted=True) + self.assertEqual(len(documents), 2) + def test_find_empty_query(self): """Make sure an empty query yields no results""" From 60bd67d3b01c1dd2d745516e55be780bf1e1fd5d Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 7 Nov 2023 16:55:54 +0100 Subject: [PATCH 05/12] Fixing black for unrestricted find --- src/plone/api/content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plone/api/content.py b/src/plone/api/content.py index 69143496..a3da980b 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -652,7 +652,7 @@ def find(context=None, depth=None, **kwargs): if not valid_indexes: return [] - if kwargs.get('unrestricted'): + if kwargs.get("unrestricted"): return catalog.unrestrictedSearchResults(**query) else: return catalog(**query) From 15432c5db4e2972bb0dcf73d9d7040899d931230 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Wed, 8 Nov 2023 10:12:10 +0100 Subject: [PATCH 06/12] Accepting various suggestions, thanks every 01. --- docs/content.md | 4 ++-- news/312.implementation | 2 +- src/plone/api/content.py | 3 ++- src/plone/api/tests/test_content.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/content.md b/docs/content.md index 4b3e4acf..6417a233 100644 --- a/docs/content.md +++ b/docs/content.md @@ -195,13 +195,13 @@ documents = api.content.find( % % self.assertGreater(len(documents), 0) -Find all Documents, and use unrestrictedSearchResults: +Find all `Document` content types, and use unrestricted search results: ```python from plone import api documents = api.content.find( context=api.portal.get(), - portal_type='Document', + portal_type="Document", unrestricted=True, ) ``` diff --git a/news/312.implementation b/news/312.implementation index 227d93ea..c7c660d9 100644 --- a/news/312.implementation +++ b/news/312.implementation @@ -1 +1 @@ -Implemented unrestricted find. \ No newline at end of file +Implemented unrestricted find of content types. @gogobd \ No newline at end of file diff --git a/src/plone/api/content.py b/src/plone/api/content.py index a3da980b..ac431917 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -599,12 +599,13 @@ def _parse_object_provides_query(query): return result -def find(context=None, depth=None, **kwargs): +def find(context=None, depth=None, untestricted=False, **kwargs): """Find content in the portal. :param context: Context for the search :type obj: Content object :param depth: How far in the content tree we want to search from context + :param unrestricted: Boolean, use unrestrictedSearchResults if True :type obj: Content object :returns: Catalog brains :rtype: List diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index 7738a328..1673f82e 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -912,8 +912,8 @@ def test_find(self): documents = api.content.find(portal_type="Document") self.assertEqual(len(documents), 2) - def test_find(self): - """Test the finding of content in various ways.""" + def test_untrestricted_find(self): + """Test the finding of content in with unrestricted search.""" # Find documents documents = api.content.find(portal_type="Document", unrestricted=True) From df59eaf36563423ed25acc01a064fbac1a4c32c6 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Wed, 8 Nov 2023 10:13:45 +0100 Subject: [PATCH 07/12] unrestricted is an explicit keyword now --- src/plone/api/content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plone/api/content.py b/src/plone/api/content.py index ac431917..d51928c9 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -653,7 +653,7 @@ def find(context=None, depth=None, untestricted=False, **kwargs): if not valid_indexes: return [] - if kwargs.get("unrestricted"): + if unrestricted: return catalog.unrestrictedSearchResults(**query) else: return catalog(**query) From fd1578f15cebe98bc3f7d9ad2ede47db805f5ff7 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Wed, 8 Nov 2023 10:20:52 +0100 Subject: [PATCH 08/12] Typo --- src/plone/api/content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plone/api/content.py b/src/plone/api/content.py index d51928c9..2e8b74e4 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -599,7 +599,7 @@ def _parse_object_provides_query(query): return result -def find(context=None, depth=None, untestricted=False, **kwargs): +def find(context=None, depth=None, unrestricted=False, **kwargs): """Find content in the portal. :param context: Context for the search From 5783c42849cc59c7c9b2f0c68001525199e46ef7 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Mon, 19 Feb 2024 13:10:54 +0100 Subject: [PATCH 09/12] Rename --- news/{312.implementation => 312.feature} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename news/{312.implementation => 312.feature} (100%) diff --git a/news/312.implementation b/news/312.feature similarity index 100% rename from news/312.implementation rename to news/312.feature From 5101fdcb5b0633a4894c8ea24bcbe4f3fb0ee2c9 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 20 Feb 2024 23:23:00 +0100 Subject: [PATCH 10/12] Log out for unrestricted search test --- src/plone/api/tests/test_content.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index 1673f82e..eecb6846 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -915,10 +915,18 @@ def test_find(self): def test_untrestricted_find(self): """Test the finding of content in with unrestricted search.""" - # Find documents + # Search as Anonymous user + from plone.app.testing import logout + logout() + + # Find documents (unrestricted) documents = api.content.find(portal_type="Document", unrestricted=True) self.assertEqual(len(documents), 2) + # Find documents (restricted) + documents = api.content.find(portal_type="Document") + self.assertEqual(len(documents), 0) + def test_find_empty_query(self): """Make sure an empty query yields no results""" From 969c6536a57c6ae498a0b63c45bbf665a78d5525 Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 20 Feb 2024 23:25:57 +0100 Subject: [PATCH 11/12] Black --- src/plone/api/tests/test_content.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index eecb6846..bea68c10 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -917,6 +917,7 @@ def test_untrestricted_find(self): # Search as Anonymous user from plone.app.testing import logout + logout() # Find documents (unrestricted) From cc704006018a2d852b6227148c8753c39242912b Mon Sep 17 00:00:00 2001 From: Georg Bernhard Date: Tue, 20 Feb 2024 23:41:16 +0100 Subject: [PATCH 12/12] Fixing linting for two files I never touched --- src/plone/api/relation.py | 1 + src/plone/api/tests/test_content.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/plone/api/relation.py b/src/plone/api/relation.py index 60df78ef..5540d4ca 100644 --- a/src/plone/api/relation.py +++ b/src/plone/api/relation.py @@ -2,6 +2,7 @@ Heavily inspired by collective.relationhelpers. """ + from AccessControl.SecurityManagement import getSecurityManager from collections import defaultdict from plone.api.exc import InvalidParameterError diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index bea68c10..637b1c64 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -1,4 +1,5 @@ """Tests for plone.api.content.""" + from Acquisition import aq_base from OFS.CopySupport import CopyError from OFS.event import ObjectWillBeMovedEvent