Skip to content

Commit

Permalink
fix: added preference visibility to reported notification (openedx#34188
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AhtishamShahid authored Feb 15, 2024
1 parent 3919c45 commit 63d1848
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/notifications/base_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.translation import gettext_lazy as _

from .utils import find_app_in_normalized_apps, find_pref_in_normalized_prefs
from ..django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA

FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE = 'filter_audit_expired_users_with_no_role'

Expand Down Expand Up @@ -131,6 +132,7 @@
'replier_name': 'replier name',
},
'email_template': '',
'visible_to': [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]
},
'response_endorsed_on_thread': {
'notification_app': 'discussion',
Expand Down
24 changes: 20 additions & 4 deletions openedx/core/djangoapps/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from xmodule.modulestore.tests.factories import CourseFactory

from ..base_notification import COURSE_NOTIFICATION_APPS, COURSE_NOTIFICATION_TYPES, NotificationAppManager
from ..utils import get_notification_types_with_visibility_settings


@ddt.ddt
Expand Down Expand Up @@ -281,7 +282,9 @@ def test_get_user_notification_preference(self, mock_emit):
self.client.login(username=self.user.username, password=self.TEST_PASSWORD)
response = self.client.get(self.path)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, self._expected_api_response())
expected_response = self._expected_api_response()
expected_response = remove_notifications_with_visibility_settings(expected_response)
self.assertEqual(response.data, expected_response)
event_name, event_data = mock_emit.call_args[0]
self.assertEqual(event_name, 'edx.notifications.preferences.viewed')

Expand Down Expand Up @@ -317,9 +320,8 @@ def test_get_user_notification_preference_with_visibility_settings(self, role, m
self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_response = self._expected_api_response()
if not role:
expected_response['notification_preference_config']['discussion']['notification_types'].pop(
'new_question_post'
)
expected_response = remove_notifications_with_visibility_settings(expected_response)

self.assertEqual(response.data, expected_response)
event_name, event_data = mock_emit.call_args[0]
self.assertEqual(event_name, 'edx.notifications.preferences.viewed')
Expand Down Expand Up @@ -360,11 +362,13 @@ def test_patch_user_notification_preference(

if update_type == 'app_update':
expected_data = self._expected_api_response()
expected_data = remove_notifications_with_visibility_settings(expected_data)
expected_data['notification_preference_config'][notification_app]['enabled'] = value
self.assertEqual(response.data, expected_data)

elif update_type == 'type_update':
expected_data = self._expected_api_response()
expected_data = remove_notifications_with_visibility_settings(expected_data)
expected_data['notification_preference_config'][notification_app][
'notification_types'][notification_type][notification_channel] = value
self.assertEqual(response.data, expected_data)
Expand Down Expand Up @@ -914,3 +918,15 @@ def test_mark_notification_read_without_app_name_and_notification_id(self):

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {'error': 'Invalid app_name or notification_id.'})


def remove_notifications_with_visibility_settings(expected_response):
"""
Remove notifications with visibility settings from the expected response.
"""
not_visible = get_notification_types_with_visibility_settings()
for notification_type, visibility_settings in not_visible.items():
expected_response['notification_preference_config']['discussion']['notification_types'].pop(
notification_type
)
return expected_response

0 comments on commit 63d1848

Please sign in to comment.