Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added waffle flag for new notification view #35569

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions openedx/core/djangoapps/notifications/config/waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@
# .. 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.enable_new_notification_view
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Waffle flag to enable new notification view
# .. toggle_use_cases: temporary, open_edx
# .. toggle_creation_date: 2024-09-30
# .. toggle_target_removal_date: 2025-10-10
# .. toggle_tickets: INF-1603
ENABLE_NEW_NOTIFICATION_VIEW = WaffleFlag(f"{WAFFLE_NAMESPACE}.enable_new_notification_view", __name__)
16 changes: 15 additions & 1 deletion openedx/core/djangoapps/notifications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Utils function for notifications app
"""
from typing import Dict, List
from waffle import get_waffle_flag_model

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_NEW_NOTIFICATION_VIEW
from openedx.core.lib.cache_utils import request_cached


Expand Down Expand Up @@ -47,6 +48,19 @@ def get_show_notifications_tray(user):
return show_notifications_tray


def get_is_new_notification_view_enabled():
"""
Returns True if the waffle flag for the new notification view is enabled, False otherwise.
"""
flag_model = get_waffle_flag_model()

try:
flag = flag_model.objects.get(name=ENABLE_NEW_NOTIFICATION_VIEW.name)
return flag.everyone if flag.everyone is not None else False
except flag_model.DoesNotExist:
return False
Comment on lines +51 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check if WaffleFlag is enabled, use .is_enabled() because no course or user information is required. Custom implementation will be helpful when waffle flag needs to be enabled for a specific user/s.

def get_is_new_notification_view_enabled():
    """
    Returns True if the waffle flag for the new notification view is enabled, False otherwise.
    """
    return ENABLE_NEW_NOTIFICATION_VIEW.is_enabled()



def get_list_in_batches(input_list, batch_size):
"""
Divides the list of objects into list of list of objects each of length batch_size.
Expand Down
6 changes: 4 additions & 2 deletions openedx/core/djangoapps/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
UserCourseNotificationPreferenceSerializer,
UserNotificationPreferenceUpdateSerializer,
)
from .utils import get_show_notifications_tray
from .utils import get_show_notifications_tray, get_is_new_notification_view_enabled


@allow_any_authenticated_user()
Expand Down Expand Up @@ -329,6 +329,7 @@ def get(self, request):
)
count_total = 0
show_notifications_tray = get_show_notifications_tray(self.request.user)
is_new_notification_view_enabled = get_is_new_notification_view_enabled()
count_by_app_name_dict = {
app_name: 0
for app_name in COURSE_NOTIFICATION_APPS
Expand All @@ -344,7 +345,8 @@ def get(self, request):
"show_notifications_tray": show_notifications_tray,
"count": count_total,
"count_by_app_name": count_by_app_name_dict,
"notification_expiry_days": settings.NOTIFICATIONS_EXPIRY
"notification_expiry_days": settings.NOTIFICATIONS_EXPIRY,
"is_new_notification_view_enabled": is_new_notification_view_enabled
})


Expand Down
Loading