Skip to content

Commit

Permalink
[#2638] Update profile with choice of communication channel for case …
Browse files Browse the repository at this point in the history
…notifications

    - user can edit the communication channel (post + digital or digital
      only) for notifications about cases in the communication section
      of their profile
  • Loading branch information
pi-sigma committed Aug 7, 2024
1 parent ae9b6d7 commit 9664b3d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class Meta:
"cases_notifications",
"messages_notifications",
"plans_notifications",
"cases_notifications_digital_only",
)

def __init__(self, user, *args, **kwargs):
Expand All @@ -210,6 +211,7 @@ def __init__(self, user, *args, **kwargs):
or not case_page_is_published()
):
del self.fields["cases_notifications"]
del self.fields["cases_notifications_digital_only"]
if not config.notifications_messages_enabled or not inbox_page_is_published():
del self.fields["messages_notifications"]
if (
Expand Down Expand Up @@ -322,6 +324,7 @@ class Meta:
"cases_notifications",
"messages_notifications",
"plans_notifications",
"cases_notifications_digital_only",
)

def __init__(self, user, *args, **kwargs) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-08-06 07:41
# Generated by Django 4.2.11 on 2024-08-07 08:33

from django.db import migrations, models

Expand All @@ -15,8 +15,8 @@ class Migration(migrations.Migration):
name="cases_notifications_digital_only",
field=models.BooleanField(
blank=True,
default=False,
help_text="Receive notifications about cases only digitally (email)",
null=True,
verbose_name="Receive case notifications only digitally",
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def has_verified_email(self):
)
cases_notifications_digital_only = models.BooleanField(
verbose_name=_("Receive case notifications only digitally"),
null=True,
default=False,
blank=True,
help_text=_("Receive notifications about cases only digitally (email)"),
)
Expand Down
31 changes: 31 additions & 0 deletions src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
benefits_page_is_published,
inbox_page_is_published,
)
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.haalcentraal.utils import fetch_brp
from open_inwoner.laposta.forms import NewsletterSubscriptionForm
from open_inwoner.laposta.models import LapostaConfig
Expand Down Expand Up @@ -342,10 +343,40 @@ def get_form_kwargs(self):

def form_valid(self, form):
form.save()

self.update_klant_api({k: form.cleaned_data[k] for k in form.changed_data})

messages.success(self.request, _("Uw wijzigingen zijn opgeslagen"))
self.log_change(self.object, _("users notifications were modified"))
return HttpResponseRedirect(self.get_success_url())

def update_klant_api(self, user_form_data: dict):
user: User = self.request.user
if not user.bsn and not user.kvk:
return

field_mapping = {
"toestemmingZaakNotificatiesAlleenDigitaal": "cases_notifications_digital_only",
}
update_data = {
api_name: user_form_data.get(local_name)
for api_name, local_name in field_mapping.items()
}
if update_data:
if client := build_klanten_client():
klant = client.retrieve_klant(**get_fetch_parameters(self.request))

if klant:
self.log_system_action(
"retrieved klant for user", user=self.request.user
)
client.partial_update_klant(klant, update_data)
if klant:
self.log_system_action(
f"patched klant from user profile edit with fields: {', '.join(sorted(update_data.keys()))}",
user=self.request.user,
)


class UserAppointmentsView(
LogMixin,
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/openklant/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Klant(ZGWModel):
achternaam: str = ""
telefoonnummer: str = ""
emailadres: str = ""
toestemmingZaakNotificatiesAlleenDigitaal: bool = False

def get_name_display(self):
return " ".join(
Expand Down
33 changes: 20 additions & 13 deletions src/open_inwoner/templates/pages/profile/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
{% render_grid %}
{% render_column start=5 span=5 %}
<h1 class="utrecht-heading-1" id="title">
{% trans "Ontvang berichten over" %}
{% trans "Notificatie voorkeuren" %}
</h1>
<p class="utrecht-paragraph">
{% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %}
</p>

<form method="POST" id="change-notifications" action="{% url 'profile:notifications' %}" class="form" novalidate>
{% csrf_token %}

<h3 class="utrecht-heading-3">Notificatie voorkeuren</h3>
<h3 class="utrecht-heading-3">{% trans "Method for case notifications" %}</h3>
<p class="utrecht-paragraph">{% trans "Choose the method of communication for notifications about cases" %}</p>

{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">

{% if form.cases_notifications_digital_only %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.cases_notifications_digital_only %}
</div>
</li>
{% endif %}

<h3 class="utrecht-heading-3">{% trans "Ontvang berichten over" %}</h3>
<p class="utrecht-paragraph">{% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %}</p>

{% if form.cases_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
Expand All @@ -43,15 +52,13 @@ <h3 class="utrecht-heading-3">Notificatie voorkeuren</h3>
</ul>
{# End of multiple checkbox fields #}

{% if siteconfig.notifications_cases_enabled %}
<div class="choice-list choice-list-multiple">
{# Info on notifications that cannot be disabled #}
<div class="choice-list__information">
<p class="choice-list-multiple__heading-4">{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}</p>
<p class="choice-list__p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>
<div class="choice-list choice-list-multiple">
{# Info on notifications that cannot be disabled #}
<div class="choice-list__information">
<p class="choice-list-multiple__heading-4">{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}</p>
<p class="choice-list__p">{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}</p>
</div>
{% endif %}
</div>

<div class="form__actions form__actions--fullwidth">
{% button text=_("Sla wijzigingen op") primary=True type="submit" form_id="change-notifications" %}
Expand Down

0 comments on commit 9664b3d

Please sign in to comment.