From b43834979535095eaf790d39eb7ef87a1c503e99 Mon Sep 17 00:00:00 2001 From: Eemaan Amir <57627710+eemaanamir@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:56:05 +0500 Subject: [PATCH] fix: rephrasing and removing bugs from response endorsed notifications (#35136) * fix: rephrasing and removing bugs from response endorsed notifications * test: updated test for response endorsed notifications --- lms/djangoapps/discussion/rest_api/tasks.py | 7 ++++--- lms/djangoapps/discussion/rest_api/tests/test_tasks.py | 4 ++-- openedx/core/djangoapps/notifications/base_notification.py | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/tasks.py b/lms/djangoapps/discussion/rest_api/tasks.py index 5f0bf8ed40ea..45bf41fe905f 100644 --- a/lms/djangoapps/discussion/rest_api/tasks.py +++ b/lms/djangoapps/discussion/rest_api/tasks.py @@ -60,15 +60,16 @@ def send_response_endorsed_notifications(thread_id, response_id, course_key_str, if not ENABLE_NOTIFICATIONS.is_enabled(course_key): return thread = Thread(id=thread_id).retrieve() - creator = User.objects.get(id=endorsed_by) - course = get_course_with_access(creator, 'load', course_key, check_if_enrolled=True) response = Comment(id=response_id).retrieve() + creator = User.objects.get(id=response.user_id) + endorser = User.objects.get(id=endorsed_by) + course = get_course_with_access(creator, 'load', course_key, check_if_enrolled=True) notification_sender = DiscussionNotificationSender(thread, course, creator) # skip sending notification to author of thread if they are the same as the author of the response if response.user_id != thread.user_id: # sends notification to author of thread notification_sender.send_response_endorsed_on_thread_notification() # sends notification to author of response - if int(response.user_id) != creator.id: + if int(response.user_id) != endorser.id: notification_sender.creator = User.objects.get(id=response.user_id) notification_sender.send_response_endorsed_notification() diff --git a/lms/djangoapps/discussion/rest_api/tests/test_tasks.py b/lms/djangoapps/discussion/rest_api/tests/test_tasks.py index 26146857366b..f3f2a68ae668 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_tasks.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_tasks.py @@ -600,10 +600,10 @@ def test_response_endorsed_notifications(self): self.assertEqual(notification_data.notification_type, 'response_endorsed_on_thread') expected_context = { - 'replier_name': self.user_3.username, + 'replier_name': self.user_2.username, 'post_title': 'test thread', 'course_name': self.course.display_name, - 'sender_id': int(self.user_3.id), + 'sender_id': int(self.user_2.id), } self.assertDictEqual(notification_data.context, expected_context) self.assertEqual(notification_data.content_url, _get_mfe_url(self.course.id, thread.id)) diff --git a/openedx/core/djangoapps/notifications/base_notification.py b/openedx/core/djangoapps/notifications/base_notification.py index 2845e9cbe41d..0287d8f73c19 100644 --- a/openedx/core/djangoapps/notifications/base_notification.py +++ b/openedx/core/djangoapps/notifications/base_notification.py @@ -146,11 +146,11 @@ 'is_core': True, 'info': '', 'non_editable': [], - 'content_template': _('<{p}><{strong}>{replier_name} response has been endorsed in your post ' + 'content_template': _('<{p}><{strong}>{replier_name}\'s response has been endorsed in your post ' '<{strong}>{post_title}'), 'content_context': { 'post_title': 'Post title', - 'replier_name': 'Endorsed by', + 'replier_name': 'replier name', }, 'email_template': '', 'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE] @@ -161,7 +161,8 @@ 'is_core': True, 'info': '', 'non_editable': [], - 'content_template': _('<{p}>{post_title}'), + 'content_template': _('<{p}>Your response has been endorsed on the post <{strong}>{post_title}'), 'content_context': { 'post_title': 'Post title', },