Skip to content

Commit

Permalink
temp: add temporary logs for course wide notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadYousaf authored and saadyousafarbi committed Dec 29, 2023
1 parent 30c029f commit 8a9e19a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,6 +22,9 @@
)


log = logging.getLogger(__name__)


class DiscussionNotificationSender:
"""
Class to send notifications to users who are subscribed to the thread.
Expand Down Expand Up @@ -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)


Expand Down
6 changes: 6 additions & 0 deletions openedx/core/djangoapps/notifications/audience_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Audience based filters for notifications
"""
import logging

from abc import abstractmethod

Expand All @@ -21,6 +22,9 @@
)


log = logging.getLogger(__name__)


class NotificationAudienceFilterBase:
"""
Base class for notification audience filters
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/notifications/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand All @@ -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)

0 comments on commit 8a9e19a

Please sign in to comment.