feat: add notification for course updates

This commit is contained in:
Saad Yousaf
2024-02-02 12:41:30 +05:00
committed by Saad Yousaf
parent 7fec28dea4
commit a110fc79d5
9 changed files with 164 additions and 27 deletions

View File

@@ -104,6 +104,7 @@ class EnrollmentAudienceFilter(NotificationAudienceFilterBase):
return CourseEnrollment.objects.filter(
course_id=self.course_key,
mode__in=enrollment_modes,
is_active=True,
).values_list('user_id', flat=True)

View File

@@ -161,7 +161,24 @@ COURSE_NOTIFICATION_TYPES = {
},
'email_template': '',
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE]
}
},
'course_update': {
'notification_app': 'updates',
'name': 'course_update',
'is_core': False,
'info': '',
'web': True,
'email': True,
'push': True,
'non_editable': [],
'content_template': _('<{p}>You have a new course update: '
'<{strong}>{course_update_content}</{strong}></{p}>'),
'content_context': {
'course_update_content': 'Course update',
},
'email_template': '',
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE]
},
}
COURSE_NOTIFICATION_APPS = {
@@ -173,7 +190,15 @@ COURSE_NOTIFICATION_APPS = {
'core_email': True,
'core_push': True,
'non_editable': ['web']
}
},
'updates': {
'enabled': True,
'core_info': _('Notifications for new announcements and updates from the course team.'),
'core_web': True,
'core_email': True,
'core_push': True,
'non_editable': []
},
}

View File

@@ -21,7 +21,7 @@ log = logging.getLogger(__name__)
NOTIFICATION_CHANNELS = ['web', 'push', 'email']
# Update this version when there is a change to any course specific notification type or app.
COURSE_NOTIFICATION_CONFIG_VERSION = 6
COURSE_NOTIFICATION_CONFIG_VERSION = 7
def get_course_notification_preference_config():

View File

@@ -249,13 +249,47 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
'info': 'Notifications for responses and comments on your posts, and the ones youre '
'following, including endorsements to your responses and on your posts.'
},
'new_discussion_post': {'web': False, 'email': False, 'push': False, 'info': ''},
'new_question_post': {'web': False, 'email': False, 'push': False, 'info': ''},
'content_reported': {'web': True, 'email': True, 'push': True, 'info': ''},
'new_discussion_post': {
'web': False,
'email': False,
'push': False,
'info': ''
},
'new_question_post': {
'web': False,
'email': False,
'push': False,
'info': ''
},
'content_reported': {
'web': True,
'email': True,
'push': True,
'info': ''
},
},
'non_editable': {
'core': ['web']
}
},
'updates': {
'enabled': True,
'core_notification_types': [],
'notification_types': {
'course_update': {
'web': True,
'email': True,
'push': True,
'info': ''
},
'core': {
'web': True,
'email': True,
'push': True,
'info': 'Notifications for new announcements and updates from the course team.'
}
},
'non_editable': {}
}
}
}
@@ -293,8 +327,8 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
@mock.patch.dict(COURSE_NOTIFICATION_TYPES, {
**COURSE_NOTIFICATION_TYPES,
**{
'new_question_post': {
'name': 'new_question_post',
'content_reported': {
'name': 'content_reported',
'visible_to': [FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_ADMINISTRATOR]
}
}
@@ -318,7 +352,9 @@ class UserNotificationPreferenceAPITest(ModuleStoreTestCase):
response = self.client.get(self.path)
self.assertEqual(response.status_code, status.HTTP_200_OK)
expected_response = self._expected_api_response()
if not role:
expected_response = remove_notifications_with_visibility_settings(expected_response)
@@ -474,6 +510,27 @@ class UserNotificationChannelPreferenceAPITest(ModuleStoreTestCase):
'non_editable': {
'core': ['web']
}
},
'updates': {
'enabled': True,
'core_notification_types': [
],
'notification_types': {
'course_update': {
'web': True,
'email': True,
'push': True,
'info': ''
},
'core': {
'web': True,
'email': True,
'push': True,
'info': 'Notifications for new announcements and updates from the course team.'
}
},
'non_editable': {}
}
}
}
@@ -742,7 +799,7 @@ class NotificationCountViewSetTestCase(ModuleStoreTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 4)
self.assertEqual(response.data['count_by_app_name'], {
'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1, 'discussion': 0})
'App Name 1': 2, 'App Name 2': 1, 'App Name 3': 1, 'discussion': 0, 'updates': 0})
self.assertEqual(response.data['show_notifications_tray'], show_notifications_tray_enabled)
def test_get_unseen_notifications_count_for_unauthenticated_user(self):
@@ -763,7 +820,7 @@ class NotificationCountViewSetTestCase(ModuleStoreTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 0)
self.assertEqual(response.data['count_by_app_name'], {'discussion': 0})
self.assertEqual(response.data['count_by_app_name'], {'discussion': 0, 'updates': 0})
def test_get_expiry_days_in_count_view(self):
"""

View File

@@ -121,19 +121,19 @@ def filter_out_visible_notifications(
:param user_forum_roles: List of forum roles for the user
:return: Updated user preferences dictionary
"""
for key in user_preferences:
if 'notification_types' in user_preferences[key]:
# Iterate over the types to remove and pop them from the dictionary
for notification_type, is_visible_to in notifications_with_visibility.items():
is_visible = False
for role in is_visible_to:
if role in user_forum_roles:
is_visible = True
break
if is_visible:
continue
discussion_user_preferences = user_preferences.get('discussion', {})
if 'notification_types' in discussion_user_preferences:
# Iterate over the types to remove and pop them from the dictionary
for notification_type, is_visible_to in notifications_with_visibility.items():
is_visible = False
for role in is_visible_to:
if role in user_forum_roles:
is_visible = True
break
if is_visible:
continue
user_preferences[key]['notification_types'].pop(notification_type)
discussion_user_preferences['notification_types'].pop(notification_type)
return user_preferences