Skip to content

Commit

Permalink
Merge pull request #838 from maykinmedia/feature/1839-notifications
Browse files Browse the repository at this point in the history
[#1839] Enable/disable notifications per status type
  • Loading branch information
stevenbal authored Nov 13, 2023
2 parents 3579d7f + 6f8e3ff commit 5893b4e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/open_inwoner/openzaak/migrations/0029_auto_20231113_1459.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.20 on 2023-11-13 13:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0028_merge_20231101_1705"),
]

operations = [
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="notify_status_change",
field=models.BooleanField(
verbose_name="Notify of status change",
default=True,
help_text="Whether the user should be notfied if a case is set to this type of status",
),
),
migrations.AlterField(
model_name="zaaktypeconfig",
name="notify_status_changes",
field=models.BooleanField(
default=False,
help_text="Whether the user should be notified of status changes for cases with this zaak type",
verbose_name="Notify of status changes",
),
),
]
13 changes: 13 additions & 0 deletions src/open_inwoner/openzaak/migrations/0030_merge_20231113_1518.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.20 on 2023-11-13 14:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0029_auto_20231113_1459"),
("openzaak", "0029_zaaktypestatustypeconfig_description"),
]

operations = []
15 changes: 14 additions & 1 deletion src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ class ZaakTypeConfig(models.Model):
# actual config

# notifications
notify_status_changes = models.BooleanField(default=False)
notify_status_changes = models.BooleanField(
verbose_name=_("Notify of status changes"),
default=False,
help_text=_(
"Whether the user should be notified of status changes for cases with this zaak type"
),
)

# documents
description = models.TextField(
Expand Down Expand Up @@ -370,6 +376,13 @@ class ZaakTypeStatusTypeConfig(models.Model):
"The text displayed in the case detail page for the status with this statustype"
),
)
notify_status_change = models.BooleanField(
verbose_name=_("Notify of status change"),
default=True,
help_text=_(
"Whether the user should be notfied if a case is set to this type of status"
),
)

class Meta:
verbose_name = _("Zaaktype Statustype Configuration")
Expand Down
23 changes: 22 additions & 1 deletion src/open_inwoner/openzaak/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
fetch_single_case_information_object,
fetch_single_status,
fetch_status_history_no_cache,
resolve_status,
)
from open_inwoner.openzaak.catalog import (
fetch_single_case_type,
Expand All @@ -43,6 +44,8 @@
from open_inwoner.utils.logentry import system_action as log_system_action
from open_inwoner.utils.url import build_absolute_url

from .models import ZaakTypeStatusTypeConfig

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -312,13 +315,31 @@ def _handle_status_notification(notification: Notification, case: Zaak, inform_u
)
return

# check status notification setting on `ZaakTypeStatusTypeConfig`
resolve_status(case)
statustype_url = case.status.statustype

try:
statustype_config = ZaakTypeStatusTypeConfig.objects.get(
statustype_url=statustype_url
)
except ZaakTypeStatusTypeConfig.DoesNotExist:
pass
else:
if not statustype_config.notify_status_change:
log_system_action(
f"ignored {r} notification: 'notify_status_change' is False for the status "
f"type configuration of the status of this case ({case.url})",
log_level=logging.INFO,
)
return

# reaching here means we're going to inform users
log_system_action(
f"accepted {r} notification: attempt informing users {wrap_join(inform_users)} for case {case.url}",
log_level=logging.INFO,
)
for user in inform_users:
# TODO run in try/except so it can't bail?
handle_status_update(user, case, status)


Expand Down
41 changes: 37 additions & 4 deletions src/open_inwoner/openzaak/tests/test_notification_zaak_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
handle_status_update,
handle_zaken_notification,
)
from open_inwoner.openzaak.tests.factories import (
NotificationFactory,
ZaakTypeConfigFactory,
)
from open_inwoner.utils.test import ClearCachesMixin
from open_inwoner.utils.tests.helpers import AssertTimelineLogMixin, Lookups

from ..api_models import Status, StatusType, Zaak, ZaakType
from ..models import OpenZaakConfig, UserCaseStatusNotification
from .factories import (
NotificationFactory,
ZaakTypeConfigFactory,
ZaakTypeStatusTypeConfigFactory,
)
from .helpers import copy_with_new_uuid
from .test_notification_data import MockAPIData

Expand Down Expand Up @@ -321,6 +322,38 @@ def test_status_handle_notification_when_skip_informeren_is_set_and_zaaktypeconf
level=logging.INFO,
)

def test_status_handle_notification_status_type_config_notify_false(
self, m, mock_handle: Mock
):
oz_config = OpenZaakConfig.get_solo()
oz_config.skip_notification_statustype_informeren = True
oz_config.save()

data = MockAPIData().install_mocks(m)

zaaktype_config = ZaakTypeConfigFactory.create(
catalogus__url=data.zaak_type["catalogus"],
identificatie=data.zaak_type["identificatie"],
# set this to notify
notify_status_changes=True,
)

ZaakTypeStatusTypeConfigFactory.create(
zaaktype_config=zaaktype_config,
statustype_url=data.status_type_final["url"],
notify_status_change=False,
)

handle_zaken_notification(data.status_notification)

mock_handle.assert_not_called()

self.assertTimelineLog(
"ignored status notification: 'notify_status_change' is False",
lookup=Lookups.startswith,
level=logging.INFO,
)

def test_status_handle_notification_when_skip_informeren_is_set_and_zaaktypeconfig_is_found_from_zaaktype_none_catalog(
self, m, mock_handle: Mock
):
Expand Down

0 comments on commit 5893b4e

Please sign in to comment.