diff --git a/docs/content.md b/docs/content.md index 5228dd2a..6417a233 100644 --- a/docs/content.md +++ b/docs/content.md @@ -195,6 +195,21 @@ documents = api.content.find( % % self.assertGreater(len(documents), 0) +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", + 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). diff --git a/news/312.feature b/news/312.feature new file mode 100644 index 00000000..c7c660d9 --- /dev/null +++ b/news/312.feature @@ -0,0 +1 @@ +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 90f43776..6be66dec 100644 --- a/src/plone/api/content.py +++ b/src/plone/api/content.py @@ -603,12 +603,13 @@ def _parse_object_provides_query(query): return result -def find(context=None, depth=None, **kwargs): +def find(context=None, depth=None, unrestricted=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 @@ -656,4 +657,7 @@ def find(context=None, depth=None, **kwargs): if not valid_indexes: return [] - return catalog(**query) + if unrestricted: + return catalog.unrestrictedSearchResults(**query) + else: + return catalog(**query) diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py index 08ab2141..637b1c64 100644 --- a/src/plone/api/tests/test_content.py +++ b/src/plone/api/tests/test_content.py @@ -913,6 +913,22 @@ def test_find(self): documents = api.content.find(portal_type="Document") self.assertEqual(len(documents), 2) + def test_untrestricted_find(self): + """Test the finding of content in with unrestricted search.""" + + # 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"""