feat: Add notify all learners option for discussion post (#36922)
* feat: Add notify all learners option for discussion post * fix: Remove waffle flag from default notification dict
This commit is contained in:
@@ -230,6 +230,24 @@ COURSE_NOTIFICATION_TYPES = {
|
||||
'email_template': '',
|
||||
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE],
|
||||
},
|
||||
'new_instructor_all_learners_post': {
|
||||
'notification_app': 'discussion',
|
||||
'name': 'new_instructor_all_learners_post',
|
||||
'is_core': False,
|
||||
'info': '',
|
||||
'web': True,
|
||||
'email': False,
|
||||
'email_cadence': EmailCadence.DAILY,
|
||||
'push': False,
|
||||
'non_editable': [],
|
||||
'content_template': _('<{p}>Your instructor posted <{strong}>{post_title}</{strong}></{p}>'),
|
||||
'grouped_content_template': '',
|
||||
'content_context': {
|
||||
'post_title': 'Post title',
|
||||
},
|
||||
'email_template': '',
|
||||
'filters': [FILTER_AUDIT_EXPIRED_USERS_WITH_NO_ROLE]
|
||||
},
|
||||
}
|
||||
|
||||
COURSE_NOTIFICATION_APPS = {
|
||||
|
||||
@@ -49,3 +49,13 @@ ENABLE_ORA_GRADE_NOTIFICATION = CourseWaffleFlag(f"{WAFFLE_NAMESPACE}.enable_ora
|
||||
# .. toggle_warning: When the flag is ON, Notifications Grouping feature is enabled.
|
||||
# .. toggle_tickets: INF-1472
|
||||
ENABLE_NOTIFICATION_GROUPING = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_notification_grouping', __name__)
|
||||
|
||||
# .. toggle_name: notifications.post_enable_notify_all_learners
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Waffle flag to enable the notify all learners on discussion post
|
||||
# .. toggle_use_cases: open_edx
|
||||
# .. toggle_creation_date: 2025-06-11
|
||||
# .. toggle_warning: When the flag is ON, notification to all learners feature is enabled on discussion post.
|
||||
# .. toggle_tickets: INF-1917
|
||||
ENABLE_NOTIFY_ALL_LEARNERS = CourseWaffleFlag(f'{WAFFLE_NAMESPACE}.enable_post_notify_all_learners', __name__)
|
||||
|
||||
@@ -26,7 +26,7 @@ NOTIFICATION_CHANNELS = ['web', 'push', 'email']
|
||||
ADDITIONAL_NOTIFICATION_CHANNEL_SETTINGS = ['email_cadence']
|
||||
|
||||
# Update this version when there is a change to any course specific notification type or app.
|
||||
COURSE_NOTIFICATION_CONFIG_VERSION = 13
|
||||
COURSE_NOTIFICATION_CONFIG_VERSION = 14
|
||||
|
||||
|
||||
def get_course_notification_preference_config():
|
||||
|
||||
@@ -311,7 +311,10 @@ class TestVisibilityFilter(unittest.TestCase):
|
||||
'core': {'web': True, 'push': True, 'email': True, 'email_cadence': 'Daily'},
|
||||
'content_reported': {'web': True, 'push': True, 'email': True, 'email_cadence': 'Daily'},
|
||||
'new_question_post': {'web': False, 'push': False, 'email': False, 'email_cadence': 'Daily'},
|
||||
'new_discussion_post': {'web': False, 'push': False, 'email': False, 'email_cadence': 'Daily'}
|
||||
'new_discussion_post': {'web': False, 'push': False, 'email': False, 'email_cadence': 'Daily'},
|
||||
'new_instructor_all_learners_post': {
|
||||
'web': True, 'push': False, 'email': False, 'email_cadence': 'Daily'
|
||||
}
|
||||
},
|
||||
'core_notification_types': [
|
||||
'new_response', 'comment_on_followed_post',
|
||||
|
||||
@@ -4,9 +4,11 @@ Utils function for notifications app
|
||||
import copy
|
||||
from typing import Dict, List, Set
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment
|
||||
from openedx.core.djangoapps.django_comment_common.models import Role
|
||||
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS
|
||||
from openedx.core.djangoapps.notifications.config.waffle import ENABLE_NOTIFICATIONS, ENABLE_NOTIFY_ALL_LEARNERS
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
|
||||
|
||||
@@ -132,12 +134,21 @@ def remove_preferences_with_no_access(preferences: dict, user) -> dict:
|
||||
user=user,
|
||||
course_id=preferences['course_id']
|
||||
).values_list('role', flat=True)
|
||||
preferences['notification_preference_config'] = filter_out_visible_notifications(
|
||||
|
||||
user_preferences = filter_out_visible_notifications(
|
||||
user_preferences,
|
||||
notifications_with_visibility_settings,
|
||||
user_forum_roles,
|
||||
user_course_roles
|
||||
)
|
||||
|
||||
course_key = CourseKey.from_string(preferences['course_id'])
|
||||
discussion_config = user_preferences.get('discussion', {})
|
||||
notification_types = discussion_config.get('notification_types', {})
|
||||
|
||||
if notification_types and not ENABLE_NOTIFY_ALL_LEARNERS.is_enabled(course_key):
|
||||
notification_types.pop('new_instructor_all_learners_post', None)
|
||||
|
||||
return preferences
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ from openedx.core.djangoapps.notifications.serializers import add_info_to_notifi
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
|
||||
from .base_notification import COURSE_NOTIFICATION_APPS
|
||||
from .config.waffle import ENABLE_NOTIFICATIONS
|
||||
from .config.waffle import ENABLE_NOTIFICATIONS, ENABLE_NOTIFY_ALL_LEARNERS
|
||||
from .events import (
|
||||
notification_preference_update_event,
|
||||
notification_preferences_viewed_event,
|
||||
@@ -603,13 +603,23 @@ class AggregatedNotificationPreferences(APIView):
|
||||
notification_configs = aggregate_notification_configs(
|
||||
notification_configs
|
||||
)
|
||||
course_ids = notification_preferences.values_list('course_id', flat=True)
|
||||
|
||||
filter_out_visible_preferences_by_course_ids(
|
||||
request.user,
|
||||
notification_configs,
|
||||
notification_preferences.values_list('course_id', flat=True),
|
||||
course_ids,
|
||||
)
|
||||
|
||||
notification_preferences_viewed_event(request)
|
||||
notification_configs = add_info_to_notification_config(notification_configs)
|
||||
|
||||
discussion_config = notification_configs.get('discussion', {})
|
||||
notification_types = discussion_config.get('notification_types', {})
|
||||
|
||||
if not any(ENABLE_NOTIFY_ALL_LEARNERS.is_enabled(course_key) for course_key in course_ids):
|
||||
notification_types.pop('new_instructor_all_learners_post', None)
|
||||
|
||||
return Response({
|
||||
'status': 'success',
|
||||
'message': 'Notification preferences retrieved',
|
||||
|
||||
Reference in New Issue
Block a user