feat: add grouping for new response notification (#37674)
This commit is contained in:
@@ -95,6 +95,8 @@ COURSE_NOTIFICATION_TYPES = {
|
||||
'is_core': True,
|
||||
'content_template': _('<{p}><{strong}>{replier_name}</{strong}> responded to your '
|
||||
'post <{strong}>{post_title}</{strong}></{p}>'),
|
||||
'grouped_content_template': _('<{p}><{strong}>{replier_name}</{strong}> and others have responded to your post '
|
||||
'<{strong}>{post_title}</{strong}></{p}>'),
|
||||
'content_context': {
|
||||
'post_title': 'Post title',
|
||||
'replier_name': 'replier name',
|
||||
@@ -148,6 +150,8 @@ COURSE_NOTIFICATION_TYPES = {
|
||||
'non_editable': [],
|
||||
'content_template': _('<{p}><{strong}>{replier_name}</{strong}> responded to a post you’re following: '
|
||||
'<{strong}>{post_title}</{strong}></{p}>'),
|
||||
'grouped_content_template': _('<{p}><{strong}>{replier_name}</{strong}> and others responded to a post you’re '
|
||||
'following: <{strong}>{post_title}</{strong}></{p}>'),
|
||||
'content_context': {
|
||||
'post_title': 'Post title',
|
||||
'replier_name': 'replier name',
|
||||
|
||||
@@ -106,6 +106,38 @@ class OraStaffGrouper(BaseNotificationGrouper):
|
||||
return content_context
|
||||
|
||||
|
||||
@NotificationRegistry.register('new_response')
|
||||
class NewResponseGrouper(BaseNotificationGrouper):
|
||||
"""
|
||||
Grouper for new response on post.
|
||||
"""
|
||||
|
||||
def group(self, new_notification, old_notification):
|
||||
"""
|
||||
Groups new ora staff notifications based on the xblock ID.
|
||||
"""
|
||||
content_context = old_notification.content_context
|
||||
content_context.setdefault("grouped", True)
|
||||
content_context["replier_name"] = new_notification.content_context["replier_name"]
|
||||
return content_context
|
||||
|
||||
|
||||
@NotificationRegistry.register('response_on_followed_post')
|
||||
class NewResponseOnFollowedPostGrouper(BaseNotificationGrouper):
|
||||
"""
|
||||
Grouper for new response on post.
|
||||
"""
|
||||
|
||||
def group(self, new_notification, old_notification):
|
||||
"""
|
||||
Groups new ora staff notifications based on the xblock ID.
|
||||
"""
|
||||
content_context = old_notification.content_context
|
||||
content_context.setdefault("grouped", True)
|
||||
content_context["replier_name"] = new_notification.content_context["replier_name"]
|
||||
return content_context
|
||||
|
||||
|
||||
def group_user_notifications(new_notification: Notification, old_notification: Notification):
|
||||
"""
|
||||
Groups user notification based on notification type and group_id
|
||||
|
||||
@@ -13,7 +13,7 @@ from openedx.core.djangoapps.notifications.grouping_notifications import (
|
||||
BaseNotificationGrouper,
|
||||
NotificationRegistry,
|
||||
group_user_notifications,
|
||||
get_user_existing_notifications, NewPostGrouper
|
||||
get_user_existing_notifications, NewPostGrouper, NewResponseGrouper, NewResponseOnFollowedPostGrouper
|
||||
)
|
||||
from openedx.core.djangoapps.notifications.models import Notification
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
@@ -98,12 +98,13 @@ class TestGroupUserNotifications(ModuleStoreTestCase):
|
||||
"""
|
||||
|
||||
@patch('openedx.core.djangoapps.notifications.grouping_notifications.NotificationRegistry.get_grouper')
|
||||
def test_group_user_notifications(self, mock_get_grouper):
|
||||
@ddt.data(NewPostGrouper, NewResponseGrouper, NewResponseOnFollowedPostGrouper)
|
||||
def test_group_user_notifications(self, grouper_class, mock_get_grouper):
|
||||
"""
|
||||
Test that the function groups notifications using the appropriate grou
|
||||
Test that the function groups notifications using the appropriate grouping class
|
||||
"""
|
||||
# Mock the grouper
|
||||
mock_grouper = MagicMock(spec=NewPostGrouper)
|
||||
mock_grouper = MagicMock(spec=grouper_class)
|
||||
mock_get_grouper.return_value = mock_grouper
|
||||
|
||||
new_notification = MagicMock(spec=Notification)
|
||||
|
||||
Reference in New Issue
Block a user