|
21 | 21 | from common.djangoapps import third_party_auth |
22 | 22 | from common.djangoapps.student.helpers import get_next_url_for_login_page |
23 | 23 | from lms.djangoapps.branding.api import get_privacy_url |
| 24 | +from openedx.core.djangoapps.geoinfo.api import country_code_from_ip |
24 | 25 | from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers |
25 | 26 | from openedx.core.djangoapps.user_authn.cookies import standard_cookie_settings |
26 | 27 | from openedx.core.djangolib.markup import HTML, Text |
| 28 | +from openedx.core.djangoapps.user_authn.views.utils import third_party_auth_context |
| 29 | +from ipware import get_client_ip |
27 | 30 |
|
28 | 31 | ENTERPRISE_HEADER_LINKS = WaffleFlag('enterprise.enterprise_header_links', __name__) # pylint: disable=toggle-missing-annotation |
29 | 32 |
|
@@ -144,6 +147,7 @@ def get_enterprise_sidebar_context(enterprise_customer, is_proxy_login): |
144 | 147 | 'enterprise_name': enterprise_customer['name'], |
145 | 148 | 'enterprise_logo_url': logo_url, |
146 | 149 | 'enterprise_branded_welcome_string': branded_welcome_string, |
| 150 | + 'enterprise_slug': enterprise_customer.get('slug'), |
147 | 151 | 'platform_welcome_string': platform_welcome_string, |
148 | 152 | } |
149 | 153 |
|
@@ -488,3 +492,50 @@ def is_course_accessed(user, course_id): |
488 | 492 | return True |
489 | 493 | except UnavailableCompletionData: |
490 | 494 | return False |
| 495 | + |
| 496 | + |
| 497 | +def get_enterprise_dashboard_url(request, enterprise_customer): |
| 498 | + """ |
| 499 | + Generate the enterprise-specific dashboard URL. |
| 500 | + """ |
| 501 | + base_url = settings.ENTERPRISE_LEARNER_PORTAL_BASE_URL |
| 502 | + return f"{base_url}/{enterprise_customer['slug']}" |
| 503 | + |
| 504 | + |
| 505 | +def get_mfe_context(request, redirect_to, tpa_hint=None): |
| 506 | + """ |
| 507 | + Returns Authn MFE context. |
| 508 | + """ |
| 509 | + # Import enterprise functions INSIDE the function to avoid circular import |
| 510 | + from openedx.features.enterprise_support.api import enterprise_customer_for_request |
| 511 | + |
| 512 | + ip_address = get_client_ip(request)[0] |
| 513 | + country_code = country_code_from_ip(ip_address) |
| 514 | + context = third_party_auth_context(request, redirect_to, tpa_hint) |
| 515 | + |
| 516 | + enterprise_customer = enterprise_customer_for_request(request) |
| 517 | + enterprise_branding = None |
| 518 | + |
| 519 | + if enterprise_customer: |
| 520 | + sidebar_context = get_enterprise_sidebar_context( |
| 521 | + enterprise_customer, |
| 522 | + is_proxy_login=False |
| 523 | + ) |
| 524 | + if sidebar_context: |
| 525 | + enterprise_branding = { |
| 526 | + 'enterpriseName': sidebar_context.get('enterprise_name'), |
| 527 | + 'enterpriseLogoUrl': sidebar_context.get('enterprise_logo_url'), |
| 528 | + 'enterpriseBrandedWelcomeString': str( |
| 529 | + sidebar_context.get('enterprise_branded_welcome_string', '') |
| 530 | + ), |
| 531 | + 'platformWelcomeString': str( |
| 532 | + sidebar_context.get('platform_welcome_string', '') |
| 533 | + ), |
| 534 | + } |
| 535 | + |
| 536 | + context.update({ |
| 537 | + 'countryCode': country_code, |
| 538 | + 'enterpriseBranding': enterprise_branding, |
| 539 | + }) |
| 540 | + |
| 541 | + return context |
0 commit comments