diff --git a/src/open_inwoner/accounts/forms.py b/src/open_inwoner/accounts/forms.py index 4ac024ed00..d7cdbf3de1 100644 --- a/src/open_inwoner/accounts/forms.py +++ b/src/open_inwoner/accounts/forms.py @@ -205,6 +205,9 @@ def __init__(self, user, *args, **kwargs): self.fields["last_name"].required = True # notifications + if not config.enable_notification_channels: + del self.fields["case_notification_channel"] + if ( not user.login_type == LoginTypeChoices.digid or not config.notifications_cases_enabled @@ -331,6 +334,9 @@ def __init__(self, user, *args, **kwargs) -> None: config = SiteConfiguration.get_solo() + if not config.enable_notification_channels: + del self.fields["case_notification_channel"] + if ( not config.notifications_cases_enabled or not case_page_is_published() diff --git a/src/open_inwoner/accounts/templates/accounts/registration_necessary.html b/src/open_inwoner/accounts/templates/accounts/registration_necessary.html index 856b5246d9..49a56e114a 100644 --- a/src/open_inwoner/accounts/templates/accounts/registration_necessary.html +++ b/src/open_inwoner/accounts/templates/accounts/registration_necessary.html @@ -70,16 +70,18 @@

{% trans "Notification preferences" %}

{# Choice of zaken notification channel #} -

{% trans "How do you want to receive notifications about cases?" %}

-
- {% with form.case_notification_channel as field %} - {% for choice in field.field.choices %} -
- {% choice_radio_stacked choice=choice name=field.name data=field.value index=forloop.counter initial=field.form.initial icon_class=choice.1|get_icon_class %} -
- {% endfor %} - {% endwith %} -
+ {% if form.case_notification_channel %} +

{% trans "How do you want to receive notifications about cases?" %}

+
+ {% with form.case_notification_channel as field %} + {% for choice in field.field.choices %} +
+ {% choice_radio_stacked choice=choice name=field.name data=field.value index=forloop.counter initial=field.form.initial icon_class=choice.1|get_icon_class %} +
+ {% endfor %} + {% endwith %} +
+ {% endif %} {% form_actions primary_icon='east' primary_text="Voltooi registratie" fullwidth=True %} diff --git a/src/open_inwoner/accounts/tests/test_auth.py b/src/open_inwoner/accounts/tests/test_auth.py index 43f3f6619c..5e1dec18d7 100644 --- a/src/open_inwoner/accounts/tests/test_auth.py +++ b/src/open_inwoner/accounts/tests/test_auth.py @@ -250,6 +250,10 @@ def test_notification_settings_with_cms_page_published(self, m): MockAPIReadPatchData.setUpServices() mock_api_data = MockAPIReadPatchData().install_mocks(m) + config = SiteConfiguration.get_solo() + config.enable_notification_channels = True + config.save() + # reset noise from signals m.reset_mock() self.clearTimelineLogs() @@ -1494,6 +1498,10 @@ def test_any_page_for_digid_user_redirect_to_necessary_fields(self): self.assertRedirects(response, redirect.url) def test_submit_without_invite(self): + config = SiteConfiguration.get_solo() + config.enable_notification_channels = True + config.save() + user = UserFactory( first_name="", last_name="", diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index c0d6d1e075..62cc5e5a5d 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -16,6 +16,7 @@ from open_inwoner.accounts.choices import NotificationChannelChoice, StatusChoices from open_inwoner.cms.profile.cms_appconfig import ProfileConfig +from open_inwoner.configurations.models import SiteConfiguration from open_inwoner.haalcentraal.tests.mixins import HaalCentraalMixin from open_inwoner.laposta.models import LapostaConfig from open_inwoner.laposta.tests.factories import LapostaListFactory, MemberFactory @@ -1011,6 +1012,10 @@ def test_notification_channel_edit(self, mock_page_display, m): MockAPIReadPatchData.setUpServices() data = MockAPIReadPatchData().install_mocks(m) + config = SiteConfiguration.get_solo() + config.enable_notification_channels = True + config.save() + # reset noise from signals m.reset_mock() self.clearTimelineLogs() diff --git a/src/open_inwoner/accounts/views/profile.py b/src/open_inwoner/accounts/views/profile.py index 494cf19142..bc12ab555c 100644 --- a/src/open_inwoner/accounts/views/profile.py +++ b/src/open_inwoner/accounts/views/profile.py @@ -25,6 +25,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 @@ -341,6 +342,10 @@ def form_valid(self, form): return HttpResponseRedirect(self.get_success_url()) def update_klant(self, user_form_data: dict): + config = SiteConfiguration.get_solo() + if not config.enable_notification_channels: + return + if notification_channel := user_form_data.get("case_notification_channel"): self.patch_klant( update_data={ diff --git a/src/open_inwoner/accounts/views/registration.py b/src/open_inwoner/accounts/views/registration.py index cd0f2846e5..c79d0eda90 100644 --- a/src/open_inwoner/accounts/views/registration.py +++ b/src/open_inwoner/accounts/views/registration.py @@ -17,6 +17,7 @@ ) from open_inwoner.accounts.choices import NotificationChannelChoice from open_inwoner.accounts.views.mixins import KlantenAPIMixin +from open_inwoner.configurations.models import SiteConfiguration from open_inwoner.utils.hash import generate_email_from_string from open_inwoner.utils.views import CommonPageMixin, LogMixin @@ -193,6 +194,10 @@ def get_initial(self): return initial def update_klant(self, user_form_data: dict): + config = SiteConfiguration.get_solo() + if not config.enable_notification_channels: + return + if notification_channel := user_form_data.get("case_notification_channel"): self.patch_klant( update_data={ diff --git a/src/open_inwoner/configurations/admin.py b/src/open_inwoner/configurations/admin.py index 0c94469aa1..1a587dbf0f 100644 --- a/src/open_inwoner/configurations/admin.py +++ b/src/open_inwoner/configurations/admin.py @@ -229,7 +229,7 @@ class SiteConfigurationAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin): }, ), ( - _("Emails"), + _("Notifications"), { "fields": ( "notifications_messages_enabled", diff --git a/src/open_inwoner/configurations/migrations/0070_siteconfiguration_enable_notification_channels.py b/src/open_inwoner/configurations/migrations/0070_siteconfiguration_enable_notification_channels.py new file mode 100644 index 0000000000..bd0662d75a --- /dev/null +++ b/src/open_inwoner/configurations/migrations/0070_siteconfiguration_enable_notification_channels.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.15 on 2024-08-14 13:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("configurations", "0069_merge_20240724_0945"), + ] + + operations = [ + migrations.AddField( + model_name="siteconfiguration", + name="enable_notification_channels", + field=models.BooleanField( + default=False, + help_text="Give users the option to choose how they want to receive notifications (digital and post or digital only)", + verbose_name="Enable choice of notification channel", + ), + ), + ] diff --git a/src/open_inwoner/configurations/models.py b/src/open_inwoner/configurations/models.py index b7606f6f0c..49db01dcd8 100644 --- a/src/open_inwoner/configurations/models.py +++ b/src/open_inwoner/configurations/models.py @@ -359,6 +359,14 @@ class SiteConfiguration(SingletonModel): ) # email notifications + enable_notification_channels = models.BooleanField( + verbose_name=_("Enable choice of notification channel"), + default=False, + help_text=_( + "Give users the option to choose how they want to receive notifications " + "(digital and post or digital only)" + ), + ) notifications_messages_enabled = models.BooleanField( verbose_name=_("User notifications for messages"), default=True, diff --git a/src/open_inwoner/templates/pages/profile/notifications.html b/src/open_inwoner/templates/pages/profile/notifications.html index ed320d987f..f6fb18f234 100644 --- a/src/open_inwoner/templates/pages/profile/notifications.html +++ b/src/open_inwoner/templates/pages/profile/notifications.html @@ -50,16 +50,18 @@

{% trans "Ontvang berichten over" %}

{# Choice of zaken notification channel #} -

{% trans "How do you want to receive notifications about cases?" %}

-
- {% with form.case_notification_channel as field %} - {% for choice in field.field.choices %} -
- {% choice_radio_stacked choice=choice name=field.name data=field.value index=forloop.counter initial=field.form.initial icon_class=choice.1|get_icon_class %} -
- {% endfor %} - {% endwith %} -
+ {% if form.case_notification_channel %} +

{% trans "How do you want to receive notifications about cases?" %}

+
+ {% with form.case_notification_channel as field %} + {% for choice in field.field.choices %} +
+ {% choice_radio_stacked choice=choice name=field.name data=field.value index=forloop.counter initial=field.form.initial icon_class=choice.1|get_icon_class %} +
+ {% endfor %} + {% endwith %} +
+ {% endif %}
{% button text=_("Sla wijzigingen op") primary=True type="submit" form_id="change-notifications" %}