|
| 1 | +""" |
| 2 | +Pipeline steps for the student dashboard filter. |
| 3 | +""" |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +from openedx_filters.filters import PipelineStep |
| 7 | + |
| 8 | +# These imports will be replaced with internal paths in epic 17 when enterprise_support is |
| 9 | +# migrated into edx-enterprise. |
| 10 | +try: |
| 11 | + from openedx.features.enterprise_support.api import ( |
| 12 | + get_dashboard_consent_notification, |
| 13 | + get_enterprise_learner_portal_context, |
| 14 | + ) |
| 15 | + from openedx.features.enterprise_support.utils import is_enterprise_learner |
| 16 | +except ImportError: |
| 17 | + get_dashboard_consent_notification = None |
| 18 | + get_enterprise_learner_portal_context = None |
| 19 | + is_enterprise_learner = None |
| 20 | + |
| 21 | + |
| 22 | +class DashboardContextEnricher(PipelineStep): |
| 23 | + """ |
| 24 | + Enrich the student dashboard context with enterprise-specific data. |
| 25 | +
|
| 26 | + Injects: enterprise_message, consent_required_courses, is_enterprise_user, and |
| 27 | + enterprise learner portal context keys. |
| 28 | + """ |
| 29 | + |
| 30 | + def run_filter(self, context: dict[str, Any], template_name: str) -> dict[str, Any]: # pylint: disable=arguments-differ |
| 31 | + """ |
| 32 | + Inject enterprise data into the dashboard context. |
| 33 | + """ |
| 34 | + request = context.get('request') |
| 35 | + user = context.get('user') |
| 36 | + course_enrollments = context.get('course_enrollment_pairs', []) |
| 37 | + |
| 38 | + if user is None: |
| 39 | + return {'context': context, 'template_name': template_name} |
| 40 | + |
| 41 | + enterprise_message = get_dashboard_consent_notification(request, user, course_enrollments) |
| 42 | + |
| 43 | + enterprise_learner_portal_context = get_enterprise_learner_portal_context(request) |
| 44 | + |
| 45 | + context['enterprise_message'] = enterprise_message |
| 46 | + context['is_enterprise_user'] = is_enterprise_learner(user) |
| 47 | + context.update(enterprise_learner_portal_context) |
| 48 | + |
| 49 | + return {'context': context, 'template_name': template_name} |
0 commit comments