diff --git a/.isort.cfg b/.isort.cfg
new file mode 100644
index 0000000..40c8f14
--- /dev/null
+++ b/.isort.cfg
@@ -0,0 +1,2 @@
+[settings]
+profile=plone
diff --git a/CHANGES.rst b/CHANGES.rst
index 645d296..7a934ad 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,8 @@ Changelog
1.2.1 (unreleased)
------------------
+- booking_type vocabulary for Service
+ [mamico]
- Align tests with redturtle.prenotazioni > 2.2.5.
[cekk]
diff --git a/src/design/plone/ioprenoto/configure.zcml b/src/design/plone/ioprenoto/configure.zcml
index 0c87f3d..98267e9 100644
--- a/src/design/plone/ioprenoto/configure.zcml
+++ b/src/design/plone/ioprenoto/configure.zcml
@@ -20,6 +20,7 @@
+
diff --git a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py
index d2384c4..5558be6 100644
--- a/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py
+++ b/src/design/plone/ioprenoto/restapi/services/bookable_list/get.py
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
from logging import getLogger
-from urllib.parse import urlencode
-
from plone import api
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.services import Service
+from urllib.parse import urlencode
from zc.relation.interfaces import ICatalog
-from zope.component import getMultiAdapter, getUtility
+from zope.component import getMultiAdapter
+from zope.component import getUtility
from zope.intid.interfaces import IIntIds
+
logger = getLogger(__name__)
@@ -28,7 +29,9 @@ def reply(self):
portal_url = api.portal.get().absolute_url()
query = {"portal_type": "Servizio", "sort_on": "sortable_title"}
for brain_service in api.content.find(**query):
- # service = brain.getObject()
+ # XXX: get_uo_from_service_uid ha l'object, ma anzichè usarlo, si tira fuori lo UID
+ # e poi si cerca quell'UID nel catalog. Sicuarmente questo aiuta a escludere
+ # oggetti privati, ma sembra un passaggio inutilmente complicato (?)
for brain_uo in api.content.find(
UID=self.get_uo_from_service_uid(uid=brain_service.UID)
):
diff --git a/src/design/plone/ioprenoto/utilities.py b/src/design/plone/ioprenoto/utilities.py
new file mode 100644
index 0000000..16d3c0e
--- /dev/null
+++ b/src/design/plone/ioprenoto/utilities.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+
+
+def get_uo_from_service(service):
+ """Dato lo UID di un servizio, restituisce le UO a cui è collegato
+ come canale fisico o unità organizzativa responsabile"""
+ canale_fisico = getattr(service, "canale_fisico", [])
+ if canale_fisico:
+ return [x.to_object for x in canale_fisico if x.to_object]
+ ufficio_responsabile = getattr(service, "ufficio_responsabile", [])
+ return [x.to_object for x in ufficio_responsabile if x.to_object]
diff --git a/src/design/plone/ioprenoto/vocabularies/__init__py b/src/design/plone/ioprenoto/vocabularies/__init__py
new file mode 100644
index 0000000..e69de29
diff --git a/src/design/plone/ioprenoto/vocabularies/configure.zcml b/src/design/plone/ioprenoto/vocabularies/configure.zcml
new file mode 100644
index 0000000..c348d50
--- /dev/null
+++ b/src/design/plone/ioprenoto/vocabularies/configure.zcml
@@ -0,0 +1,11 @@
+
+
+
+
+
diff --git a/src/design/plone/ioprenoto/vocabularies/tipologies.py b/src/design/plone/ioprenoto/vocabularies/tipologies.py
new file mode 100644
index 0000000..75fe7fb
--- /dev/null
+++ b/src/design/plone/ioprenoto/vocabularies/tipologies.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+from design.plone.ioprenoto.utilities import get_uo_from_service
+from plone import api
+from redturtle.prenotazioni.vocabularies.tipologies import (
+ PrenotazioneTypesVocabulary as Base,
+)
+from zc.relation.interfaces import ICatalog
+from zope.component import getUtility
+from zope.interface import implementer
+from zope.intid.interfaces import IIntIds
+from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleVocabulary
+
+
+@implementer(IVocabularyFactory)
+class PrenotazioneTypesVocabulary(Base):
+ def __call__(self, context):
+ """
+ Return all the tipologies defined in the PrenotazioniFolder related to a Service
+ """
+ terms = []
+ intids = getUtility(IIntIds)
+ catalog = getUtility(ICatalog)
+ for uo in get_uo_from_service(context) or []:
+ relations = catalog.findRelations(
+ {
+ "to_id": intids.getId(uo),
+ "from_attribute": "uffici_correlati",
+ }
+ )
+ for rel in relations:
+ prenotazioni_folder = rel.from_object
+ if prenotazioni_folder and api.user.has_permission(
+ "View", obj=prenotazioni_folder
+ ):
+ terms.extend(
+ [
+ self.booking_type2term(booking_type)
+ for booking_type in prenotazioni_folder.get_booking_types()
+ ]
+ )
+ return SimpleVocabulary(terms)
+
+
+PrenotazioneTypesVocabularyFactory = PrenotazioneTypesVocabulary()