From 8a9e19ad8f447a10df701c813287e138037e1888 Mon Sep 17 00:00:00 2001 From: SaadYousaf Date: Thu, 28 Dec 2023 14:32:56 +0500 Subject: [PATCH] temp: add temporary logs for course wide notifications --- .../discussion/rest_api/discussions_notifications.py | 7 +++++++ openedx/core/djangoapps/notifications/audience_filters.py | 6 ++++++ openedx/core/djangoapps/notifications/handlers.py | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/lms/djangoapps/discussion/rest_api/discussions_notifications.py b/lms/djangoapps/discussion/rest_api/discussions_notifications.py index cba7852023ef..31f158fbd742 100644 --- a/lms/djangoapps/discussion/rest_api/discussions_notifications.py +++ b/lms/djangoapps/discussion/rest_api/discussions_notifications.py @@ -1,6 +1,8 @@ """ Discussion notifications sender util. """ +import logging + from django.conf import settings from lms.djangoapps.discussion.django_comment_client.permissions import get_team from openedx_events.learning.data import UserNotificationData, CourseNotificationData @@ -20,6 +22,9 @@ ) +log = logging.getLogger(__name__) + + class DiscussionNotificationSender: """ Class to send notifications to users who are subscribed to the thread. @@ -257,6 +262,8 @@ def send_new_thread_created_notification(self): 'username': self.creator.username, 'post_title': self.thread.title } + + log.info(f"Temp: Audience filter for course-wide notification is {audience_filters}") self._send_course_wide_notification(notification_type, audience_filters, context) diff --git a/openedx/core/djangoapps/notifications/audience_filters.py b/openedx/core/djangoapps/notifications/audience_filters.py index fe9a047f78ca..8d02bb3ea756 100644 --- a/openedx/core/djangoapps/notifications/audience_filters.py +++ b/openedx/core/djangoapps/notifications/audience_filters.py @@ -1,6 +1,7 @@ """ Audience based filters for notifications """ +import logging from abc import abstractmethod @@ -21,6 +22,9 @@ ) +log = logging.getLogger(__name__) + + class NotificationAudienceFilterBase: """ Base class for notification audience filters @@ -80,10 +84,12 @@ def filter(self, course_roles): if 'staff' in course_roles: staff_users = CourseStaffRole(course_key).users_with_role().values_list('id', flat=True) + log.info(f'Temp: Course wide notification, staff users calculated are {staff_users}') user_ids.extend(staff_users) if 'instructor' in course_roles: instructor_users = CourseInstructorRole(course_key).users_with_role().values_list('id', flat=True) + log.info(f'Temp: Course wide notification, instructor users calculated are {instructor_users}') user_ids.extend(instructor_users) return user_ids diff --git a/openedx/core/djangoapps/notifications/handlers.py b/openedx/core/djangoapps/notifications/handlers.py index 9308f0e63e88..05dd9f5bbd42 100644 --- a/openedx/core/djangoapps/notifications/handlers.py +++ b/openedx/core/djangoapps/notifications/handlers.py @@ -96,10 +96,13 @@ def calculate_course_wide_notification_audience(course_key, audience_filters): if filter_class: filter_instance = filter_class(course_key) filtered_users = filter_instance.filter(filter_values) + log.info(f'Temp: Course-wide notification filtered users are ' + f'{filtered_users} for filter type {filter_type}') audience_user_ids.extend(filtered_users) else: raise ValueError(f"Invalid audience filter type: {filter_type}") + log.info(f'Temp: Course-wide notification after audience filter is applied, users: {list(set(audience_user_ids))}') return list(set(audience_user_ids)) @@ -124,4 +127,5 @@ def generate_course_notifications(signal, sender, course_notification_data, meta 'content_url': course_notification_data.get('content_url'), } + log.info(f"Temp: Course-wide notification, user_ids to sent notifications to {notification_data.get('user_ids')}") send_notifications.delay(**notification_data)