From 2c94a0a09db8cf5429fb61c0d0352cdfb35ad5a0 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Mon, 25 Sep 2023 12:44:30 +0200 Subject: [PATCH] Workaround booking_url in @bookings differente per gestori e cittadini --- CHANGES.rst | 3 +- src/design/plone/ioprenoto/__init__.py | 1 + .../ovverrides/prenotazioniFolder.py | 2 +- .../restapi/services/bookings/search.py | 33 ++++++++++++------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b5188bd..69fd1aa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 1.1.7 (unreleased) ------------------ -- Nothing changed yet. +- Workaround booking_url in @bookings differente per gestori e cittadini + [mamico] 1.1.6 (2023-09-22) diff --git a/src/design/plone/ioprenoto/__init__.py b/src/design/plone/ioprenoto/__init__.py index 3664f7b..9e164b5 100644 --- a/src/design/plone/ioprenoto/__init__.py +++ b/src/design/plone/ioprenoto/__init__.py @@ -5,6 +5,7 @@ _ = MessageFactory("design.plone.ioprenoto") +PRENOTAZIONI_MANAGE_PERMISSION = "redturtle.prenotazioni: Manage Prenotazioni" # Non permettiamo ai redattori di scegliere se mostrare o meno il campo note, # ma lo mettiamo di default nello schema diff --git a/src/design/plone/ioprenoto/restapi/serializers/ovverrides/prenotazioniFolder.py b/src/design/plone/ioprenoto/restapi/serializers/ovverrides/prenotazioniFolder.py index cbe90fc..9939d12 100644 --- a/src/design/plone/ioprenoto/restapi/serializers/ovverrides/prenotazioniFolder.py +++ b/src/design/plone/ioprenoto/restapi/serializers/ovverrides/prenotazioniFolder.py @@ -1,4 +1,5 @@ from design.plone.ioprenoto.interfaces import IDesignPloneIoprenotoLayer +from design.plone.ioprenoto import PRENOTAZIONI_MANAGE_PERMISSION from plone import api from plone.restapi.interfaces import ISerializeToJson from plone.restapi.interfaces import ISerializeToJsonSummary @@ -9,7 +10,6 @@ from zope.interface import implementer -PRENOTAZIONI_MANAGE_PERMISSION = "redturtle.prenotazioni: Manage Prenotazioni" # TODO: move to registry PRENOTAZIONE_APPUNTAMENTO_ADDRESS = "prenotazione-appuntamenti-uffici" diff --git a/src/design/plone/ioprenoto/restapi/services/bookings/search.py b/src/design/plone/ioprenoto/restapi/services/bookings/search.py index f1a9c07..211646f 100644 --- a/src/design/plone/ioprenoto/restapi/services/bookings/search.py +++ b/src/design/plone/ioprenoto/restapi/services/bookings/search.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from plone import api +from design.plone.ioprenoto import PRENOTAZIONI_MANAGE_PERMISSION from redturtle.prenotazioni.restapi.services.bookings.search import ( BookingsSearch as BookingsSearchBase, BookingsSearchFolder as BookingsSearchFolderBase, @@ -13,12 +14,16 @@ class BookingsSearch(BookingsSearchBase): def reply(self): response = super().reply() - base_url = api.portal.get_registry_record( - name="volto.frontend_domain", default="" - ) - base_url = f"{base_url}/prenotazione-appuntamenti-uffici" - for item in response.get("items") or []: - item["booking_url"] = f"{base_url}?booking_id={item['booking_id']}" + if not api.user.has_permission( + PRENOTAZIONI_MANAGE_PERMISSION, + obj=self.context, + ): + base_url = api.portal.get_registry_record( + name="volto.frontend_domain", default="" + ) + base_url = f"{base_url}/prenotazione-appuntamenti-uffici" + for item in response.get("items") or []: + item["booking_url"] = f"{base_url}?booking_id={item['booking_id']}" return response @@ -27,10 +32,14 @@ def reply(self): class BookingsSearchFolder(BookingsSearchFolderBase): def reply(self): response = super().reply() - base_url = api.portal.get_registry_record( - name="volto.frontend_domain", default="" - ) - base_url = f"{base_url}/prenotazione-appuntamenti-uffici" - for item in response.get("items") or []: - item["booking_url"] = f"{base_url}?booking_id={item['booking_id']}" + if not api.user.has_permission( + PRENOTAZIONI_MANAGE_PERMISSION, + obj=self.context, + ): + base_url = api.portal.get_registry_record( + name="volto.frontend_domain", default="" + ) + base_url = f"{base_url}/prenotazione-appuntamenti-uffici" + for item in response.get("items") or []: + item["booking_url"] = f"{base_url}?booking_id={item['booking_id']}" return response