Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions openedx/core/djangoapps/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.core.cache import cache
from django.test.utils import override_settings
from django.urls import reverse
from edx_toggles.toggles.testutils import override_waffle_flag
from rest_framework import status
from rest_framework.test import APIClient, APITestCase

Expand All @@ -31,6 +32,7 @@
from xmodule.modulestore.tests.factories import CourseFactory

from ..base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, get_default_values_of_preferences
from ..config.waffle import DISABLE_EMAIL_NOTIFICATIONS
from ..utils import exclude_inaccessible_preferences, get_notification_types_with_visibility_settings

User = get_user_model()
Expand Down Expand Up @@ -742,6 +744,7 @@ def test_if_data_is_correctly_aggregated(self):
data = {
"status": "success",
"show_preferences": True,
"show_email_preferences": True,
"message": "Notification preferences retrieved successfully.",
"data": {
"discussion": {
Expand Down Expand Up @@ -888,6 +891,24 @@ def test_update_preferences(self):
)
self.assertEqual(preference.web, True) # noqa: PT009

def test_show_email_preferences_flag_disabled(self):
"""
Test: show_email_preferences is True when DISABLE_EMAIL_NOTIFICATIONS flag is off.
"""
with override_waffle_flag(DISABLE_EMAIL_NOTIFICATIONS, active=False):
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK) # noqa: PT009
self.assertTrue(response.data['show_email_preferences']) # noqa: PT009

def test_show_email_preferences_flag_enabled(self):
"""
Test: show_email_preferences is False when DISABLE_EMAIL_NOTIFICATIONS flag is on.
"""
with override_waffle_flag(DISABLE_EMAIL_NOTIFICATIONS, active=True):
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK) # noqa: PT009
self.assertFalse(response.data['show_email_preferences']) # noqa: PT009

def test_update_preferences_non_grouped_email(self):
"""
Test case: Update notification preferences for the authenticated user
Expand Down
9 changes: 8 additions & 1 deletion openedx/core/djangoapps/notifications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from common.djangoapps.student.models import CourseAccessRole
from openedx.core.djangoapps.django_comment_common.models import Role
from openedx.core.djangoapps.notifications.config.waffle import DISABLE_NOTIFICATIONS
from openedx.core.djangoapps.notifications.config.waffle import DISABLE_EMAIL_NOTIFICATIONS, DISABLE_NOTIFICATIONS
from openedx.core.djangoapps.notifications.models import NotificationPreference, create_notification_preference
from openedx.core.lib.cache_utils import request_cached

Expand All @@ -17,6 +17,13 @@ def get_show_notifications_tray():
return not DISABLE_NOTIFICATIONS.is_enabled()


def get_show_email_preferences():
"""
Returns whether email notification preferences are enabled via waffle flag
"""
return not DISABLE_EMAIL_NOTIFICATIONS.is_enabled()


def get_list_in_batches(input_list, batch_size):
"""
Divides the list of objects into list of list of objects each of length batch_size.
Expand Down
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .utils import (
create_account_notification_pref_if_not_exists,
exclude_inaccessible_preferences,
get_show_email_preferences,
get_show_notifications_tray,
)

Expand Down Expand Up @@ -305,6 +306,7 @@ def get(self, request):
'status': 'success',
'message': 'Notification preferences retrieved successfully.',
'show_preferences': get_show_notifications_tray(),
'show_email_preferences': get_show_email_preferences(),
'data': structured_preferences
}, status=status.HTTP_200_OK)

Expand Down
Loading