Skip to content

Commit

Permalink
Merge pull request #1374 from maykinmedia/issue/2707-profile-notifica…
Browse files Browse the repository at this point in the history
…tions

[#2707] Fix display of notification preferences in profile
  • Loading branch information
alextreme authored Aug 30, 2024
2 parents 6dbabce + 0bd87ab commit 2b1d3a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
29 changes: 19 additions & 10 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
OpenIDConnectDigiDConfig,
OpenIDConnectEHerkenningConfig,
)
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.utils.hash import create_sha256_hash
from open_inwoner.utils.validators import (
CharFieldValidator,
Expand Down Expand Up @@ -376,23 +377,31 @@ def get_interests(self) -> list:
return list(self.selected_categories.values_list("name", flat=True))

def get_active_notifications(self) -> str:
"""
Determine active notifications on the basis of:
- SiteConfiguration settings
- publication status of relevant CMS page
- user preference
"""
from open_inwoner.cms.utils.page_display import (
case_page_is_published,
collaborate_page_is_published,
inbox_page_is_published,
)

config = SiteConfiguration.get_solo()

enabled = []
if (
self.cases_notifications
and self.login_type == LoginTypeChoices.digid
and case_page_is_published()
):
enabled.append(_("cases"))
if self.messages_notifications and inbox_page_is_published():
enabled.append(_("messages"))
if self.plans_notifications and collaborate_page_is_published():
enabled.append(_("plans"))
if config.notifications_cases_enabled:
if self.login_type == LoginTypeChoices.digid and case_page_is_published():
enabled.append(_("cases"))
if config.notifications_messages_enabled:
if self.messages_notifications and inbox_page_is_published():
enabled.append(_("messages"))
if config.notifications_plans_enabled:
if self.plans_notifications and collaborate_page_is_published():
enabled.append(_("plans"))

if not enabled:
return _("You do not have any notifications enabled.")

Expand Down
30 changes: 28 additions & 2 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class ProfileViewTests(WebTest):
def setUp(self):
self.url = reverse("profile:detail")
self.return_url = reverse("logout")
self.user = UserFactory(first_name="Erik", street="MyStreet")
self.user = UserFactory(
first_name="Erik", street="MyStreet", messages_notifications=True
)
self.digid_user = DigidUserFactory()
self.eherkenning_user = eHerkenningUserFactory()

Expand Down Expand Up @@ -133,7 +135,10 @@ def test_show_correct_logout_button_for_login_type_eherkenning(self, mock_solo):

self.assertEqual(logout_link.attr("href"), logout_url)

def test_user_information_profile_page(self):
@patch(
"open_inwoner.cms.utils.page_display.inbox_page_is_published", return_value=True
)
def test_user_information_profile_page(self, m):
response = self.app.get(self.url, user=self.user)

self.assertContains(response, self.user.first_name)
Expand All @@ -148,6 +153,27 @@ def test_user_information_profile_page(self):
# check business profile section not displayed
self.assertNotContains(response, "Bedrijfsgegevens")

# check notification preferences displayed
doc = PQ(response.content)

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

@patch(
"open_inwoner.cms.utils.page_display.inbox_page_is_published", return_value=True
)
def test_admin_disable_options(self, m):
config = SiteConfiguration.get_solo()
config.notifications_messages_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)

def test_get_empty_profile_page(self):
response = self.app.get(self.url, user=self.user)

Expand Down

0 comments on commit 2b1d3a9

Please sign in to comment.