Skip to content

Commit

Permalink
[#2744] Hide notifications from profile + registration if disabled vi…
Browse files Browse the repository at this point in the history
…a admin
  • Loading branch information
pi-sigma committed Sep 12, 2024
1 parent af6f72b commit 80989e9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1 class="utrecht-heading-1">{% trans "Registratie voltooien" %}</h1><br>


{% if config.any_notifications_enabled %}
<h3 class="utrecht-heading-3">{% trans "Notification preferences" %}</h3>
<h3 class="utrecht-heading-3">{% trans "Notification preferences" %}</h3>

{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">
Expand All @@ -49,14 +49,16 @@ <h3 class="utrecht-heading-3">{% trans "Notification preferences" %}</h3>
{% if form.messages_notifications %}
<li class="choice-list-multiple__item">
<div class="choice-list-multiple__content">
{% checkbox form.messages_notifications %}</div>
{% 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>
{% checkbox form.plans_notifications %}
</div>
</li>
{% endif %}
</ul>
Expand All @@ -83,8 +85,7 @@ <h3 class="utrecht-heading-3">{% trans "Notification preferences" %}</h3>
{% endif %}
{% endif %}

<div class="choice-list__information--bottom-border">
</div>
<div class="choice-list__information--bottom-border"></div>

{% form_actions primary_icon='east' primary_text="Voltooi registratie" fullwidth=True %}
</form>
Expand Down
31 changes: 21 additions & 10 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,17 @@ def test_user_information_profile_page(self, m):
)
def test_admin_disable_options(self, m):
config = SiteConfiguration.get_solo()
config.notifications_actions_enabled = False
config.notifications_cases_enabled = False
config.notifications_messages_enabled = False
config.notifications_plans_enabled = False
config.save()

response = self.app.get(self.url, user=self.user)

doc = PQ(response.content)

notifications_text = doc.find("#profile-notifications")[0].text_content()
self.assertNotIn("Mijn Berichten", notifications_text)
self.assertEqual(doc.find("#profile-notifications"), [])

def test_get_empty_profile_page(self):
response = self.app.get(self.url, user=self.user)
Expand Down Expand Up @@ -978,15 +980,13 @@ 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.config = SiteConfiguration.get_solo()
self.config.notifications_messages_enabled = True
self.config.notifications_cases_enabled = True
self.config.notifications_plans_enabled = True
self.config.save()

self.url = reverse("profile:notifications")
self.user = UserFactory()

Expand All @@ -996,6 +996,17 @@ def test_login_required(self, mock_page_display):

self.assertRedirects(response, f"{login_url}?next={self.url}")

def test_notifications_disabled(self, mock_page_display):
self.config.notifications_actions_enabled = False
self.config.notifications_cases_enabled = False
self.config.notifications_messages_enabled = False
self.config.notifications_plans_enabled = False
self.config.save()

response = self.app.get(self.url, user=self.user)

self.assertRedirects(response, reverse("profile:detail"))

def test_default_values_for_regular_user(self, mock_page_display):
response = self.app.get(self.url, user=self.user)
form = response.forms["change-notifications"]
Expand Down
6 changes: 6 additions & 0 deletions src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ def crumbs(self):
(_("Ontvang berichten over"), reverse("profile:notifications")),
]

def get(self, *args, **kwargs):
config = SiteConfiguration.get_solo()
if not config.any_notifications_enabled:
return HttpResponseRedirect(reverse("profile:detail"))
return super().get(*args, **kwargs)

def get_object(self):
return self.request.user

Expand Down
42 changes: 22 additions & 20 deletions src/open_inwoner/templates/pages/profile/me.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,30 @@ <h2 class="utrecht-heading-2 " id="personal-overview">{% trans "Persoonlijke geg
{% endif %}

{# Notifications #}
<section class="tabled tabled--flexible profile-section profile-section--bordered profile-section__notifications" id="profile-notifications">
<div class="tabled__section">
<header class="oip-header-group title">
<h2 class="utrecht-heading-2" id="notifications">{% trans "Voorkeuren voor meldingen" %}
</h2>
<div class="tabled__item--force-right tabled__item--mobile-big">
{% button href="profile:notifications" text=_("Bewerk") icon="edit" transparent=True icon_outlined=True %}
</div>
</header>
{% if siteconfig.any_notifications_enabled %}
<section class="tabled tabled--flexible profile-section profile-section--bordered profile-section__notifications" id="profile-notifications">
<div class="tabled__section">
<header class="oip-header-group title">
<h2 class="utrecht-heading-2" id="notifications">{% trans "Voorkeuren voor meldingen" %}
</h2>
<div class="tabled__item--force-right tabled__item--mobile-big">
{% button href="profile:notifications" text=_("Bewerk") icon="edit" transparent=True icon_outlined=True %}
</div>
</header>

</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Communicatiekanaal" %}</div>
<div class="tabled__item tabled__value">E-mail</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Ontvang notificaties over" %}</div>
<div class="tabled__item tabled__value">
<div class="item__option">{{ user.get_active_notifications }}</div>
</div>
</div>
</section>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Communicatiekanaal" %}</div>
<div class="tabled__item tabled__value">E-mail</div>
</div>
<div class="tabled__row tabled__row--blank">
<div class="tabled__item tabled__key">{% trans "Ontvang notificaties over" %}</div>
<div class="tabled__item tabled__value">
<div class="item__option">{{ user.get_active_notifications }}</div>
</div>
</div>
</section>
{% endif %}

{# Newsletters #}
{% if view.config.newsletters and form.fields.newsletters.choices %}
Expand Down
52 changes: 25 additions & 27 deletions src/open_inwoner/templates/pages/profile/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@ <h1 class="utrecht-heading-1" id="title">
<form method="POST" id="change-notifications" action="{% url 'profile:notifications' %}" class="form form__choice-list" novalidate>
{% csrf_token %}

{% if form.any_notifications_enabled %}
{# Start of multiple checkbox fields #}
<ul class="choice-list choice-list-multiple">
{# 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 #}
{% 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 notifications_cases_enabled %}
<div class="choice-list choice-list-multiple">
Expand Down

0 comments on commit 80989e9

Please sign in to comment.