From f04333937ad98191ec08c81381726116c72aaea5 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 19 Jan 2024 15:54:24 +0100 Subject: [PATCH] :sparkles: [#2024] Split email templates for zaak status/document notification task: https://taiga.maykinmedia.nl/project/open-inwoner/task/2024 --- src/open_inwoner/conf/parts/maileditor.py | 78 ++++++++++++++++--- ...2_case_notification_mail_template_split.py | 49 ++++++++++++ src/open_inwoner/openzaak/notifications.py | 12 ++- .../openzaak/tests/test_notification_utils.py | 2 +- .../test_notification_zaak_infoobject.py | 1 + .../tests/test_notification_zaak_status.py | 1 + 6 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 src/open_inwoner/openzaak/migrations/0042_case_notification_mail_template_split.py diff --git a/src/open_inwoner/conf/parts/maileditor.py b/src/open_inwoner/conf/parts/maileditor.py index 1644a8343d..e69b1da29c 100644 --- a/src/open_inwoner/conf/parts/maileditor.py +++ b/src/open_inwoner/conf/parts/maileditor.py @@ -290,33 +290,93 @@ }, ], }, - "case_notification": { - "name": _("Case update notification"), + "case_status_notification": { + "name": _("Case status update notification"), "description": _( - "This email is used to notify people an update happened to their case" + "This email is used to notify people about a new status being set on their case" ), - "subject_default": "Update to your case at {{ site_name }}", + "subject_default": "Uw zaak is bijgewerkt op {{ site_name }}", "body_default": """

Beste

-

You are receiving this email because one of your cases received a new status update or document attachment.

+

U ontvangt deze email, omdat de status van een van uw zaken is bijgewerkt.

- + - + - +
Case identificationZaakidentificatie {{ identification }}
Case typeZaaktype {{ type_description }}
Start dateStartdatum {{ start_date }}
-

Go to your case

+

Ga naar uw zaak

+ +

Met vriendelijke groet, + {{ site_name }}

+ """, + "subject": [ + { + "name": "site_name", + "description": _("Name of the site."), + }, + ], + "body": [ + { + "name": "identification", + "description": _("The identification of the case"), + }, + { + "name": "type_description", + "description": _("The description of the type of the case"), + }, + { + "name": "start_date", + "description": _("The start date of the case"), + }, + { + "name": "case_link", + "description": _("The link to the case details."), + }, + { + "name": "site_name", + "description": _("Name of the site"), + }, + ], + }, + "case_document_notification": { + "name": _("Case document update notification"), + "description": _( + "This email is used to notify people that a new document was added to their case" + ), + "subject_default": "Uw zaak is bijgewerkt op {{ site_name }}", + "body_default": """ +

Beste

+ +

U ontvangt deze email, omdat er bij een van uw zaken een document als bijlage is toegevoegd.

+ + + + + + + + + + + + + + +
Zaakidentificatie{{ identification }}
Zaaktype{{ type_description }}
Startdatum{{ start_date }}
+ +

Ga naar uw zaak

Met vriendelijke groet, {{ site_name }}

diff --git a/src/open_inwoner/openzaak/migrations/0042_case_notification_mail_template_split.py b/src/open_inwoner/openzaak/migrations/0042_case_notification_mail_template_split.py new file mode 100644 index 0000000000..bb444a65d3 --- /dev/null +++ b/src/open_inwoner/openzaak/migrations/0042_case_notification_mail_template_split.py @@ -0,0 +1,49 @@ +# Generated by Django 3.2.23 on 2024-01-19 15:02 + +from django.db import migrations + + +def split_case_notification_mail_template(apps, schema_editor): + """ + Split the `case_notification` email template into two separate templates, one for + status notifications and one for document notifications + """ + MailTemplate = apps.get_model("mail_editor", "MailTemplate") + + case_notification_template = MailTemplate.objects.filter( + template_type="case_notification" + ).first() + + if case_notification_template: + case_notification_template.template_type = "case_status_notification" + case_notification_template.save() + + case_notification_template.pk = None + case_notification_template.template_type = "case_document_notification" + case_notification_template.save() + + +def join_case_notification_mail_template(apps, schema_editor): + MailTemplate = apps.get_model("mail_editor", "MailTemplate") + + case_notification_template = MailTemplate.objects.get( + template_type="case_status_notification" + ) + MailTemplate.objects.get(template_type="case_document_notification").delete() + + case_notification_template.template_type = "case_notification" + case_notification_template.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("mail_editor", "0001_initial"), + ("openzaak", "0041_configuration_cases_button"), + ] + + operations = [ + migrations.RunPython( + split_case_notification_mail_template, join_case_notification_mail_template + ) + ] diff --git a/src/open_inwoner/openzaak/notifications.py b/src/open_inwoner/openzaak/notifications.py index ae2e85345c..f801ae26ec 100644 --- a/src/open_inwoner/openzaak/notifications.py +++ b/src/open_inwoner/openzaak/notifications.py @@ -247,7 +247,7 @@ def handle_zaakinformatieobject_update( ) return - send_case_update_email(user, case) + send_case_update_email(user, case, "case_document_notification") note.mark_sent() log_system_action( @@ -387,7 +387,7 @@ def handle_status_update(user: User, case: Zaak, status: Status): ) return - send_case_update_email(user, case) + send_case_update_email(user, case, "case_status_notification") note.mark_sent() log_system_action( @@ -396,7 +396,9 @@ def handle_status_update(user: User, case: Zaak, status: Status): ) -def send_case_update_email(user: User, case: Zaak): +def send_case_update_email( + user: User, case: Zaak, template_name: str, extra_context: dict = None +): """ send the actual mail """ @@ -404,13 +406,15 @@ def send_case_update_email(user: User, case: Zaak): reverse("cases:case_detail", kwargs={"object_id": str(case.uuid)}) ) - template = find_template("case_notification") + template = find_template(template_name) context = { "identification": case.identification, "type_description": case.zaaktype.omschrijving, "start_date": case.startdatum, "case_link": case_detail_url, } + if extra_context: + context.update(extra_context) template.send_email([user.email], context) diff --git a/src/open_inwoner/openzaak/tests/test_notification_utils.py b/src/open_inwoner/openzaak/tests/test_notification_utils.py index 66ef357a28..55736d4caa 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_utils.py +++ b/src/open_inwoner/openzaak/tests/test_notification_utils.py @@ -42,7 +42,7 @@ def test_send_case_update_email(self): Zaak, "_format_zaak_identificatie" ) as format_identificatie: format_identificatie.return_value = ret_val - send_case_update_email(user, case) + send_case_update_email(user, case, "case_status_notification") format_identificatie.assert_called_once() diff --git a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py index 0bbcf05929..7166e6dbe1 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py +++ b/src/open_inwoner/openzaak/tests/test_notification_zaak_infoobject.py @@ -419,6 +419,7 @@ def test_handle_zaak_info_object_update( args = mock_send.call_args.args self.assertEqual(args[0], user) self.assertEqual(args[1].url, case.url) + self.assertEqual(args[2], "case_document_notification") mock_send.reset_mock() diff --git a/src/open_inwoner/openzaak/tests/test_notification_zaak_status.py b/src/open_inwoner/openzaak/tests/test_notification_zaak_status.py index 3e93f1209b..78de3c6638 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_zaak_status.py +++ b/src/open_inwoner/openzaak/tests/test_notification_zaak_status.py @@ -532,6 +532,7 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock): args = mock_send.call_args.args self.assertEqual(args[0], user) self.assertEqual(args[1].url, case.url) + self.assertEqual(args[2], "case_status_notification") mock_send.reset_mock()