Skip to content

Commit

Permalink
Extend the email vars list (#31)
Browse files Browse the repository at this point in the history
* Extend the email vars list

* Fix changes

* add test

* Fix test

* Increase readability

* Update readme

* explain changes

* return sorted list of folders by title

---------

Co-authored-by: Mauro Amico <[email protected]>
Co-authored-by: Andrea Cecchi <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2023
1 parent 568aee8 commit 9fb7f17
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
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

# 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(),
)

0 comments on commit 9fb7f17

Please sign in to comment.