ENT-32 Show enterprise customer branding on Logistration.
nit: css
This commit is contained in:
@@ -3,9 +3,11 @@ Helpers to access the enterprise app
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
import logging
|
||||
|
||||
try:
|
||||
from enterprise.models import EnterpriseCustomer
|
||||
from enterprise import api as enterprise_api
|
||||
from enterprise.tpa_pipeline import (
|
||||
active_provider_requests_data_sharing,
|
||||
active_provider_enforces_data_sharing,
|
||||
@@ -16,6 +18,8 @@ except ImportError:
|
||||
pass
|
||||
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS = 'enterprise_customer_branding_override_details'
|
||||
LOGGER = logging.getLogger("edx.enterprise_helpers")
|
||||
|
||||
|
||||
def enterprise_enabled():
|
||||
@@ -120,3 +124,60 @@ def insert_enterprise_pipeline_elements(pipeline):
|
||||
|
||||
for index, element in enumerate(additional_elements):
|
||||
pipeline.insert(insert_point + index, element)
|
||||
|
||||
|
||||
def get_enterprise_customer_logo_url(request):
|
||||
"""
|
||||
Client API operation adapter/wrapper.
|
||||
"""
|
||||
|
||||
if not enterprise_enabled():
|
||||
return None
|
||||
|
||||
parameter = get_enterprise_branding_filter_param(request)
|
||||
if not parameter:
|
||||
return None
|
||||
|
||||
provider_id = parameter.get('provider_id', None)
|
||||
ec_uuid = parameter.get('ec_uuid', None)
|
||||
|
||||
if provider_id:
|
||||
branding_info = enterprise_api.get_enterprise_branding_info_by_provider_id(provider_id=provider_id)
|
||||
elif ec_uuid:
|
||||
branding_info = enterprise_api.get_enterprise_branding_info_by_ec_uuid(ec_uuid=ec_uuid)
|
||||
|
||||
logo_url = None
|
||||
if branding_info and branding_info.logo:
|
||||
logo_url = branding_info.logo.url
|
||||
|
||||
return logo_url
|
||||
|
||||
|
||||
def set_enterprise_branding_filter_param(request, provider_id):
|
||||
"""
|
||||
Setting 'ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS' in session. 'ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS'
|
||||
either be provider_id or ec_uuid. e.g. {provider_id: 'xyz'} or {ec_src: enterprise_customer_uuid}
|
||||
"""
|
||||
ec_uuid = request.GET.get('ec_src', None)
|
||||
if provider_id:
|
||||
LOGGER.info(
|
||||
"Session key 'ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS' has been set with provider_id '%s'",
|
||||
provider_id
|
||||
)
|
||||
request.session[ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS] = {'provider_id': provider_id}
|
||||
|
||||
elif ec_uuid:
|
||||
# we are assuming that none sso based enterprise will return Enterprise Customer uuid as 'ec_src' in query
|
||||
# param e.g. edx.org/foo/bar?ec_src=6185ed46-68a4-45d6-8367-96c0bf70d1a6
|
||||
LOGGER.info(
|
||||
"Session key 'ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS' has been set with ec_uuid '%s'", ec_uuid
|
||||
)
|
||||
request.session[ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS] = {'ec_uuid': ec_uuid}
|
||||
|
||||
|
||||
def get_enterprise_branding_filter_param(request):
|
||||
"""
|
||||
:return Filter parameter from session for enterprise customer branding information.
|
||||
|
||||
"""
|
||||
return request.session.get(ENTERPRISE_CUSTOMER_BRANDING_OVERRIDE_DETAILS, None)
|
||||
|
||||
@@ -12,7 +12,10 @@ from util.enterprise_helpers import (
|
||||
data_sharing_consent_required_at_login,
|
||||
data_sharing_consent_requirement_at_login,
|
||||
insert_enterprise_fields,
|
||||
insert_enterprise_pipeline_elements
|
||||
insert_enterprise_pipeline_elements,
|
||||
set_enterprise_branding_filter_param,
|
||||
get_enterprise_branding_filter_param,
|
||||
get_enterprise_customer_logo_url
|
||||
)
|
||||
|
||||
|
||||
@@ -144,3 +147,68 @@ class TestEnterpriseHelpers(unittest.TestCase):
|
||||
mock_ec.requests_data_sharing_consent = False
|
||||
insert_enterprise_fields(request, form_desc)
|
||||
form_desc.add_field.assert_not_called()
|
||||
|
||||
def test_set_enterprise_branding_filter_param(self):
|
||||
"""
|
||||
Test that the enterprise customer branding parameters are setting correctly.
|
||||
"""
|
||||
ec_uuid = '97b4a894-cea9-4103-8f9f-2c5c95a58ba3'
|
||||
provider_id = 'test-provider-idp'
|
||||
|
||||
request = mock.MagicMock(session={}, GET={'ec_src': ec_uuid})
|
||||
set_enterprise_branding_filter_param(request, provider_id=None)
|
||||
self.assertEqual(get_enterprise_branding_filter_param(request), {'ec_uuid': ec_uuid})
|
||||
|
||||
set_enterprise_branding_filter_param(request, provider_id=provider_id)
|
||||
self.assertEqual(get_enterprise_branding_filter_param(request), {'provider_id': provider_id})
|
||||
|
||||
@mock.patch('util.enterprise_helpers.enterprise_enabled', mock.Mock(return_value=True))
|
||||
def test_get_enterprise_customer_logo_url(self):
|
||||
"""
|
||||
Test test_get_enterprise_customer_logo_url return the logo url as desired.
|
||||
"""
|
||||
ec_uuid = '97b4a894-cea9-4103-8f9f-2c5c95a58ba3'
|
||||
provider_id = 'test-provider-idp'
|
||||
request = mock.MagicMock(session={}, GET={'ec_src': ec_uuid})
|
||||
branding_info = mock.Mock(
|
||||
logo=mock.Mock(
|
||||
url='/test/image.png'
|
||||
)
|
||||
)
|
||||
|
||||
set_enterprise_branding_filter_param(request, provider_id=None)
|
||||
with mock.patch('enterprise.api.get_enterprise_branding_info_by_ec_uuid', return_value=branding_info):
|
||||
logo_url = get_enterprise_customer_logo_url(request)
|
||||
self.assertEqual(logo_url, '/test/image.png')
|
||||
|
||||
set_enterprise_branding_filter_param(request, provider_id)
|
||||
with mock.patch('enterprise.api.get_enterprise_branding_info_by_provider_id', return_value=branding_info):
|
||||
logo_url = get_enterprise_customer_logo_url(request)
|
||||
self.assertEqual(logo_url, '/test/image.png')
|
||||
|
||||
@mock.patch('util.enterprise_helpers.enterprise_enabled', mock.Mock(return_value=False))
|
||||
def test_get_enterprise_customer_logo_url_return_none(self):
|
||||
"""
|
||||
Test get_enterprise_customer_logo_url return 'None' when enterprise application is not installed.
|
||||
"""
|
||||
request = mock.MagicMock(session={})
|
||||
branding_info = mock.Mock()
|
||||
|
||||
set_enterprise_branding_filter_param(request, 'test-idp')
|
||||
with mock.patch('enterprise.api.get_enterprise_branding_info_by_provider_id', return_value=branding_info):
|
||||
logo_url = get_enterprise_customer_logo_url(request)
|
||||
self.assertEqual(logo_url, None)
|
||||
|
||||
@mock.patch('util.enterprise_helpers.enterprise_enabled', mock.Mock(return_value=True))
|
||||
@mock.patch('util.enterprise_helpers.get_enterprise_branding_filter_param', mock.Mock(return_value=None))
|
||||
def test_get_enterprise_customer_logo_url_return_none_when_param_missing(self):
|
||||
"""
|
||||
Test get_enterprise_customer_logo_url return 'None' when filter parameters are missing.
|
||||
"""
|
||||
request = mock.MagicMock(session={})
|
||||
branding_info = mock.Mock()
|
||||
|
||||
set_enterprise_branding_filter_param(request, provider_id=None)
|
||||
with mock.patch('enterprise.api.get_enterprise_branding_info_by_provider_id', return_value=branding_info):
|
||||
logo_url = get_enterprise_customer_logo_url(request)
|
||||
self.assertEqual(logo_url, None)
|
||||
|
||||
Reference in New Issue
Block a user