Skip to content

Commit 0c2ae7e

Browse files
feat: added enterprise theming changes (#139)
* feat: added enterprise theming changes * fix: fixed newline breaking changes * fix: removed the whitespace (cherry picked from commit a681c1f)
1 parent feb3e3f commit 0c2ae7e

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

openedx/core/djangoapps/user_authn/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class PipelineUserDetailsSerializer(serializers.Serializer):
3232
lastName = serializers.CharField(source='last_name', allow_null=True)
3333

3434

35+
class EnterpriseBrandingSerializer(serializers.Serializer):
36+
"""Serializer for enterprise branding data."""
37+
38+
enterpriseName = serializers.CharField(allow_null=True, required=False)
39+
enterpriseLogoUrl = serializers.CharField(allow_null=True, required=False)
40+
enterpriseBrandedWelcomeString = serializers.CharField(allow_null=True, required=False)
41+
enterpriseSlug = serializers.CharField(allow_null=True, required=False)
42+
platformWelcomeString = serializers.CharField(allow_null=True, required=False)
43+
44+
3545
class ContextDataSerializer(serializers.Serializer):
3646
"""
3747
Context Data Serializers

openedx/core/djangoapps/user_authn/views/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,29 @@ def get_mfe_context(request, redirect_to, tpa_hint=None):
122122
"""
123123
Returns Authn MFE context.
124124
"""
125+
# Import enterprise functions INSIDE the function to avoid circular import
126+
from openedx.features.enterprise_support.api import enterprise_customer_for_request
127+
from openedx.features.enterprise_support.utils import get_enterprise_sidebar_context
125128

126129
ip_address = get_client_ip(request)[0]
127130
country_code = country_code_from_ip(ip_address)
128131
context = third_party_auth_context(request, redirect_to, tpa_hint)
132+
# Add enterprise branding if enterprise customer is detected
133+
enterprise_customer = enterprise_customer_for_request(request)
134+
enterprise_branding = None
135+
if enterprise_customer:
136+
sidebar_context = get_enterprise_sidebar_context(enterprise_customer, is_proxy_login=False)
137+
if sidebar_context:
138+
enterprise_branding = {
139+
'enterpriseName': sidebar_context.get('enterprise_name'),
140+
'enterpriseLogoUrl': sidebar_context.get('enterprise_logo_url'),
141+
'enterpriseBrandedWelcomeString': str(sidebar_context.get('enterprise_branded_welcome_string', '')),
142+
'platformWelcomeString': str(sidebar_context.get('platform_welcome_string', '')),
143+
'enterpriseSlug': sidebar_context.get('enterprise_slug') or enterprise_customer.get('slug'),
144+
}
129145
context.update({
130146
'countryCode': country_code,
147+
'enterpriseBranding': enterprise_branding, # Add enterprise branding to context
131148
})
132149
return context
133150

openedx/features/enterprise_support/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ def get_enterprise_customer(self, uuid):
298298
return enterprise_customer
299299

300300

301+
def fetch_enterprise_branding(self, enterprise_customer_uuid):
302+
"""
303+
Fetch branding configuration for the given enterprise customer UUID.
304+
"""
305+
branding_url = f"{self.base_api_url}/enterprise-customer-branding/{enterprise_customer_uuid}/"
306+
response = self.client.get(branding_url)
307+
response.raise_for_status()
308+
return response.json()
309+
310+
301311
def activate_learner_enterprise(request, user, enterprise_customer):
302312
"""
303313
Allow an enterprise learner to activate one of learner's linked enterprises.

openedx/features/enterprise_support/utils.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
from common.djangoapps import third_party_auth
2222
from common.djangoapps.student.helpers import get_next_url_for_login_page
2323
from lms.djangoapps.branding.api import get_privacy_url
24+
from openedx.core.djangoapps.geoinfo.api import country_code_from_ip
2425
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
2526
from openedx.core.djangoapps.user_authn.cookies import standard_cookie_settings
2627
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
2730

2831
ENTERPRISE_HEADER_LINKS = WaffleFlag('enterprise.enterprise_header_links', __name__) # pylint: disable=toggle-missing-annotation
2932

@@ -144,6 +147,7 @@ def get_enterprise_sidebar_context(enterprise_customer, is_proxy_login):
144147
'enterprise_name': enterprise_customer['name'],
145148
'enterprise_logo_url': logo_url,
146149
'enterprise_branded_welcome_string': branded_welcome_string,
150+
'enterprise_slug': enterprise_customer.get('slug'),
147151
'platform_welcome_string': platform_welcome_string,
148152
}
149153

@@ -488,3 +492,50 @@ def is_course_accessed(user, course_id):
488492
return True
489493
except UnavailableCompletionData:
490494
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

Comments
 (0)