From 5b162047189e3f941c731072d2148ae8c58cd785 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 31 Jan 2024 13:55:46 +0100 Subject: [PATCH 1/4] add new field and Rename service endpoint to *@editable-footer-data* and changed its data structure --- .gitignore | 1 + CHANGES.rst | 5 +- README.rst | 28 +++++---- .../voltoplugin/editablefooter/configure.zcml | 2 + .../voltoplugin/editablefooter/interfaces.py | 9 +++ .../redturtle.volto_editablefooter.po | 55 ---------------- ...> redturtle.voltoplugin.editablefooter.po} | 36 +++++++---- ... redturtle.voltoplugin.editablefooter.pot} | 38 +++++++----- .../editablefooter/locales/update.py | 4 +- .../profiles/default/metadata.xml | 2 +- .../editablefooter/restapi/configure.zcml | 6 +- .../editablefooter/restapi/deserializer.py | 14 +++-- .../voltoplugin/editablefooter/restapi/get.py | 22 ++++--- .../editablefooter/restapi/serializer.py | 7 ++- ...y => test_editable_footer_data_service.py} | 62 ++++++++++++------- .../editablefooter/upgrades/__init__.py | 1 + .../editablefooter/upgrades/configure.zcml | 16 +++++ .../editablefooter/upgrades/upgrades.py | 30 +++++++++ 18 files changed, 196 insertions(+), 142 deletions(-) delete mode 100644 src/redturtle/voltoplugin/editablefooter/locales/en/LC_MESSAGES/redturtle.volto_editablefooter.po rename src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/{redturtle.volto_editablefooter.po => redturtle.voltoplugin.editablefooter.po} (66%) rename src/redturtle/voltoplugin/editablefooter/locales/{redturtle.volto_editablefooter.pot => redturtle.voltoplugin.editablefooter.pot} (64%) rename src/redturtle/voltoplugin/editablefooter/tests/{test_footer_columns_route.py => test_editable_footer_data_service.py} (60%) create mode 100644 src/redturtle/voltoplugin/editablefooter/upgrades/__init__.py create mode 100644 src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml create mode 100644 src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py diff --git a/.gitignore b/.gitignore index a61569d..50f3452 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.py? *.swp # dirs +__pycache__/ bin/ buildout-cache/ develop-eggs/ diff --git a/CHANGES.rst b/CHANGES.rst index cc3137c..d833c7c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,10 @@ Changelog 1.2.2 (unreleased) ------------------ -- Nothing changed yet. +- Add footer_top field in settings, to manage a new footer row before columns. + [cekk] +- [BREAKING] Rename service endpoint to *@editable-footer-data* and changed its data structure. + [cekk] 1.2.1 (2024-01-17) diff --git a/README.rst b/README.rst index bc232f9..0a3ed0d 100644 --- a/README.rst +++ b/README.rst @@ -19,23 +19,25 @@ Volto endpoint Anonymous users can't access registry resources by default with plone.restapi (there is a special permission). -To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@footer-columns*:: +To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@editable-footer-data*:: - > curl -i http://localhost:8080/Plone/@footer-columns -H 'Accept: application/json' + > curl -i http://localhost:8080/Plone/@editable-footer-data -H 'Accept: application/json' The response is something similar to this:: - - [ - { - 'text': {'data': 'foo'}, - 'title': 'First column' - }, - { - 'text': {'content-type': 'text/html', 'data': ''}, - 'title': 'Second column' - } - ] + { + "footer_top": {...}, + "footer_columns": [ + { + 'text': {'data': 'foo'}, + 'title': 'First column' + }, + { + 'text': {'content-type': 'text/html', 'data': ''}, + 'title': 'Second column' + } + ] + } Control panel diff --git a/src/redturtle/voltoplugin/editablefooter/configure.zcml b/src/redturtle/voltoplugin/editablefooter/configure.zcml index 758fbc4..326fe7d 100644 --- a/src/redturtle/voltoplugin/editablefooter/configure.zcml +++ b/src/redturtle/voltoplugin/editablefooter/configure.zcml @@ -16,6 +16,8 @@ + + diff --git a/src/redturtle/voltoplugin/editablefooter/interfaces.py b/src/redturtle/voltoplugin/editablefooter/interfaces.py index 98eaa91..4999113 100644 --- a/src/redturtle/voltoplugin/editablefooter/interfaces.py +++ b/src/redturtle/voltoplugin/editablefooter/interfaces.py @@ -10,6 +10,15 @@ class IRedturtleVoltoEditablefooterLayer(IDefaultBrowserLayer): class IEditableFooterSettings(IControlpanel): + footer_top = SourceText( + title=_("footer_top_label", default="Footer top"), + description=_( + "footer_top_help", + default="Insert some text that will be shown as first element in the footer, before the columns.", + ), + required=False, + default="", + ) footer_columns = SourceText( title=_("footer_columns_label", default="Footer columns"), description=_( diff --git a/src/redturtle/voltoplugin/editablefooter/locales/en/LC_MESSAGES/redturtle.volto_editablefooter.po b/src/redturtle/voltoplugin/editablefooter/locales/en/LC_MESSAGES/redturtle.volto_editablefooter.po deleted file mode 100644 index 25bbfc9..0000000 --- a/src/redturtle/voltoplugin/editablefooter/locales/en/LC_MESSAGES/redturtle.volto_editablefooter.po +++ /dev/null @@ -1,55 +0,0 @@ -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2020-10-08 14:24+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=1; plural=0\n" -"Language-Code: en\n" -"Language-Name: English\n" -"Preferred-Encodings: utf-8 latin1\n" -"Domain: DOMAIN\n" - -#: redturtle/voltoplugin/editablefooter/profiles/default/controlpanel.xml -msgid "Editable footer settings" -msgstr "" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 -msgid "Installs the redturtle.voltoplugin.editablefooter add-on." -msgstr "" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 -msgid "Uninstalls the redturtle.voltoplugin.editablefooter add-on." -msgstr "" - -#. Default: "Set infos for columns in footer." -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:13 -msgid "editable_footer_settings_help" -msgstr "" - -#. Default: "Editable Footer Settings" -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:10 -msgid "editable_footer_settings_label" -msgstr "" - -#. Default: "Set a list of custom columns for the footer. You can have different sets for each portal's languages." -#: redturtle/voltoplugin/editablefooter/interfaces.py:15 -msgid "footer_columns_help" -msgstr "" - -#. Default: "Footer columns" -#: redturtle/voltoplugin/editablefooter/interfaces.py:14 -msgid "footer_columns_label" -msgstr "" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 -msgid "redturtle.voltoplugin.editablefooter" -msgstr "" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 -msgid "redturtle.voltoplugin.editablefooter (uninstall)" -msgstr "" diff --git a/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.volto_editablefooter.po b/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po similarity index 66% rename from src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.volto_editablefooter.po rename to src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po index 20460e0..4c95fe2 100644 --- a/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.volto_editablefooter.po +++ b/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2020-10-08 14:24+0000\n" +"POT-Creation-Date: 2024-01-31 11:22+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,38 +18,48 @@ msgstr "" msgid "Editable footer settings" msgstr "Impostazioni footer" -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 +#: redturtle/voltoplugin/editablefooter/configure.zcml:31 msgid "Installs the redturtle.voltoplugin.editablefooter add-on." msgstr "Installa redturtle.voltoplugin.editablefooter" -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 +#: redturtle/voltoplugin/editablefooter/configure.zcml:40 msgid "Uninstalls the redturtle.voltoplugin.editablefooter add-on." msgstr "Disinstalla redturtle.voltoplugin.editablefooter" +#: redturtle/voltoplugin/editablefooter/configure.zcml:31 +msgid "Volto Editable Footer" +msgstr "Volto Editable Footer" + +#: redturtle/voltoplugin/editablefooter/configure.zcml:40 +msgid "Volto Editable Footer (uninstall)" +msgstr "Volto Editable Footer (uninstall" + #. Default: "Set infos for columns in footer." -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:13 +#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:12 msgid "editable_footer_settings_help" msgstr "Imposta i dati per le colonne del footer." #. Default: "Editable Footer Settings" -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:10 +#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:11 msgid "editable_footer_settings_label" msgstr "Impostazioni footer" #. Default: "Set a list of custom columns for the footer. You can have different sets for each portal's languages." -#: redturtle/voltoplugin/editablefooter/interfaces.py:15 +#: redturtle/voltoplugin/editablefooter/interfaces.py:24 msgid "footer_columns_help" msgstr "Configura una serie di colonne per il footer. Puoi creare differenti impostazioni per le varie lingue del sito." #. Default: "Footer columns" -#: redturtle/voltoplugin/editablefooter/interfaces.py:14 +#: redturtle/voltoplugin/editablefooter/interfaces.py:23 msgid "footer_columns_label" msgstr "Colonne footer" -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 -msgid "redturtle.voltoplugin.editablefooter" -msgstr "" +#. Default: "Insert some text that will be shown as first element in the footer, before the columns." +#: redturtle/voltoplugin/editablefooter/interfaces.py:15 +msgid "footer_top_help" +msgstr "Inserisci del testo che apparirà come primo elemento nel footer, sopra alle colonne." -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 -msgid "redturtle.voltoplugin.editablefooter (uninstall)" -msgstr "" +#. Default: "Footer top" +#: redturtle/voltoplugin/editablefooter/interfaces.py:14 +msgid "footer_top_label" +msgstr "Testata del footer" diff --git a/src/redturtle/voltoplugin/editablefooter/locales/redturtle.volto_editablefooter.pot b/src/redturtle/voltoplugin/editablefooter/locales/redturtle.voltoplugin.editablefooter.pot similarity index 64% rename from src/redturtle/voltoplugin/editablefooter/locales/redturtle.volto_editablefooter.pot rename to src/redturtle/voltoplugin/editablefooter/locales/redturtle.voltoplugin.editablefooter.pot index 61ab3a1..b1fbdc8 100644 --- a/src/redturtle/voltoplugin/editablefooter/locales/redturtle.volto_editablefooter.pot +++ b/src/redturtle/voltoplugin/editablefooter/locales/redturtle.voltoplugin.editablefooter.pot @@ -1,10 +1,10 @@ -# --- PLEASE EDIT THE LINES BELOW CORRECTLY --- -# SOME DESCRIPTIVE TITLE. -# FIRST AUTHOR , YEAR. +#--- PLEASE EDIT THE LINES BELOW CORRECTLY --- +#SOME DESCRIPTIVE TITLE. +#FIRST AUTHOR , YEAR. msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2020-10-08 14:24+0000\n" +"POT-Creation-Date: 2024-01-31 11:22+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -21,38 +21,48 @@ msgstr "" msgid "Editable footer settings" msgstr "" -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 +#: redturtle/voltoplugin/editablefooter/configure.zcml:31 msgid "Installs the redturtle.voltoplugin.editablefooter add-on." msgstr "" -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 +#: redturtle/voltoplugin/editablefooter/configure.zcml:40 msgid "Uninstalls the redturtle.voltoplugin.editablefooter add-on." msgstr "" +#: redturtle/voltoplugin/editablefooter/configure.zcml:31 +msgid "Volto Editable Footer" +msgstr "" + +#: redturtle/voltoplugin/editablefooter/configure.zcml:40 +msgid "Volto Editable Footer (uninstall)" +msgstr "" + #. Default: "Set infos for columns in footer." -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:13 +#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:12 msgid "editable_footer_settings_help" msgstr "" #. Default: "Editable Footer Settings" -#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:10 +#: redturtle/voltoplugin/editablefooter/browser/controlpanel.py:11 msgid "editable_footer_settings_label" msgstr "" #. Default: "Set a list of custom columns for the footer. You can have different sets for each portal's languages." -#: redturtle/voltoplugin/editablefooter/interfaces.py:15 +#: redturtle/voltoplugin/editablefooter/interfaces.py:24 msgid "footer_columns_help" msgstr "" #. Default: "Footer columns" -#: redturtle/voltoplugin/editablefooter/interfaces.py:14 +#: redturtle/voltoplugin/editablefooter/interfaces.py:23 msgid "footer_columns_label" msgstr "" -#: redturtle/voltoplugin/editablefooter/configure.zcml:28 -msgid "redturtle.voltoplugin.editablefooter" +#. Default: "Insert some text that will be shown as first element in the footer, before the columns." +#: redturtle/voltoplugin/editablefooter/interfaces.py:15 +msgid "footer_top_help" msgstr "" -#: redturtle/voltoplugin/editablefooter/configure.zcml:37 -msgid "redturtle.voltoplugin.editablefooter (uninstall)" +#. Default: "Footer top" +#: redturtle/voltoplugin/editablefooter/interfaces.py:14 +msgid "footer_top_label" msgstr "" diff --git a/src/redturtle/voltoplugin/editablefooter/locales/update.py b/src/redturtle/voltoplugin/editablefooter/locales/update.py index 2c6cd42..1c6ad48 100644 --- a/src/redturtle/voltoplugin/editablefooter/locales/update.py +++ b/src/redturtle/voltoplugin/editablefooter/locales/update.py @@ -7,7 +7,7 @@ domain = "redturtle.voltoplugin.editablefooter" os.chdir(pkg_resources.resource_filename(domain, "")) -os.chdir("../../../") +os.chdir("../../../../") target_path = "src/redturtle/voltoplugin/editablefooter/" locale_path = target_path + "locales/" i18ndude = "./bin/i18ndude" @@ -31,7 +31,7 @@ def locale_folder_setup(): ) subprocess.call(cmd, shell=True) - os.chdir("../../../../") + os.chdir("../../../../../") def _rebuild(): diff --git a/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml b/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml index 6ec05d9..2d36211 100644 --- a/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml +++ b/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1000 + 1001 profile-plone.restapi:default diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml b/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml index 07b360c..35e5e9f 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml +++ b/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml @@ -23,14 +23,14 @@ diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py b/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py index 48ee160..77b7814 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py @@ -21,15 +21,21 @@ def __call__(self): req = json_body(self.controlpanel.request) proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix) errors = [] - data = req.get("footer_columns", {}) - if not data: + footer_top = req.get("footer_top", {}) + footer_columns = req.get("footer_columns", {}) + + if not footer_columns: errors.append({"message": "Missing data", "field": "footer_columns"}) raise BadRequest(errors) try: # later we need to do some validations - setattr(proxy, "footer_columns", json.dumps(data)) + setattr(proxy, "footer_columns", json.dumps(footer_columns)) except ValueError as e: errors.append({"message": str(e), "field": "footer_columns", "error": e}) - + try: + # later we need to do some validations + setattr(proxy, "footer_top", json.dumps(footer_top)) + except ValueError as e: + errors.append({"message": str(e), "field": "footer_top", "error": e}) if errors: raise BadRequest(errors) diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/get.py b/src/redturtle/voltoplugin/editablefooter/restapi/get.py index 097a635..c34ec08 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/get.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/get.py @@ -20,17 +20,20 @@ @implementer(IPublishTraverse) -class FooterColumns(Service): - def __init__(self, context, request): - super(FooterColumns, self).__init__(context, request) - +class EditableFooterGet(Service): def reply(self): - record = api.portal.get_registry_record( + res = {"footer_top": None, "footer_columns": None} + footer_top = api.portal.get_registry_record( + "footer_top", interface=IEditableFooterSettings, default="" + ) + footer_columns = api.portal.get_registry_record( "footer_columns", interface=IEditableFooterSettings, default="" ) - if not record: - return [] - data = json.loads(record) + if footer_top: + res["footer_top"] = json.loads(footer_top) + if not footer_columns: + return res + data = json.loads(footer_columns) portal_url = self.get_portal_url() for el in data or []: if isinstance(el, dict): @@ -44,7 +47,8 @@ def reply(self): item["text"]["data"] = item["text"]["data"].replace( 'href="/', f'href="{portal_url}/' ) - return data + res["footer_columns"] = data + return res def get_portal_url(self): portal_url = api.portal.get().absolute_url() diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py b/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py index 0428c16..c11a62e 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py @@ -15,7 +15,8 @@ class EditableFooterControlpanelSerializeToJson(ControlpanelSerializeToJson): def __call__(self): json_data = super(EditableFooterControlpanelSerializeToJson, self).__call__() - conf = json_data["data"].get("footer_columns", "") - if conf: - json_data["data"]["footer_columns"] = json.loads(conf) + for field in ["footer_columns", "footer_top"]: + value = json_data["data"].get(field, "") + if value: + json_data["data"][field] = json.loads(value) return json_data diff --git a/src/redturtle/voltoplugin/editablefooter/tests/test_footer_columns_route.py b/src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py similarity index 60% rename from src/redturtle/voltoplugin/editablefooter/tests/test_footer_columns_route.py rename to src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py index d2e236d..c7ef779 100644 --- a/src/redturtle/voltoplugin/editablefooter/tests/test_footer_columns_route.py +++ b/src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py @@ -19,22 +19,19 @@ import unittest -class FooterColumnsEndpointTest(unittest.TestCase): - layer = VOLTO_EDITABLEFOOTER_API_FUNCTIONAL_TESTING - +class BaseTest(unittest.TestCase): def setUp(self): self.app = self.layer["app"] self.portal = self.layer["portal"] self.request = self.layer["request"] self.portal_url = self.portal.absolute_url() - self.controlpanel_url = "/@controlpanels/editable-footer-settings" setRoles(self.portal, TEST_USER_ID, ["Manager"]) 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) - self.value = [ + self.footer_columns_value = [ { "items": [ {"text": {"data": 'Link 1'}}, @@ -42,7 +39,9 @@ def setUp(self): ] } ] - self.set_record_value(field="footer_columns", value=json.dumps(self.value)) + self.set_record_value( + field="footer_columns", value=json.dumps(self.footer_columns_value) + ) def tearDown(self): self.api_session.close() @@ -51,24 +50,37 @@ def set_record_value(self, field, value): api.portal.set_registry_record(field, value, interface=IEditableFooterSettings) commit() + +class EditableFooterDataServiceTest(BaseTest): + layer = VOLTO_EDITABLEFOOTER_API_FUNCTIONAL_TESTING + def test_route_exists(self): - response = self.api_session.get("/@footer-columns") + response = self.api_session.get("/@editable-footer-data") self.assertEqual(response.status_code, 200) self.assertEqual(response.headers.get("Content-Type"), "application/json") - def test_return_json_data(self): - response = self.api_session.get("/@footer-columns") + def test_return_data_structure(self): + response = self.api_session.get("/@editable-footer-data") + result = response.json() + + self.assertIn("footer_top", result) + self.assertIn("footer_columns", result) + + def test_return_json_data_absolute_links_converted_for_footer_columns(self): + response = self.api_session.get("/@editable-footer-data") self.assertEqual(response.status_code, 200) result = response.json() - # self.value has relative links, but the result should have absolute links - self.assertNotEqual(result, self.value) + # self.footer_columns_value has relative links, but the result should have absolute links + self.assertNotEqual(result["footer_columns"], self.footer_columns_value) self.assertEqual( - json.dumps(result), - json.dumps(self.value).replace('href=\\"/', f'href=\\"{self.portal_url}/'), + json.dumps(result["footer_columns"]), + json.dumps(self.footer_columns_value).replace( + 'href=\\"/', f'href=\\"{self.portal_url}/' + ), ) -class FooterColumnsEndpointTestWithPloneVolto(FooterColumnsEndpointTest): +class EditableFooterDataServiceTestWithPloneVolto(BaseTest): layer = VOLTO_EDITABLEFOOTER_API_FUNCTIONAL_TESTING def setUp(self): @@ -78,14 +90,16 @@ def setUp(self): def test_return_json_data_with_portal_url_if_plone_volto_installed_and_not_configured( self, ): - response = self.api_session.get("/@footer-columns") + response = self.api_session.get("/@editable-footer-data") self.assertEqual(response.status_code, 200) result = response.json() - # self.value has relative links, but the result should have absolute links - self.assertNotEqual(result, self.value) + # self.footer_columns_value has relative links, but the result should have absolute links + self.assertNotEqual(result["footer_columns"], self.footer_columns_value) self.assertEqual( - json.dumps(result), - json.dumps(self.value).replace('href=\\"/', f'href=\\"{self.portal_url}/'), + json.dumps(result["footer_columns"]), + json.dumps(self.footer_columns_value).replace( + 'href=\\"/', f'href=\\"{self.portal_url}/' + ), ) def test_return_json_data_with_frontend_domain_if_set(self): @@ -96,14 +110,14 @@ def test_return_json_data_with_frontend_domain_if_set(self): settings.frontend_domain = "http://foo.org" commit() - response = self.api_session.get("/@footer-columns") + response = self.api_session.get("/@editable-footer-data") self.assertEqual(response.status_code, 200) result = response.json() - # self.value has relative links, but the result should have absolute links - self.assertNotEqual(result, self.value) + # self.footer_columns_value has relative links, but the result should have absolute links + self.assertNotEqual(result["footer_columns"], self.footer_columns_value) self.assertEqual( - json.dumps(result), - json.dumps(self.value).replace( + json.dumps(result["footer_columns"]), + json.dumps(self.footer_columns_value).replace( 'href=\\"/', f'href=\\"{settings.frontend_domain}/' ), ) diff --git a/src/redturtle/voltoplugin/editablefooter/upgrades/__init__.py b/src/redturtle/voltoplugin/editablefooter/upgrades/__init__.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/src/redturtle/voltoplugin/editablefooter/upgrades/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml b/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml new file mode 100644 index 0000000..035dca3 --- /dev/null +++ b/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml @@ -0,0 +1,16 @@ + + + + + + diff --git a/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py b/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py new file mode 100644 index 0000000..2d65a3e --- /dev/null +++ b/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import logging + +logger = logging.getLogger(__name__) + +DEFAULT_PROFILE = "profile-redturtle.voltoplugin.editablefooter:default" + + +def update_profile(context, profile, run_dependencies=True): + context.runImportStepFromProfile(DEFAULT_PROFILE, profile, run_dependencies) + + +def update_types(context): + update_profile(context, "typeinfo") + + +def update_rolemap(context): + update_profile(context, "rolemap") + + +def update_registry(context): + update_profile(context, "plone.app.registry", run_dependencies=False) + + +def update_controlpanel(context): + update_profile(context, "controlpanel") + + +def update_catalog(context): + update_profile(context, "catalog") From 0cb0bb8cfdee6609995599c7c7bda2bf8e9f3306 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 31 Jan 2024 14:05:13 +0100 Subject: [PATCH 2/4] fix readme --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 0a3ed0d..ece6552 100644 --- a/README.rst +++ b/README.rst @@ -25,6 +25,7 @@ To avoid enabling registry access to everyone, this package exposes a dedicated The response is something similar to this:: + { "footer_top": {...}, "footer_columns": [ From 59fe89d08c177f036d8c659afc8ec0fc4f785925 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 4 Mar 2024 13:54:51 +0100 Subject: [PATCH 3/4] revert old endpoint name --- CHANGES.rst | 2 -- .../voltoplugin/editablefooter/restapi/configure.zcml | 2 +- .../tests/test_editable_footer_data_service.py | 10 +++++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d833c7c..3b339ca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,8 +7,6 @@ Changelog - Add footer_top field in settings, to manage a new footer row before columns. [cekk] -- [BREAKING] Rename service endpoint to *@editable-footer-data* and changed its data structure. - [cekk] 1.2.1 (2024-01-17) diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml b/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml index 35e5e9f..5d216b6 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml +++ b/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml @@ -26,7 +26,7 @@ factory=".get.EditableFooterGet" for="Products.CMFCore.interfaces.ISiteRoot" permission="zope2.View" - name="@editable-footer-data" + name="@footer-columns" /> Date: Mon, 4 Mar 2024 13:55:54 +0100 Subject: [PATCH 4/4] fix readme --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index ece6552..f3cf092 100644 --- a/README.rst +++ b/README.rst @@ -19,9 +19,9 @@ Volto endpoint Anonymous users can't access registry resources by default with plone.restapi (there is a special permission). -To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@editable-footer-data*:: +To avoid enabling registry access to everyone, this package exposes a dedicated restapi route with the infos to draw the menu: *@footer-columns*:: - > curl -i http://localhost:8080/Plone/@editable-footer-data -H 'Accept: application/json' + > curl -i http://localhost:8080/Plone/@footer-columns -H 'Accept: application/json' The response is something similar to this::