diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index b9f61b14ef..baeb23e462 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -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, @@ -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.") diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index f29630d777..f4d9c41e95 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -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() @@ -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) @@ -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)