Skip to content

Commit

Permalink
feat: added notification when response is endorsed or answered
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed Jan 22, 2024
1 parent 2ae9155 commit 6f556ca
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ def _create_cohort_course_audience(self):
}
return {}

def send_new_response_endorsed_notification(self):
"""
Sends a notification to the author of the thread
response on his thread has been endorsed
"""
self._send_notification([self.thread.user_id], "response_endorsed")

def send_new_thread_created_notification(self):
"""
Send notification based on notification_type
Expand Down
17 changes: 17 additions & 0 deletions lms/djangoapps/discussion/rest_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ def send_response_notifications(thread_id, course_key_str, user_id, parent_id=No
notification_sender.send_new_response_notification()
notification_sender.send_new_comment_on_response_notification()
notification_sender.send_response_on_followed_post_notification()


@shared_task
@set_code_owner_attribute
def send_response_endorsed_notification(thread_id, course_key_str):
"""
Send notification when a response is marked answered/ endorsed
"""
course_key = CourseKey.from_string(course_key_str)
if not ENABLE_NOTIFICATIONS.is_enabled(course_key):
return
thread = Thread(id=thread_id).retrieve()
user = User.objects.get(id=thread.user_id)
course = get_course_with_access(user, 'load', course_key, check_if_enrolled=True)
notification_sender = DiscussionNotificationSender(thread, course)
notification_sender.send_new_response_endorsed_notification()

15 changes: 14 additions & 1 deletion lms/djangoapps/discussion/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from xmodule.modulestore.django import SignalHandler

from lms.djangoapps.discussion import tasks
from lms.djangoapps.discussion.rest_api.tasks import send_response_notifications, send_thread_created_notification
from lms.djangoapps.discussion.rest_api.tasks import send_response_notifications, send_thread_created_notification, send_response_endorsed_notification
from openedx.core.djangoapps.django_comment_common import signals
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
from openedx.core.djangoapps.theming.helpers import get_current_site
Expand Down Expand Up @@ -157,3 +157,16 @@ def create_comment_created_notification(*args, **kwargs):
parent_id = comment.attributes['parent_id']
course_key_str = comment.attributes['course_id']
send_response_notifications.apply_async(args=[thread_id, course_key_str, user.id, parent_id])


@receiver(signals.comment_endorsed)
def create_response_endorsed_notification(*args, **kwargs):
"""
Creates a notification when new response is endorsed
"""
user = kwargs['user']
comment = kwargs['post']
thread_id = comment.attributes['thread_id']
course_key_str = comment.attributes['course_id']

send_response_endorsed_notification.apply_async(args=[thread_id, course_key_str])
17 changes: 17 additions & 0 deletions openedx/core/djangoapps/notifications/base_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@
'email_template': '',
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE]
},
'endorsed_post': {
'notification_app': 'discussion',
'name': 'endorsed_post',
'is_core': False,
'info': '',
'web': True,
'email': True,
'push': True,
'non_editable': [],
'content_template': _('<{p}><{strong}>{username}</{strong}> response has been endorsed in your post <{strong}>{post_title}</{strong}></{p}>'),
'content_context': {
'post_title': 'Post title',
'username': 'Post author name',
},
'email_template': '',
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE]
},
}

COURSE_NOTIFICATION_APPS = {
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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 = 4
COURSE_NOTIFICATION_CONFIG_VERSION = 5


def get_course_notification_preference_config():
Expand Down

0 comments on commit 6f556ca

Please sign in to comment.