diff --git a/.gitignore b/.gitignore index 50f3452..a61569d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ *.py? *.swp # dirs -__pycache__/ bin/ buildout-cache/ develop-eggs/ diff --git a/CHANGES.rst b/CHANGES.rst index 96e013b..e93222f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,26 +2,6 @@ Changelog ========= -1.3.2 (unreleased) ------------------- - -- Nothing changed yet. - - -1.3.1 (2024-03-14) ------------------- - -- Handle missing record in restapi endpoint. - [cekk] - - -1.3.0 (2024-03-07) ------------------- - -- Add footer_top field in settings, to manage a new footer row before columns. - [cekk] - - 1.2.1 (2024-01-17) ------------------ diff --git a/README.rst b/README.rst index f3cf092..bc232f9 100644 --- a/README.rst +++ b/README.rst @@ -26,19 +26,16 @@ To avoid enabling registry access to everyone, this package exposes a dedicated The response is something similar to this:: - { - "footer_top": {...}, - "footer_columns": [ - { - 'text': {'data': 'foo'}, - 'title': 'First column' - }, - { - 'text': {'content-type': 'text/html', 'data': ''}, - 'title': 'Second column' - } - ] - } + [ + { + 'text': {'data': 'foo'}, + 'title': 'First column' + }, + { + 'text': {'content-type': 'text/html', 'data': ''}, + 'title': 'Second column' + } + ] Control panel diff --git a/setup.py b/setup.py index 1708ce9..dece911 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="redturtle.voltoplugin.editablefooter", - version="1.3.2.dev0", + version="1.2.1", description="Add-on for Volto to manage four-columns footer", long_description=long_description, # Get more from https://pypi.org/classifiers/ diff --git a/src/redturtle/voltoplugin/editablefooter/configure.zcml b/src/redturtle/voltoplugin/editablefooter/configure.zcml index 326fe7d..758fbc4 100644 --- a/src/redturtle/voltoplugin/editablefooter/configure.zcml +++ b/src/redturtle/voltoplugin/editablefooter/configure.zcml @@ -16,8 +16,6 @@ - - diff --git a/src/redturtle/voltoplugin/editablefooter/interfaces.py b/src/redturtle/voltoplugin/editablefooter/interfaces.py index 4999113..98eaa91 100644 --- a/src/redturtle/voltoplugin/editablefooter/interfaces.py +++ b/src/redturtle/voltoplugin/editablefooter/interfaces.py @@ -10,15 +10,6 @@ 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/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po b/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po deleted file mode 100644 index 4c95fe2..0000000 --- a/src/redturtle/voltoplugin/editablefooter/locales/it/LC_MESSAGES/redturtle.voltoplugin.editablefooter.po +++ /dev/null @@ -1,65 +0,0 @@ -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\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" -"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: it\n" -"Language-Name: Italian\n" -"Preferred-Encodings: utf-8 latin1\n" -"Domain: DOMAIN\n" - -#: redturtle/voltoplugin/editablefooter/profiles/default/controlpanel.xml -msgid "Editable footer settings" -msgstr "Impostazioni footer" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:31 -msgid "Installs the redturtle.voltoplugin.editablefooter add-on." -msgstr "Installa redturtle.voltoplugin.editablefooter" - -#: 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: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: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: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:23 -msgid "footer_columns_label" -msgstr "Colonne footer" - -#. 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." - -#. 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.voltoplugin.editablefooter.pot b/src/redturtle/voltoplugin/editablefooter/locales/redturtle.voltoplugin.editablefooter.pot deleted file mode 100644 index b1fbdc8..0000000 --- a/src/redturtle/voltoplugin/editablefooter/locales/redturtle.voltoplugin.editablefooter.pot +++ /dev/null @@ -1,68 +0,0 @@ -#--- PLEASE EDIT THE LINES BELOW CORRECTLY --- -#SOME DESCRIPTIVE TITLE. -#FIRST AUTHOR , YEAR. -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\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" -"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: redturtle.voltoplugin.editablefooter\n" - -#: redturtle/voltoplugin/editablefooter/profiles/default/controlpanel.xml -msgid "Editable footer settings" -msgstr "" - -#: redturtle/voltoplugin/editablefooter/configure.zcml:31 -msgid "Installs the redturtle.voltoplugin.editablefooter add-on." -msgstr "" - -#: 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:12 -msgid "editable_footer_settings_help" -msgstr "" - -#. Default: "Editable Footer Settings" -#: 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:24 -msgid "footer_columns_help" -msgstr "" - -#. Default: "Footer columns" -#: redturtle/voltoplugin/editablefooter/interfaces.py:23 -msgid "footer_columns_label" -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 "" - -#. 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 1c6ad48..2c6cd42 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 2d36211..6ec05d9 100644 --- a/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml +++ b/src/redturtle/voltoplugin/editablefooter/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1001 + 1000 profile-plone.restapi:default diff --git a/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml b/src/redturtle/voltoplugin/editablefooter/restapi/configure.zcml index 5d216b6..07b360c 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 77b7814..48ee160 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/deserializer.py @@ -21,21 +21,15 @@ def __call__(self): req = json_body(self.controlpanel.request) proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix) errors = [] - footer_top = req.get("footer_top", {}) - footer_columns = req.get("footer_columns", {}) - - if not footer_columns: + data = req.get("footer_columns", {}) + if not data: 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(footer_columns)) + setattr(proxy, "footer_columns", json.dumps(data)) 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 5ed110b..097a635 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/get.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/get.py @@ -20,23 +20,17 @@ @implementer(IPublishTraverse) -class EditableFooterGet(Service): +class FooterColumns(Service): + def __init__(self, context, request): + super(FooterColumns, self).__init__(context, request) + def reply(self): - res = {"footer_top": None, "footer_columns": None} - footer_columns = api.portal.get_registry_record( + record = api.portal.get_registry_record( "footer_columns", interface=IEditableFooterSettings, default="" ) - try: - footer_top = api.portal.get_registry_record( - "footer_top", interface=IEditableFooterSettings, default="" - ) - except KeyError: - footer_top = "" - if footer_top: - res["footer_top"] = json.loads(footer_top) - if not footer_columns: - return res - data = json.loads(footer_columns) + if not record: + return [] + data = json.loads(record) portal_url = self.get_portal_url() for el in data or []: if isinstance(el, dict): @@ -50,8 +44,7 @@ def reply(self): item["text"]["data"] = item["text"]["data"].replace( 'href="/', f'href="{portal_url}/' ) - res["footer_columns"] = data - return res + return data 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 c11a62e..0428c16 100644 --- a/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py +++ b/src/redturtle/voltoplugin/editablefooter/restapi/serializer.py @@ -15,8 +15,7 @@ class EditableFooterControlpanelSerializeToJson(ControlpanelSerializeToJson): def __call__(self): json_data = super(EditableFooterControlpanelSerializeToJson, self).__call__() - for field in ["footer_columns", "footer_top"]: - value = json_data["data"].get(field, "") - if value: - json_data["data"][field] = json.loads(value) + conf = json_data["data"].get("footer_columns", "") + if conf: + json_data["data"]["footer_columns"] = json.loads(conf) return json_data diff --git a/src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py b/src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py deleted file mode 100644 index bba906c..0000000 --- a/src/redturtle/voltoplugin/editablefooter/tests/test_editable_footer_data_service.py +++ /dev/null @@ -1,123 +0,0 @@ -# -*- coding: utf-8 -*- -from plone import api -from plone.app.testing import applyProfile -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.registry.interfaces import IRegistry -from plone.restapi.testing import RelativeSession -from redturtle.voltoplugin.editablefooter.interfaces import IEditableFooterSettings -from redturtle.voltoplugin.editablefooter.testing import ( - VOLTO_EDITABLEFOOTER_API_FUNCTIONAL_TESTING, -) -from transaction import commit -from zope.component import getUtility - - -import json -import unittest - - -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() - 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.footer_columns_value = [ - { - "items": [ - {"text": {"data": 'Link 1'}}, - {"text": {"data": 'Link 1'}}, - ] - } - ] - self.set_record_value( - field="footer_columns", value=json.dumps(self.footer_columns_value) - ) - - def tearDown(self): - self.api_session.close() - - 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") - self.assertEqual(response.status_code, 200) - self.assertEqual(response.headers.get("Content-Type"), "application/json") - - def test_return_data_structure(self): - response = self.api_session.get("/@footer-columns") - 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("/@footer-columns") - self.assertEqual(response.status_code, 200) - result = response.json() - # 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["footer_columns"]), - json.dumps(self.footer_columns_value).replace( - 'href=\\"/', f'href=\\"{self.portal_url}/' - ), - ) - - -class EditableFooterDataServiceTestWithPloneVolto(BaseTest): - layer = VOLTO_EDITABLEFOOTER_API_FUNCTIONAL_TESTING - - def setUp(self): - super().setUp() - applyProfile(self.portal, "plone.volto:default") - - def test_return_json_data_with_portal_url_if_plone_volto_installed_and_not_configured( - self, - ): - response = self.api_session.get("/@footer-columns") - self.assertEqual(response.status_code, 200) - result = response.json() - # 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["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): - from plone.volto.interfaces import IVoltoSettings - - registry = getUtility(IRegistry) - settings = registry.forInterface(IVoltoSettings, prefix="volto", check=False) - settings.frontend_domain = "http://foo.org" - commit() - - response = self.api_session.get("/@footer-columns") - self.assertEqual(response.status_code, 200) - result = response.json() - # 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["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 deleted file mode 100644 index 40a96af..0000000 --- a/src/redturtle/voltoplugin/editablefooter/upgrades/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml b/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml deleted file mode 100644 index 035dca3..0000000 --- a/src/redturtle/voltoplugin/editablefooter/upgrades/configure.zcml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py b/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py deleted file mode 100644 index 2d65a3e..0000000 --- a/src/redturtle/voltoplugin/editablefooter/upgrades/upgrades.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- 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")