Skip to content

Commit 67abe20

Browse files
committed
[#2055] Add option to use different template for action required notifications
1 parent 36acab5 commit 67abe20

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

src/open_inwoner/conf/parts/maileditor.py

+61
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,67 @@
410410
},
411411
],
412412
},
413+
"case_status_notification_action_required": {
414+
"name": _("Case status update notification (action required)"),
415+
"description": _(
416+
"This email is used to notify people about a new status being set on their case "
417+
"that requires action on their part."
418+
),
419+
"subject_default": "Action required",
420+
"body_default": """
421+
<p>Beste</p>
422+
423+
<p>U ontvangt deze email, omdat de status van een van uw zaken is bijgewerkt.</p>
424+
425+
<table>
426+
<tr>
427+
<th>Zaakidentificatie</th>
428+
<td>{{ identification }}</td>
429+
</tr>
430+
<tr>
431+
<th>Zaaktype</th>
432+
<td>{{ type_description }}</td>
433+
</tr>
434+
<tr>
435+
<th>Startdatum</th>
436+
<td>{{ start_date }}</td>
437+
</tr>
438+
</table>
439+
440+
<p><a href="{{ case_link }}">Ga naar uw zaak</a> </p>
441+
442+
<p>Met vriendelijke groet,
443+
{{ site_name }} </p>
444+
""",
445+
"subject": [
446+
{
447+
"name": "site_name",
448+
"description": _("Name of the site."),
449+
},
450+
],
451+
"body": [
452+
{
453+
"name": "identification",
454+
"description": _("The identification of the case"),
455+
},
456+
{
457+
"name": "type_description",
458+
"description": _("The description of the type of the case"),
459+
},
460+
{
461+
"name": "start_date",
462+
"description": _("The start date of the case"),
463+
},
464+
{
465+
"name": "case_link",
466+
"description": _("The link to the case details."),
467+
},
468+
{
469+
"name": "site_name",
470+
"description": _("Name of the site"),
471+
},
472+
],
473+
},
413474
"contactform_registration": {
414475
"name": _("Contact form registration notification"),
415476
"description": _("This email is used to register a contact form submission"),

src/open_inwoner/openzaak/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class ZaakTypeStatusTypeConfigInline(admin.StackedInline):
193193
"status_indicator",
194194
"status_indicator_text",
195195
"notify_status_change",
196+
"action_required",
196197
"document_upload_enabled",
197198
"document_upload_description",
198199
"description",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.2.23 on 2024-01-30 14:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("openzaak", "0042_case_notification_mail_template_split"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="zaaktypestatustypeconfig",
15+
name="action_required",
16+
field=models.BooleanField(
17+
default=False,
18+
help_text="Whether the status change notification should indicate that an action is required",
19+
verbose_name="Action required",
20+
),
21+
),
22+
]

src/open_inwoner/openzaak/models.py

+7
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ class ZaakTypeStatusTypeConfig(models.Model):
420420
"Whether the user should be notfied if a case is set to this type of status"
421421
),
422422
)
423+
action_required = models.BooleanField(
424+
verbose_name=_("Action required"),
425+
default=False,
426+
help_text=_(
427+
"Whether the status change notification should indicate that an action is required"
428+
),
429+
)
423430
document_upload_enabled = models.BooleanField(
424431
default=True,
425432
verbose_name=_("Document uploads"),

src/open_inwoner/openzaak/notifications.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def handle_status_update(
477477
user: User,
478478
case: Zaak,
479479
status: Status,
480+
status_type_config: ZaakTypeStatusTypeConfig,
480481
):
481482
# hook into userfeed
482483
hooks.case_status_notification_received(user, case, status)
@@ -505,7 +506,13 @@ def handle_status_update(
505506
)
506507
return
507508

508-
send_case_update_email(user, case, "case_status_notification")
509+
# choose template
510+
if status_type_config.action_required:
511+
template_name = "case_status_notification_action_required"
512+
else:
513+
template_name = "case_status_notification"
514+
515+
send_case_update_email(user, case, template_name)
509516
note.mark_sent()
510517

511518
log_system_action(

src/open_inwoner/openzaak/tests/test_notification_zaak_status.py

+53-5
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,21 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock):
540540
status = factory(Status, data.status_final)
541541
status.statustype = factory(StatusType, data.status_type_final)
542542

543+
ztc = ZaakTypeConfigFactory.create(
544+
catalogus=None,
545+
identificatie=data.zaak_type["identificatie"],
546+
# set this to notify
547+
notify_status_changes=True,
548+
)
549+
status_type_config = ZaakTypeStatusTypeConfigFactory.create(
550+
zaaktype_config=ztc,
551+
omschrijving=data.status_type_final["omschrijving"],
552+
statustype_url=data.status_type_final["url"],
553+
notify_status_change=True,
554+
)
555+
543556
# first call
544-
handle_status_update(user, case, status)
557+
handle_status_update(user, case, status, status_type_config)
545558

546559
mock_send.assert_called_once()
547560

@@ -566,7 +579,7 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock):
566579
)
567580

568581
# second call with same case/status
569-
handle_status_update(user, case, status)
582+
handle_status_update(user, case, status, status_type_config)
570583

571584
# no duplicate mail for this user/case/status
572585
mock_send.assert_not_called()
@@ -578,7 +591,7 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock):
578591
)
579592
# other user is fine
580593
other_user = UserFactory.create()
581-
handle_status_update(other_user, case, status)
594+
handle_status_update(other_user, case, status, status_type_config)
582595

583596
mock_send.assert_called_once()
584597

@@ -594,7 +607,7 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock):
594607
status.statustype = factory(
595608
StatusType, copy_with_new_uuid(data.status_type_final)
596609
)
597-
handle_status_update(user, case, status)
610+
handle_status_update(user, case, status, status_type_config)
598611

599612
# not sent because we already send to this user within the frequency
600613
mock_send.assert_not_called()
@@ -611,7 +624,42 @@ def test_handle_status_update(self, mock_send: Mock, mock_feed_hook: Mock):
611624
status.statustype = factory(
612625
StatusType, copy_with_new_uuid(data.status_type_final)
613626
)
614-
handle_status_update(user, case, status)
627+
handle_status_update(user, case, status, status_type_config)
615628

616629
# this one succeeds
617630
mock_send.assert_called_once()
631+
632+
@patch("open_inwoner.userfeed.hooks.case_status_notification_received")
633+
@patch("open_inwoner.openzaak.notifications.send_case_update_email")
634+
def test_action_required_template(self, mock_send: Mock, mock_feed_hook: Mock):
635+
data = MockAPIData()
636+
user = data.user_initiator
637+
638+
case = factory(Zaak, data.zaak)
639+
case.zaaktype = factory(ZaakType, data.zaak_type)
640+
641+
status = factory(Status, data.status_final)
642+
status.statustype = factory(StatusType, data.status_type_final)
643+
644+
ztc = ZaakTypeConfigFactory.create(
645+
catalogus=None,
646+
identificatie=data.zaak_type["identificatie"],
647+
# set this to notify
648+
notify_status_changes=True,
649+
)
650+
status_type_config = ZaakTypeStatusTypeConfigFactory.create(
651+
zaaktype_config=ztc,
652+
omschrijving=data.status_type_final["omschrijving"],
653+
statustype_url=data.status_type_final["url"],
654+
notify_status_change=True,
655+
action_required=True,
656+
)
657+
658+
handle_status_update(user, case, status, status_type_config)
659+
660+
mock_send.assert_called_once()
661+
# check call arguments
662+
args = mock_send.call_args.args
663+
self.assertEqual(args[0], user)
664+
self.assertEqual(args[1].url, case.url)
665+
self.assertEqual(args[2], "case_status_notification_action_required")

0 commit comments

Comments
 (0)