diff --git a/src/redturtle/prenotazioni/content/prenotazioni_folder.py b/src/redturtle/prenotazioni/content/prenotazioni_folder.py index a859dfc5..c2d45174 100644 --- a/src/redturtle/prenotazioni/content/prenotazioni_folder.py +++ b/src/redturtle/prenotazioni/content/prenotazioni_folder.py @@ -18,7 +18,10 @@ from redturtle.prenotazioni import _ from redturtle.prenotazioni.browser.widget import WeekTableOverridesFieldWidget from redturtle.prenotazioni.config import DEFAULT_VISIBLE_BOOKING_FIELDS -from redturtle.prenotazioni.content.validators import PauseValidator, checkOverrides +from redturtle.prenotazioni.content.validators import ( + PauseValidator, + checkOverrides, +) try: from plone.app.dexterity import textindexer @@ -42,7 +45,9 @@ def get_from_form(form, fieldname): return value return None - number_of_entry = request.form.get("form.widgets.{}.count".format(fieldname)) + number_of_entry = request.form.get( + "form.widgets.{}.count".format(fieldname) + ) data = [] prefix = "form.widgets.{}".format(fieldname) for counter in range(int(number_of_entry)): @@ -82,7 +87,9 @@ class IWeekTableRow(model.Schema): ) afternoon_start = schema.Choice( - title=_("afternoon_start_label", default="Start time in the afternoon"), + title=_( + "afternoon_start_label", default="Start time in the afternoon" + ), vocabulary="redturtle.prenotazioni.VocOreInizio", required=False, ) @@ -130,6 +137,11 @@ class IBookingTypeRow(Interface): required=True, vocabulary="redturtle.prenotazioni.VocDurataIncontro", ) + hidden = schema.Bool( + title=_("Hidden type"), + required=False, + default=False, + ) @provider(IContextAwareDefaultFactory) @@ -217,7 +229,9 @@ class IPrenotazioniFolder(model.Schema): descriptionAgenda = RichText( required=False, title=_("Descrizione Agenda", default="Descrizione Agenda"), - description=_("Inserire il testo di presentazione dell'agenda corrente"), + description=_( + "Inserire il testo di presentazione dell'agenda corrente" + ), ) form.mode(descriptionAgenda="display") @@ -232,7 +246,9 @@ class IPrenotazioniFolder(model.Schema): directives.widget(visible_booking_fields=CheckBoxFieldWidget) visible_booking_fields = schema.List( - title=_("label_visible_booking_fields", default="Visible booking fields"), + title=_( + "label_visible_booking_fields", default="Visible booking fields" + ), description=_( "help_visible_booking_fields", "User will not be able to add a booking unless those " @@ -250,7 +266,9 @@ class IPrenotazioniFolder(model.Schema): directives.widget(required_booking_fields=CheckBoxFieldWidget) required_booking_fields = schema.List( - title=_("label_required_booking_fields", default="Required booking fields"), + title=_( + "label_required_booking_fields", default="Required booking fields" + ), description=_( "help_required_booking_fields", "User will not be able to add a booking unless those " @@ -500,10 +518,14 @@ def data_validation(data): raise Invalid(_("You should set a start time for afternoon.")) if interval["morning_start"] and interval["morning_end"]: if interval["morning_start"] > interval["morning_end"]: - raise Invalid(_("Morning start should not be greater than end.")) + raise Invalid( + _("Morning start should not be greater than end.") + ) if interval["afternoon_start"] and interval["afternoon_end"]: if interval["afternoon_start"] > interval["afternoon_end"]: - raise Invalid(_("Afternoon start should not be greater than end.")) + raise Invalid( + _("Afternoon start should not be greater than end.") + ) # TODO: definire o descrivere quando avviee la notifica # TODO: inserire qui la chiave IO ? o su un config in zope.conf/environment ? diff --git a/src/redturtle/prenotazioni/restapi/serializers/adapters/configure.zcml b/src/redturtle/prenotazioni/restapi/serializers/adapters/configure.zcml index 4b43a5ea..851d9788 100644 --- a/src/redturtle/prenotazioni/restapi/serializers/adapters/configure.zcml +++ b/src/redturtle/prenotazioni/restapi/serializers/adapters/configure.zcml @@ -6,5 +6,6 @@ + diff --git a/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazioni_folder.py b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazioni_folder.py new file mode 100644 index 00000000..392c246c --- /dev/null +++ b/src/redturtle/prenotazioni/restapi/serializers/adapters/prenotazioni_folder.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from plone import api +from plone.restapi.interfaces import IFieldSerializer, ISerializeToJson +from plone.restapi.serializer.converters import json_compatible +from zope.component import adapter, getMultiAdapter +from zope.i18n import translate +from zope.interface import implementer +from zope.publisher.interfaces import IRequest +from zope.schema import getFields +from plone.restapi.serializer.dxcontent import SerializeFolderToJson + +from redturtle.prenotazioni import logger +from redturtle.prenotazioni.content.prenotazioni_folder import ( + IPrenotazioniFolder, +) +from redturtle.prenotazioni.interfaces import ( + ISerializeToPrenotazioneSearchableItem, +) +from redturtle.prenotazioni.interfaces import IRedturtlePrenotazioniLayer + +from copy import deepcopy + + +@implementer(ISerializeToJson) +@adapter(IPrenotazioniFolder, IRedturtlePrenotazioniLayer) +class PrenotazioniFolderSerializer(SerializeFolderToJson): + def __call__(self, *args, **kwargs): + res = super().__call__() + + for index, type in enumerate(deepcopy(res.get("booking_types", {}))): + if type.get("hidden"): + del res["booking_types"][index] + + return res diff --git a/src/redturtle/prenotazioni/tests/test_prenotazioni_folder_serializer.py b/src/redturtle/prenotazioni/tests/test_prenotazioni_folder_serializer.py new file mode 100644 index 00000000..d8dbc97d --- /dev/null +++ b/src/redturtle/prenotazioni/tests/test_prenotazioni_folder_serializer.py @@ -0,0 +1,90 @@ +# -*- coding: UTF-8 -*- +import email +import unittest +from datetime import date, datetime, timedelta + +import pytz +from collective.contentrules.mailfromfield.actions.mail import ( + MailFromFieldAction, +) +from plone import api +from plone.app.testing import TEST_USER_ID, setRoles +from plone.contentrules.rule.interfaces import IExecutable +from Products.CMFCore.WorkflowCore import ActionSucceededEvent +from zope.component import getMultiAdapter +from zope.interface import implementer +from zope.interface.interfaces import IObjectEvent +from zope.globalrequest import getRequest +from plone.restapi.interfaces import ISerializeToJson + +from redturtle.prenotazioni.adapters.booker import IBooker +from redturtle.prenotazioni.testing import ( + REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING, +) + + +@implementer(IObjectEvent) +class DummyEvent(object): + def __init__(self, object): + self.object = object + + +class TestEmailToManagers(unittest.TestCase): + layer = REDTURTLE_PRENOTAZIONI_FUNCTIONAL_TESTING + + def setUp(self): + self.app = self.layer["app"] + self.portal = self.layer["portal"] + self.mailhost = self.portal.MailHost + self.hidden_type_name = "Type Hidden" + self.not_hidden_type_name = "Type visible" + + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + + self.folder_prenotazioni = api.content.create( + container=self.portal, + type="PrenotazioniFolder", + title="Prenota foo", + description="", + daData=date.today(), + booking_types=[ + { + "name": self.hidden_type_name, + "duration": "30", + "hidden": True, + }, + { + "name": self.not_hidden_type_name, + "duration": "30", + "hidden": False, + }, + ], + gates=["Gate A"], + ) + week_table = self.folder_prenotazioni.week_table + for data in week_table: + data["morning_start"] = "0700" + data["morning_end"] = "1000" + self.folder_prenotazioni.week_table = week_table + + def test_hidden_type_is_not_shown(self): + self.assertNotIn( + self.hidden_type_name, + [ + i["name"] + for i in getMultiAdapter( + (self.folder_prenotazioni, getRequest()), ISerializeToJson + )()["booking_types"] + ], + ) + + def test_not_hidden_type_is_being_shown(self): + self.assertIn( + self.not_hidden_type_name, + [ + i["name"] + for i in getMultiAdapter( + (self.folder_prenotazioni, getRequest()), ISerializeToJson + )()["booking_types"] + ], + )