Skip to content

Commit

Permalink
[#2638] Make choice of notification channel optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Aug 14, 2024
1 parent 15c3c42 commit 3a591fb
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ <h3 class="utrecht-heading-3">{% trans "Notification preferences" %}</h3>
</div>

{# Choice of zaken notification channel #}
<h3 class="utrecht-heading-4">{% trans "How do you want to receive notifications about cases?" %}</h3>
<div class="radios radios--spaced">
{% with form.case_notification_channel as field %}
{% for choice in field.field.choices %}
<div class="radio-group radio-group--stacked choice-list-multiple__item">
{% 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 %}
</div>
{% endfor %}
{% endwith %}
</div>
{% if form.case_notification_channel %}
<h3 class="utrecht-heading-4">{% trans "How do you want to receive notifications about cases?" %}</h3>
<div class="radios radios--spaced">
{% with form.case_notification_channel as field %}
{% for choice in field.field.choices %}
<div class="radio-group radio-group--stacked choice-list-multiple__item">
{% 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 %}
</div>
{% endfor %}
{% endwith %}
</div>
{% endif %}

{% form_actions primary_icon='east' primary_text="Voltooi registratie" fullwidth=True %}
</form>
Expand Down
8 changes: 8 additions & 0 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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="",
Expand Down
5 changes: 5 additions & 0 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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={
Expand Down
5 changes: 5 additions & 0 deletions src/open_inwoner/accounts/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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={
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/configurations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class SiteConfigurationAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
},
),
(
_("Emails"),
_("Notifications"),
{
"fields": (
"notifications_messages_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
8 changes: 8 additions & 0 deletions src/open_inwoner/configurations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions src/open_inwoner/templates/pages/profile/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ <h3 class="utrecht-heading-3">{% trans "Ontvang berichten over" %}</h3>
</div>

{# Choice of zaken notification channel #}
<h3 class="utrecht-heading-4">{% trans "How do you want to receive notifications about cases?" %}</h3>
<div class="radios radios--spaced">
{% with form.case_notification_channel as field %}
{% for choice in field.field.choices %}
<div class="radio-group radio-group--stacked choice-list-multiple__item">
{% 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 %}
</div>
{% endfor %}
{% endwith %}
</div>
{% if form.case_notification_channel %}
<h3 class="utrecht-heading-4">{% trans "How do you want to receive notifications about cases?" %}</h3>
<div class="radios radios--spaced">
{% with form.case_notification_channel as field %}
{% for choice in field.field.choices %}
<div class="radio-group radio-group--stacked choice-list-multiple__item">
{% 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 %}
</div>
{% endfor %}
{% endwith %}
</div>
{% endif %}

<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 3a591fb

Please sign in to comment.