refactor: deprecated v2 preferences api and its dependencies#38072
refactor: deprecated v2 preferences api and its dependencies#38072AhtishamShahid wants to merge 3 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the deprecated V2 notification preferences API and the NotificationTypeManager/NotificationAppManager abstractions, consolidating “default preferences” logic into simpler utility functions and aligning terminology around use_app_defaults / grouped notifications.
Changes:
- Removed the V2 aggregated preferences view and URL route, and deleted its associated test coverage.
- Replaced per-app default lookup (
get_default_values_of_preference) with a unifiedget_default_values_of_preferenceshelper and updated call sites. - Updated comments/terminology around “core” notifications to
use_app_defaults/ grouped notifications.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
openedx/core/djangoapps/notifications/views.py |
Removes V2 API view and relies on V3 grouped-notification update flow. |
openedx/core/djangoapps/notifications/urls.py |
Removes the V2 route and import wiring. |
openedx/core/djangoapps/notifications/tests/test_views.py |
Removes V2 view tests and associated imports. |
openedx/core/djangoapps/notifications/tasks.py |
Switches default web-config lookup to the new unified defaults helper. |
openedx/core/djangoapps/notifications/serializers.py |
Removes unused helper and adjusts notification type validation logic. |
openedx/core/djangoapps/notifications/base_notification.py |
Removes manager classes, introduces unified defaults helper usage, and updates terminology/comments. |
Comments suppressed due to low confidence (1)
openedx/core/djangoapps/notifications/base_notification.py:401
get_notification_contentcallsget_default_values_of_preferences(), which rebuilds a merged dict for all notification types on every invocation. SinceNotification.contentuses this during listing/serialization, this can become a hot path. Consider caching the merged mapping (e.g.,functools.lru_cacheor a module-level computed constant) and using that here to avoid repeated per-notification recomputation.
# Retrieve the notification type object from NotificationTypeManager.
notification_type = get_default_values_of_preferences().get(notification_type, None)
if notification_type:
# Check if the notification is grouped.
is_grouped = context.get('grouped', False)
# Determine the correct template key based on whether it's grouped or not.
template_key = "grouped_content_template" if is_grouped else "content_template"
# Get the corresponding template from the notification type.
template = notification_type.get(template_key, None)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Each notification type defined in COURSE_NOTIFICATION_TYPES also references an app. | ||
|
|
||
| Each notification type can also be optionally defined as a core notification. | ||
| In this case, the delivery preferences for that notification are taken | ||
| from the `core_*` fields of the associated notification app. | ||
| """ |
There was a problem hiding this comment.
The NotificationApp docstring is now incomplete (“In this case, the delivery preferences for that notification are taken …”) after removing the core terminology. Please finish or rewrite this docstring so it fully explains how app defaults apply to use_app_defaults / grouped notifications.
| def add_non_editable_in_preference(preference): | ||
| """ | ||
| Add non_editable preferences to the preference dict |
There was a problem hiding this comment.
add_non_editable_in_preference still special-cases a notification type named "core" to pull non-editable channels from the app config, but the V3 API uses "grouped_notification" for that synthetic grouped entry. This means app-level non_editable settings won’t be applied to grouped notifications. Update the special-case to handle "grouped_notification" (and consider whether "core" is still needed anywhere).
| def get_default_values_of_preferences() -> dict[str, dict[str, Any]]: | ||
| """ | ||
| Returns default preferences for all notification apps |
There was a problem hiding this comment.
get_default_values_of_preferences merges app defaults into notification type configs. For use_app_defaults types, the current merge order ({**app_defaults, **values}) lets any overlapping keys on the type override app defaults, which contradicts the comment above saying the app config should override type-level web/email/push/email_cadence/non_editable. Consider reversing precedence (or explicitly ensuring app defaults win for those keys) so misconfigured types can’t silently override app-level defaults.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request refactors the notification preferences system by removing the
NotificationTypeManagerandNotificationAppManagerclasses, simplifying how default notification preferences are accessed and managed. It also updates terminology for clarity and removes unused or redundant functions. The changes streamline the codebase and improve maintainability.Refactoring and Simplification:
NotificationTypeManagerandNotificationAppManagerclasses, along with their associated methods, inbase_notification.py. Preference logic is now handled by simpler utility functions.get_default_values_of_preferencefunction and updated all usages to use the more generalget_default_values_of_preferences. [1] [2] [3]Terminology and Documentation Updates:
NotificationTypeandNotificationAppto useuse_app_defaultsinstead ofis_core, clarifying the intent and behavior of these fields. [1] [2] [3]Code Cleanup:
get_non_editable_channelsfunction fromserializers.pyand cleaned up related validation logic. [1] [2]test_views.pyto remove references to deleted classes.Functionality Adjustments:
get_notification_contentto use the new utility function for preferences.These changes collectively make the notification preference system easier to understand, reduce code duplication, and improve maintainability.