diff --git a/src/open_inwoner/accounts/forms.py b/src/open_inwoner/accounts/forms.py index 8a619d9d6f..650d3e9eed 100644 --- a/src/open_inwoner/accounts/forms.py +++ b/src/open_inwoner/accounts/forms.py @@ -192,6 +192,7 @@ class Meta: "cases_notifications", "messages_notifications", "plans_notifications", + "cases_notifications_digital_only", ) def __init__(self, user, *args, **kwargs): @@ -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 ( @@ -322,6 +324,7 @@ class Meta: "cases_notifications", "messages_notifications", "plans_notifications", + "cases_notifications_digital_only", ) def __init__(self, user, *args, **kwargs) -> None: diff --git a/src/open_inwoner/accounts/migrations/0076_user_cases_notifications_digital_only.py b/src/open_inwoner/accounts/migrations/0076_user_cases_notifications_digital_only.py index e984edf798..2973a95938 100644 --- a/src/open_inwoner/accounts/migrations/0076_user_cases_notifications_digital_only.py +++ b/src/open_inwoner/accounts/migrations/0076_user_cases_notifications_digital_only.py @@ -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 @@ -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", ), ), diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index 4e652dd2e8..f72b322250 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -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)"), ) diff --git a/src/open_inwoner/accounts/views/profile.py b/src/open_inwoner/accounts/views/profile.py index 7004540f6d..0f6935ade6 100644 --- a/src/open_inwoner/accounts/views/profile.py +++ b/src/open_inwoner/accounts/views/profile.py @@ -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 @@ -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, diff --git a/src/open_inwoner/openklant/api_models.py b/src/open_inwoner/openklant/api_models.py index 1b2da63eb0..33161dc39f 100644 --- a/src/open_inwoner/openklant/api_models.py +++ b/src/open_inwoner/openklant/api_models.py @@ -31,6 +31,7 @@ class Klant(ZGWModel): achternaam: str = "" telefoonnummer: str = "" emailadres: str = "" + toestemmingZaakNotificatiesAlleenDigitaal: bool = False def get_name_display(self): return " ".join( diff --git a/src/open_inwoner/templates/pages/profile/notifications.html b/src/open_inwoner/templates/pages/profile/notifications.html index 5f06003e7c..be41c2e664 100644 --- a/src/open_inwoner/templates/pages/profile/notifications.html +++ b/src/open_inwoner/templates/pages/profile/notifications.html @@ -5,20 +5,29 @@ {% render_grid %} {% render_column start=5 span=5 %}

- {% trans "Ontvang berichten over" %} + {% trans "Notificatie voorkeuren" %}

-

- {% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %} -

{% csrf_token %} -

Notificatie voorkeuren

+

{% trans "Method for case notifications" %}

+

{% trans "Choose the method of communication for notifications about cases" %}

{# Start of multiple checkbox fields #} {# End of multiple checkbox fields #} - {% if siteconfig.notifications_cases_enabled %} -
- {# Info on notifications that cannot be disabled #} -
-

{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}

-

{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}

-
+
+ {# Info on notifications that cannot be disabled #} +
+

{% icon icon="check" outlined=True %} {% trans "Zaaknotificaties - actie is nodig" %}

+

{% trans "E-mailnotificaties wanneer er actie nodig is voor een zaak (kan niet uitgeschakeld worden)" %}

- {% endif %} +
{% button text=_("Sla wijzigingen op") primary=True type="submit" form_id="change-notifications" %}