Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanditems #65

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ Changelog
5.0.10 (unreleased)
-------------------

- `search_sections` in IDesignPloneSettings has a new filed in each section:
`expandItems` that is a boolean to decide if the items of the section should
be expanded or not (default is True).
[mamico]
- Add a profile to limit addables on site root
[lucabel]


5.0.9 (2024-04-12)
------------------

Expand Down
29 changes: 19 additions & 10 deletions src/design/plone/policy/restapi/search_filters/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ def reply(self):
(section, self.request),
ISerializeToJsonSummary,
)()
children = section.listFolderContents(
contentFilter={"portal_type": utils.getUserFriendlyTypes()}
)
item_infos["items"] = [
getMultiAdapter(
(x, self.request),
ISerializeToJsonSummary,
)()
for x in children
]
if section_settings.get("expandItems", True):
children = section.listFolderContents(
contentFilter={"portal_type": utils.getUserFriendlyTypes()}
)
item_infos["items"] = [
getMultiAdapter(
(x, self.request),
ISerializeToJsonSummary,
)()
for x in children
]
else:
# do not expand childrens, the only item is the section/container itself
item_infos["items"] = [
getMultiAdapter(
(section, self.request),
ISerializeToJsonSummary,
)()
]
item_infos["title"] = section_settings.get("title", "")
items.append(item_infos)
if items:
Expand Down
27 changes: 26 additions & 1 deletion src/design/plone/policy/tests/test_search_filters_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from Products.CMFPlone.interfaces import ISearchSchema
from transaction import commit
from zope.component import getUtility

from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings
import json
import unittest


Expand Down Expand Up @@ -126,3 +127,27 @@ def test_endpoint_do_not_return_contents_that_are_not_searchable(self):

self.assertEqual("Amministrazione", amministrazione["title"])
self.assertEqual(7, len(amministrazione["items"]))

def test_not_expand_items(self):
# first section has 7 children
response = self.api_session.get("/@search-filters").json()
self.assertEqual(len(response["sections"][0]["items"][0]["items"]), 7)
self.assertEqual(len(response["sections"][0]["items"][1]["items"]), 15)

# change expandItems to False for the first section
settings = json.loads(
api.portal.get_registry_record(
"search_sections", interface=IDesignPloneSettings
)
)
settings[0]["items"][0]["expandItems"] = False
api.portal.set_registry_record(
"search_sections", json.dumps(settings), interface=IDesignPloneSettings
)
commit()

response = self.api_session.get("/@search-filters").json()
# first item now has only 1 child
self.assertEqual(len(response["sections"][0]["items"][0]["items"]), 1)
# second item still has 15 children
self.assertEqual(len(response["sections"][0]["items"][1]["items"]), 15)
Loading