From 08d5bac6335545e8cc19a8391a760516d52ea44a Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 26 Jan 2024 14:15:35 +0100 Subject: [PATCH 1/4] initial work --- .../plone/contenttypes/controlpanels/settings.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/design/plone/contenttypes/controlpanels/settings.py b/src/design/plone/contenttypes/controlpanels/settings.py index 60beed41..365b8135 100644 --- a/src/design/plone/contenttypes/controlpanels/settings.py +++ b/src/design/plone/contenttypes/controlpanels/settings.py @@ -88,6 +88,16 @@ class IDesignPloneSettings(Interface): default=True, required=False, ) + show_dynamic_folders_in_footer = Bool( + title=_("show_dynamic_folders_in_footer_label", default="Footer dinamico"), + description=_( + "show_dynamic_folders_in_footer_help", + default="Se selezionato, il footer verrà popolato automaticamente " + "con i contenuti di primo livello non esclusi dalla navigazione.", + ), + default=True, + required=False, + ) class DesignPloneControlPanelForm(RegistryEditForm): From e2206ddbe4b88c7924730e6576f14e6cddba2a12 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Sat, 27 Jan 2024 21:18:57 +0100 Subject: [PATCH 2/4] Add new flag in settings needed to choose to show or not auto-generated footer columns and Customize @navigation endpoint to expose also the new flag for frontend --- CHANGES.rst | 5 +- .../restapi/services/configure.zcml | 4 +- .../restapi/services/navigation/__init__.py | 0 .../services/navigation/configure.zcml | 22 +++++ .../restapi/services/navigation/get.py | 29 +++++++ .../tests/test_custom_service_navigation.py | 82 +++++++++++++++++++ .../contenttypes/upgrades/configure.zcml | 11 ++- 7 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/design/plone/contenttypes/restapi/services/navigation/__init__.py create mode 100644 src/design/plone/contenttypes/restapi/services/navigation/configure.zcml create mode 100644 src/design/plone/contenttypes/restapi/services/navigation/get.py create mode 100644 src/design/plone/contenttypes/tests/test_custom_service_navigation.py diff --git a/CHANGES.rst b/CHANGES.rst index e0b2077f..94faf86a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,7 +8,10 @@ Changelog [eikichi18] - Add getObjSize info in File field serializer. [cekk] - +- Add new flag in settings needed to choose to show or not auto-generated footer columns. + [cekk] +- Customize @navigation endpoint to expose also the new flag for frontend. + [cekk] 6.1.10 (2024-01-16) ------------------- diff --git a/src/design/plone/contenttypes/restapi/services/configure.zcml b/src/design/plone/contenttypes/restapi/services/configure.zcml index 06d609df..e93dcc9d 100644 --- a/src/design/plone/contenttypes/restapi/services/configure.zcml +++ b/src/design/plone/contenttypes/restapi/services/configure.zcml @@ -6,9 +6,11 @@ + - + + + + + + + + diff --git a/src/design/plone/contenttypes/restapi/services/navigation/get.py b/src/design/plone/contenttypes/restapi/services/navigation/get.py new file mode 100644 index 00000000..70e42e12 --- /dev/null +++ b/src/design/plone/contenttypes/restapi/services/navigation/get.py @@ -0,0 +1,29 @@ +from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings +from design.plone.contenttypes.interfaces import IDesignPloneContenttypesLayer +from plone import api +from plone.restapi.interfaces import IExpandableElement +from plone.restapi.services import Service +from plone.restapi.services.navigation.get import Navigation as BaseNavigation +from zope.component import adapter +from zope.interface import implementer +from zope.interface import Interface + + +@implementer(IExpandableElement) +@adapter(Interface, IDesignPloneContenttypesLayer) +class Navigation(BaseNavigation): + def __call__(self, expand=False): + result = super().__call__(expand=expand) + show_dynamic_folders_in_footer = api.portal.get_registry_record( + "show_dynamic_folders_in_footer", + interface=IDesignPloneSettings, + default=False, + ) + result["navigation"]["show_in_footer"] = show_dynamic_folders_in_footer + return result + + +class NavigationGet(Service): + def reply(self): + navigation = Navigation(self.context, self.request) + return navigation(expand=True)["navigation"] diff --git a/src/design/plone/contenttypes/tests/test_custom_service_navigation.py b/src/design/plone/contenttypes/tests/test_custom_service_navigation.py new file mode 100644 index 00000000..014ad580 --- /dev/null +++ b/src/design/plone/contenttypes/tests/test_custom_service_navigation.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +from design.plone.contenttypes.controlpanels.settings import IDesignPloneSettings +from design.plone.contenttypes.testing import ( + DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING, +) +from plone import api +from plone.app.testing import setRoles +from plone.app.testing import SITE_OWNER_NAME +from plone.app.testing import SITE_OWNER_PASSWORD +from plone.app.testing import TEST_USER_ID +from plone.dexterity.utils import createContentInContainer +from plone.restapi.testing import RelativeSession +from transaction import commit + +import unittest + + +class CustomNavigationTest(unittest.TestCase): + layer = DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING + + def setUp(self): + self.app = self.layer["app"] + self.portal = self.layer["portal"] + self.portal_url = self.portal.absolute_url() + self.api_session = RelativeSession(self.portal_url) + self.api_session.headers.update({"Accept": "application/json"}) + self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + + self.folder = createContentInContainer( + self.portal, "Folder", id="folder", title="Some Folder" + ) + self.folder2 = createContentInContainer( + self.portal, "Folder", id="folder2", title="Some Folder 2" + ) + self.subfolder1 = createContentInContainer( + self.folder, "Folder", id="subfolder1", title="SubFolder 1" + ) + self.subfolder2 = createContentInContainer( + self.folder, "Folder", id="subfolder2", title="SubFolder 2" + ) + self.thirdlevelfolder = createContentInContainer( + self.subfolder1, + "Folder", + id="thirdlevelfolder", + title="Third Level Folder", + ) + self.fourthlevelfolder = createContentInContainer( + self.thirdlevelfolder, + "Folder", + id="fourthlevelfolder", + title="Fourth Level Folder", + ) + createContentInContainer(self.folder, "Document", id="doc1", title="A document") + commit() + + def tearDown(self): + self.api_session.close() + + def test_return_show_in_footer_info_based_on_registry(self): + # by default is True + response = self.api_session.get( + "/@navigation", params={"expand.navigation.depth": 2} + ).json() + + self.assertIn("show_in_footer", response) + self.assertTrue(response["show_in_footer"]) + + # change it + api.portal.set_registry_record( + "show_dynamic_folders_in_footer", + False, + interface=IDesignPloneSettings, + ) + commit() + + response = self.api_session.get( + "/@navigation", params={"expand.navigation.depth": 2} + ).json() + + self.assertIn("show_in_footer", response) + self.assertFalse(response["show_in_footer"]) diff --git a/src/design/plone/contenttypes/upgrades/configure.zcml b/src/design/plone/contenttypes/upgrades/configure.zcml index 8e88bee8..c1896bd3 100644 --- a/src/design/plone/contenttypes/upgrades/configure.zcml +++ b/src/design/plone/contenttypes/upgrades/configure.zcml @@ -804,5 +804,14 @@ handler=".upgrades.update_pdc_with_pdc_desc" /> - + + + From 9a01432f7bb02529bdb7ef0f46f60c91c1ae975a Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Sat, 27 Jan 2024 21:19:11 +0100 Subject: [PATCH 3/4] zpretty --- .../contenttypes/restapi/services/navigation/configure.zcml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/design/plone/contenttypes/restapi/services/navigation/configure.zcml b/src/design/plone/contenttypes/restapi/services/navigation/configure.zcml index 66fff132..e9bc6b20 100644 --- a/src/design/plone/contenttypes/restapi/services/navigation/configure.zcml +++ b/src/design/plone/contenttypes/restapi/services/navigation/configure.zcml @@ -15,8 +15,8 @@ factory=".get.NavigationGet" for="zope.interface.Interface" permission="zope2.View" - name="@navigation" layer="design.plone.contenttypes.interfaces.IDesignPloneContenttypesLayer" + name="@navigation" /> From 9dd91ea6593d9168f0ee1103a1df8f5978be278f Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Sat, 27 Jan 2024 21:25:22 +0100 Subject: [PATCH 4/4] update readme --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c1580770..ab5124c1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - [Design Plone Content-types](#design-plone-content-types) - [Features](#features) -- [Compatibilità](#compatibilit%C3%A0) +- [Compatibilità](#compatibilità) - [Tipi di contenuto](#tipi-di-contenuto) - [Elenco tipi implementati](#elenco-tipi-implementati) - [Bando](#bando) @@ -30,10 +30,11 @@ - [Campi indicizzati nel SearchableText](#campi-indicizzati-nel-searchabletext-2) - [Servizio](#servizio) - [Campi indicizzati nel SearchableText](#campi-indicizzati-nel-searchabletext-3) - - [Unità Organizzativa](#unit%C3%A0-organizzativa) + - [Unità Organizzativa](#unità-organizzativa) - [Campi indicizzati nel SearchableText](#campi-indicizzati-nel-searchabletext-4) - [Pannello di controllo](#pannello-di-controllo) - [Gestione modulistica](#gestione-modulistica) +- [Viste verifica contentuti](#viste-verifica-contentuti) - [Data di modifica](#data-di-modifica) - [Endpoint restapi](#endpoint-restapi) - [Customizzazione dati relation field](#customizzazione-dati-relation-field) @@ -421,6 +422,10 @@ Endpoint ed expansion per la modulistica. Nei content-type CartellaModulistica, tra i vari expansion c'è anche `@modulistica_items`. Questo è utile per la vista di frontend, in quanto se richiamato, ritorna la struttura di dati da mostrare in visualizzazione. +## @navigation + +Endpoint customizzato da plone.restapi per esporre anche il valore show_in_footer per decidere se disegnare o meno le colonne dinamiche nel footer. + # Installazione Questo prodotto non è stato pensato per funzionare da solo, ma fa parte della suite "design.plone".