Skip to content

Commit

Permalink
Merge pull request #975 from maykinmedia/feature/2024-email-notif-dif…
Browse files Browse the repository at this point in the history
…ferent-types

✨ [#2024] Split email templates for zaak status/document notification
  • Loading branch information
alextreme authored Jan 22, 2024
2 parents d1c3777 + f043339 commit c63452b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 14 deletions.
78 changes: 69 additions & 9 deletions src/open_inwoner/conf/parts/maileditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": """
<p>Beste</p>
<p>You are receiving this email because one of your cases received a new status update or document attachment.</p>
<p>U ontvangt deze email, omdat de status van een van uw zaken is bijgewerkt.</p>
<table>
<tr>
<th>Case identification</th>
<th>Zaakidentificatie</th>
<td>{{ identification }}</td>
</tr>
<tr>
<th>Case type</th>
<th>Zaaktype</th>
<td>{{ type_description }}</td>
</tr>
<tr>
<th>Start date</th>
<th>Startdatum</th>
<td>{{ start_date }}</td>
</tr>
</table>
<p><a href="{{ case_link }}">Go to your case</a> </p>
<p><a href="{{ case_link }}">Ga naar uw zaak</a> </p>
<p>Met vriendelijke groet,
{{ site_name }} </p>
""",
"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": """
<p>Beste</p>
<p>U ontvangt deze email, omdat er bij een van uw zaken een document als bijlage is toegevoegd.</p>
<table>
<tr>
<th>Zaakidentificatie</th>
<td>{{ identification }}</td>
</tr>
<tr>
<th>Zaaktype</th>
<td>{{ type_description }}</td>
</tr>
<tr>
<th>Startdatum</th>
<td>{{ start_date }}</td>
</tr>
</table>
<p><a href="{{ case_link }}">Ga naar uw zaak</a> </p>
<p>Met vriendelijke groet,
{{ site_name }} </p>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
]
12 changes: 8 additions & 4 deletions src/open_inwoner/openzaak/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -396,21 +396,25 @@ 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
"""
case_detail_url = build_absolute_url(
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)


Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/openzaak/tests/test_notification_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit c63452b

Please sign in to comment.