Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the email vars list #31

Merged
merged 10 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ Changelog
[cekk]

- Compatibilize with the 2.0.1 redturtle.prenotazioni version.
[folix-01]
- Add the UO.contact_info field to @bookable-uo-list response.
[folix-01]
- Extend prenotazioni email vars list (unita_organizzativa_title, booking_print_url_with_delete_token).
[folix-01]


1.1.10 (2023-10-16)
Expand Down
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Servizio serializer

There is a customization of Servizio serializer that adds an additional field:

- `referenced_by_prenotazioni_folder` which idicates if it has backreferences to PrenotazioniFolder
- `referenced_by_prenotazioni_folder` which idicates if it has backreferences to PrenotazioniFolder
(design.plone.ioprenoto) throught correlated UO (with "Uffici correlati" field)

PrenotazioniFolder serializer
Expand All @@ -57,7 +57,7 @@ if the user has not `design.plone.ioprenoto.ManagePrenotazioni`.
@bookable-uo-list
-----------------

Endpoint that returns a list of *UnitaOrganizzativa* contents that have at least one PrenotazioniFolder that
Endpoint that returns a list of *UnitaOrganizzativa* contents that have at least one PrenotazioniFolder that
relates to it (with "Uffici correlati" field).

Parameters:
Expand Down Expand Up @@ -122,6 +122,15 @@ Response::
}


Content Rules (mail notifications) of redturtle.prenotazioni
------------------------------------------------------------

The email templates var list is extended by the following variables:

* ``${unita_organizzativa_title}`` - title of UnitaOrganizzativa related to PrenotazioniFolder.
* ``${booking_print_url_with_delete_token}`` - booking pring url with delete token.


Installation
============

Expand Down
7 changes: 7 additions & 0 deletions src/design/plone/ioprenoto/adapters/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@
name="booking_operator_url"
/>

<adapter
factory=".stringinterp.BookingUnitaOrganizzativaTitle"
provides="plone.stringinterp.interfaces.IStringSubstitution"
for="*"
name="unita_organizzativa_title"
/>

</configure>
24 changes: 24 additions & 0 deletions src/design/plone/ioprenoto/adapters/stringinterp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.registry.interfaces import IRegistry
from plone.stringinterp.adapters import BaseSubstitution
from plone.volto.interfaces import IVoltoSettings
from redturtle.prenotazioni.adapters import stringinterp as base
from zope.component import adapter, getUtility
Expand Down Expand Up @@ -62,3 +63,26 @@ def safe_call(self):
booking_folder.getPhysicalPath()[len(portal.getPhysicalPath()) :] # noqa
)
return f"{portal_url}/{booking_folder_path}?tab=search&SearchableText={self.context.getBookingCode()}&login=1"


@adapter(Interface)
class BookingUnitaOrganizzativaTitle(BaseSubstitution):
def safe_call(self):
# The PrenotazioniFolder c.t. object which contains the contextual booking
prenotazioni_folder = self.context.getPrenotazioniFolder()

# The Relation objects to related offices of PrenotazioniFolder
uffici_correlati_relations = prenotazioni_folder.uffici_correlati
mamico marked this conversation as resolved.
Show resolved Hide resolved

# Get first Relation object
ufficio_correlato_relation = (
uffici_correlati_relations and uffici_correlati_relations[0]
)

# Ufficio correlato object
ufficio_correlato = getattr(ufficio_correlato_relation, "to_object", None)

# Get ufficio correlato title
ufficio_correlato_title = getattr(ufficio_correlato, "title", "")

return ufficio_correlato_title
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def reply(self):
"id": uo.getId(),
"uid": uo.UID(),
"contact_info": self.get_uo_contact_info(uo),
"prenotazioni_folder": folders,
"prenotazioni_folder": sorted(
folders, key=lambda x: x["title"]
),
}
)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from plone.stringinterp.interfaces import IContextWrapper, IStringSubstitution
from plone.volto.interfaces import IVoltoSettings
from redturtle.prenotazioni.adapters.booker import IBooker
from zope.component import getAdapter, getUtility
from z3c.relationfield.relation import RelationValue
from zope.component import getAdapter, getUtility, queryUtility
from zope.intid.interfaces import IIntIds

from design.plone.ioprenoto.testing import DESIGN_PLONE_IOPRENOTO_FUNCTIONAL_TESTING


class TestStringinterpOverrides(unittest.TestCase):
class TestStringinterp(unittest.TestCase):
layer = DESIGN_PLONE_IOPRENOTO_FUNCTIONAL_TESTING

def setUp(self):
Expand All @@ -23,13 +25,33 @@ def setUp(self):
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ["Manager"])

self.unita_organizzativa = api.content.create(
container=self.portal,
type="UnitaOrganizzativa",
title="UO",
)
self.servizio = api.content.create(
container=self.portal,
type="Servizio",
title="Servizio",
ufficio_responsabile=[
RelationValue(
to_id=queryUtility(IIntIds).getId(self.unita_organizzativa)
)
],
)
self.folder_prenotazioni = api.content.create(
container=self.portal,
type="PrenotazioniFolder",
title="Prenota foo",
description="",
daData=date.today(),
gates=["Gate A"],
uffici_correlati=[
RelationValue(
to_id=queryUtility(IIntIds).getId(self.unita_organizzativa)
)
],
)
week_table = self.folder_prenotazioni.week_table
week_table[0]["morning_start"] = "0700"
Expand Down Expand Up @@ -114,3 +136,11 @@ def test_booking_print_url_override_with_custom_frontend_domain(
)(),
f"http://foo.bar/prenotazione-appuntamenti-uffici?booking_id={self.prenotazione.UID()}",
)

def test_unita_organizzativa_title(self):
self.assertEqual(
getAdapter(
self.prenotazione, IStringSubstitution, "unita_organizzativa_title"
)(),
self.unita_organizzativa.Title(),
)
Loading