Skip to content

Commit

Permalink
Merge pull request #1360 from maykinmedia/issue/2688-notification-tem…
Browse files Browse the repository at this point in the history
…plates

[#2688] Improve template for user notifications
  • Loading branch information
alextreme authored Aug 22, 2024
2 parents 69a2d27 + b2b5975 commit 24881d7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
14 changes: 9 additions & 5 deletions src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,27 @@ class Meta:
def __init__(self, user, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

config = SiteConfiguration.get_solo()
siteconfig = SiteConfiguration.get_solo()
self.any_notifications_enabled = siteconfig.any_notifications_enabled

if not config.enable_notification_channel_choice:
if not siteconfig.enable_notification_channel_choice:
del self.fields["case_notification_channel"]

if (
not config.notifications_cases_enabled
not siteconfig.notifications_cases_enabled
or not case_page_is_published()
or not user.login_type == LoginTypeChoices.digid
):
del self.fields["cases_notifications"]

if not config.notifications_messages_enabled or not inbox_page_is_published():
if (
not siteconfig.notifications_messages_enabled
or not inbox_page_is_published()
):
del self.fields["messages_notifications"]

if (
not config.notifications_plans_enabled
not siteconfig.notifications_plans_enabled
or not collaborate_page_is_published()
):
del self.fields["plans_notifications"]
Expand Down
4 changes: 4 additions & 0 deletions src/open_inwoner/accounts/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def test_categories_modification_is_logged(self):

@patch("open_inwoner.cms.utils.page_display._is_published", return_value=True)
def test_user_notifications_update_is_logged(self, mock_cms_page_display):
config = SiteConfiguration.get_solo()
config.notifications_messages_enabled = True
config.save()

form = self.app.get(reverse("profile:notifications"), user=self.user).forms[
"change-notifications"
]
Expand Down
15 changes: 14 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,14 @@ def test_preselected_values(self):
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
@patch("open_inwoner.cms.utils.page_display._is_published", return_value=True)
class EditNotificationsTests(AssertTimelineLogMixin, WebTest):
@classmethod
def setUpTestData(cls):
config = SiteConfiguration.get_solo()
config.notifications_messages_enabled = True
config.notifications_cases_enabled = True
config.notifications_plans_enabled = True
config.save()

def setUp(self):
self.url = reverse("profile:notifications")
self.user = UserFactory()
Expand Down Expand Up @@ -1065,8 +1073,13 @@ def setUpTestData(cls):
cls.url = reverse("profile:notifications")
cls.user = UserFactory()

config = SiteConfiguration.get_solo()
config.notifications_messages_enabled = True
config.notifications_cases_enabled = True
config.notifications_plans_enabled = True
config.save()

def test_inbox_notifications_display(self):
# inbox page not created
response = self.app.get(self.url, user=self.user)
form = response.forms["change-notifications"]

Expand Down
56 changes: 30 additions & 26 deletions src/open_inwoner/templates/pages/profile/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ <h1 class="utrecht-heading-1" id="title">
<form method="POST" id="change-notifications" action="{% url 'profile:notifications' %}" class="form" novalidate>
{% csrf_token %}

{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">
{% if form.any_notifications_enabled %}
{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">

<h3 class="utrecht-heading-3">{% trans "Ontvang berichten over" %}</h3>
<p class="utrecht-paragraph">{% trans "Kies voor welk onderwerp je meldingen wilt ontvangen" %}</p>
<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">
{% checkbox form.cases_notifications %}
</div>
</li>
{% endif %}
{% if form.cases_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.cases_notifications %}
</div>
</li>
{% endif %}

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

{% if form.plans_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.plans_notifications %}</div>
</li>
{% endif %}
</ul>
{# End of multiple checkbox fields #}
{% if form.plans_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.plans_notifications %}</div>
</li>
{% endif %}
</ul>
{# End of multiple checkbox fields #}
{% endif %}

<div class="choice-list choice-list-multiple">
{# Info on notifications that cannot be disabled #}
Expand All @@ -64,7 +66,9 @@ <h3 class="utrecht-heading-4">{% trans "How do you want to receive notifications
{% endif %}

<div class="form__actions form__actions--fullwidth">
{% button text=_("Sla wijzigingen op") primary=True type="submit" form_id="change-notifications" %}
{% if form.any_notifications_enabled or form.case_notification_channel %}
{% button text=_("Sla wijzigingen op") primary=True type="submit" form_id="change-notifications" %}
{% endif %}
{% button href="profile:detail" icon="west" text=_("Terug naar Mijn profiel") icon_outlined=True transparent=True %}
</div>
</form>
Expand Down

0 comments on commit 24881d7

Please sign in to comment.