fix: course wide preferences are visible when patch call is sent (#33726)

This commit is contained in:
Muhammad Adeel Tajamul
2023-11-16 14:41:28 +05:00
committed by GitHub
parent 94658f5890
commit 1806b290b8
2 changed files with 14 additions and 5 deletions

View File

@@ -210,11 +210,13 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
enrollment=enrollment_data
)
def _expected_api_response(self):
def _expected_api_response(self, course=None):
"""
Helper method to return expected API response.
"""
return {
if course is None:
course = self.course
response = {
'id': 1,
'course_name': 'course-v1:testorg+testcourse+testrun Course',
'course_id': 'course-v1:testorg+testcourse+testrun',
@@ -245,6 +247,12 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
}
}
}
if not ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course.id):
app_prefs = response['notification_preference_config']['discussion']
notification_types = app_prefs['notification_types']
for notification_type in ['new_discussion_post', 'new_question_post']:
notification_types.pop(notification_type)
return response
def test_get_user_notification_preference_without_login(self):
"""
@@ -254,13 +262,13 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
@mock.patch("eventtracking.tracker.emit")
@override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True)
def test_get_user_notification_preference(self, mock_emit):
"""
Test get user notification preference.
"""
self.client.login(username=self.user.username, password=self.TEST_PASSWORD)
with override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True):
response = self.client.get(self.path)
response = self.client.get(self.path)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, self._expected_api_response())
event_name, event_data = mock_emit.call_args[0]

View File

@@ -219,7 +219,8 @@ class UserNotificationPreferenceView(APIView):
updated_notification_preferences = preference_update.save()
notification_preference_update_event(request.user, course_id, preference_update.validated_data)
serializer = UserCourseNotificationPreferenceSerializer(updated_notification_preferences)
return Response(serializer.data, status=status.HTTP_200_OK)
preferences = filter_course_wide_preferences(course_id, serializer.data)
return Response(preferences, status=status.HTTP_200_OK)
@allow_any_authenticated_user()