diff --git a/src/iosanita/policy/restapi/configure.zcml b/src/iosanita/policy/restapi/configure.zcml index 2d6e335..9735c60 100644 --- a/src/iosanita/policy/restapi/configure.zcml +++ b/src/iosanita/policy/restapi/configure.zcml @@ -4,9 +4,12 @@ > + + + + + + + diff --git a/src/iosanita/policy/restapi/deserializer/controlpanel.py b/src/iosanita/policy/restapi/deserializer/controlpanel.py new file mode 100644 index 0000000..a8c1d5f --- /dev/null +++ b/src/iosanita/policy/restapi/deserializer/controlpanel.py @@ -0,0 +1,32 @@ +from plone.restapi.deserializer import json_body +from plone.restapi.deserializer.controlpanels import ControlpanelDeserializeFromJson +from plone.restapi.interfaces import IDeserializeFromJson +from zope.component import adapter +from zope.interface import implementer +from iosanita.policy.interfaces import IIoSanitaSettingsControlpanel + + +@implementer(IDeserializeFromJson) +@adapter(IIoSanitaSettingsControlpanel) +class IoSanitaControlpanelDeserializeFromJson(ControlpanelDeserializeFromJson): + def __call__(self): + """ + Convert json data into a string + """ + super().__call__() + + req = json_body(self.controlpanel.request) + proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix) + + search_sections = req.get("search_sections", []) + for section in search_sections: + # simplify stored data + for item in section.get("items", []): + fixed_urls = [ + {"UID": x.get("UID", "")} + for x in item.get("linkUrl", []) + if x.get("UID", "") + ] + item["linkUrl"] = fixed_urls + + setattr(proxy, "search_sections", search_sections) diff --git a/src/iosanita/policy/restapi/serializer/__init__.py b/src/iosanita/policy/restapi/serializer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/iosanita/policy/restapi/serializer/configure.zcml b/src/iosanita/policy/restapi/serializer/configure.zcml new file mode 100644 index 0000000..b8f1092 --- /dev/null +++ b/src/iosanita/policy/restapi/serializer/configure.zcml @@ -0,0 +1,10 @@ + + + + + diff --git a/src/iosanita/policy/restapi/serializer/controlpanel.py b/src/iosanita/policy/restapi/serializer/controlpanel.py new file mode 100644 index 0000000..0f6be1c --- /dev/null +++ b/src/iosanita/policy/restapi/serializer/controlpanel.py @@ -0,0 +1,39 @@ +from plone.restapi.serializer.controlpanels import ControlpanelSerializeToJson +from plone.restapi.interfaces import ISerializeToJson +from zope.component import adapter +from zope.interface import implementer +from iosanita.policy.interfaces import IIoSanitaSettingsControlpanel +from plone import api +from plone.restapi.interfaces import ISerializeToJsonSummary +from zope.component import getMultiAdapter + +import json + + +@implementer(ISerializeToJson) +@adapter(IIoSanitaSettingsControlpanel) +class IoSanitaControlpanelSerializeToJson(ControlpanelSerializeToJson): + def __call__(self): + """ + Convert json data into a string + """ + json_data = super().__call__() + search_sections = json.loads(json_data["data"].get("search_sections", "{}")) + + for section in search_sections: + # expand stored data + for item in section.get("items", []): + expanded_links = [] + for link_url in item.get("linkUrl", []): + section = api.content.get(UID=link_url.get("UID", "")) + if not section: + continue + item_infos = getMultiAdapter( + (section, self.request), + ISerializeToJsonSummary, + )() + expanded_links.append(item_infos) + item["linkUrl"] = expanded_links + + json_data["data"]["search_sections"] = json.dumps(search_sections) + return json_data diff --git a/src/iosanita/policy/restapi/services/search_filters/get.py b/src/iosanita/policy/restapi/services/search_filters/get.py index 2e0ffe5..b8dbb02 100644 --- a/src/iosanita/policy/restapi/services/search_filters/get.py +++ b/src/iosanita/policy/restapi/services/search_filters/get.py @@ -29,6 +29,10 @@ def get_section_data(self, field_id): items = [] for section_settings in setting.get("items") or []: for uid in section_settings.get("linkUrl") or []: + if isinstance(uid, dict): + uid = uid.get("UID", "") + if not uid: + continue try: section = api.content.get(UID=uid) except Unauthorized: