Skip to content

Commit

Permalink
backport #65 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Jul 1, 2024
1 parent 0230fd6 commit 83bd6f9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Changelog
4.0.10 (unreleased)
-------------------

- Nothing changed yet.

- `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]

4.0.9 (2024-04-11)
------------------
Expand Down
33 changes: 20 additions & 13 deletions src/design/plone/policy/restapi/search_filters/get.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from AccessControl.unauthorized import Unauthorized
from design.plone.contenttypes.controlpanels.settings import (
IDesignPloneSettings,
)
from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings
from plone import api
from plone.registry.interfaces import IRegistry
from plone.restapi.interfaces import ISerializeToJsonSummary
Expand All @@ -13,6 +11,7 @@
from zope.i18n import translate
from zope.interface import implementer
from zope.publisher.interfaces import IPublishTraverse

import json


Expand Down Expand Up @@ -59,16 +58,24 @@ def reply(self):
(section, self.request),
ISerializeToJsonSummary,
)()
children = section.listFolderContents()
if children:
item_infos["items"] = []
for children in section.listFolderContents():
item_infos["items"].append(
getMultiAdapter(
(children, self.request),
ISerializeToJsonSummary,
)()
)
if section_settings.get("expandItems", True):
children = section.listFolderContents()
if children:
item_infos["items"] = []
for children in section.listFolderContents():
item_infos["items"].append(
getMultiAdapter(
(children, self.request),
ISerializeToJsonSummary,
)()
)
else:
item_infos["items"] = [
getMultiAdapter(
(section, self.request),
ISerializeToJsonSummary,
)()
]
if section_settings.get("title", ""):
item_infos["title"] = section_settings["title"]
items.append(item_infos)
Expand Down
30 changes: 27 additions & 3 deletions src/design/plone/policy/tests/test_search_filters_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from design.plone.policy.testing import (
DESIGN_PLONE_POLICY_API_FUNCTIONAL_TESTING,
)
from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings
from design.plone.policy.testing import DESIGN_PLONE_POLICY_API_FUNCTIONAL_TESTING
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
Expand All @@ -13,6 +12,7 @@
from transaction import commit
from zope.component import getUtility

import json
import unittest


Expand Down Expand Up @@ -99,3 +99,27 @@ def test_endpoint_return_list_of_searchable_types(self):
self.assertIn("portal_types", response)
types = [x["id"] for x in response["portal_types"]]
self.assertNotIn("Document", types)

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)

0 comments on commit 83bd6f9

Please sign in to comment.