Unverified Commit 3132d29c by Asad Iqbal Committed by GitHub

Merge pull request #16557 from edx/asadiqbal08/ENT-729

ENT-729 asadiqbal08/Authenticating directly using "tpa_hint" URL link the learner to enterprise customer
parents ded34227 e5c55a89
......@@ -10,6 +10,8 @@ If true, it:
b) calls apply_settings(), passing in the Django settings
"""
from openedx.features.enterprise_support.api import insert_enterprise_pipeline_elements
_FIELDS_STORED_IN_SESSION = ['auth_entry', 'next']
_MIDDLEWARE_CLASSES = ['third_party_auth.middleware.ExceptionMiddleware']
_SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/dashboard'
......@@ -59,6 +61,9 @@ def apply_settings(django_settings):
'third_party_auth.pipeline.login_analytics',
]
# Add enterprise pipeline elements if the enterprise app is installed
insert_enterprise_pipeline_elements(django_settings.SOCIAL_AUTH_PIPELINE)
# Required so that we can use unmodified PSA OAuth2 backends:
django_settings.SOCIAL_AUTH_STRATEGY = 'third_party_auth.strategy.ConfigurationModelStrategy'
......
......@@ -547,3 +547,20 @@ def get_dashboard_consent_notification(request, user, course_enrollments):
}
)
return ''
def insert_enterprise_pipeline_elements(pipeline):
"""
If the enterprise app is enabled, insert additional elements into the
pipeline related to enterprise.
"""
if not enterprise_enabled():
return
additional_elements = (
'enterprise.tpa_pipeline.handle_enterprise_logistration',
)
insert_point = pipeline.index('social_core.pipeline.social_auth.load_extra_data')
for index, element in enumerate(additional_elements):
pipeline.insert(insert_point + index, element)
......@@ -25,6 +25,8 @@ from openedx.features.enterprise_support.api import (
enterprise_customer_for_request,
get_dashboard_consent_notification,
get_enterprise_consent_url,
insert_enterprise_pipeline_elements,
enterprise_enabled,
)
from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseServiceMockMixin
from openedx.features.enterprise_support.utils import get_cache_key
......@@ -428,3 +430,25 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
self.assertIn(substr, notification_string)
else:
self.assertEqual(notification_string, '')
@override_settings(FEATURES=dict(ENABLE_ENTERPRISE_INTEGRATION=False))
def test_utils_with_enterprise_disabled(self):
"""
Test that disabling the enterprise integration flag causes
the utilities to return the expected default values.
"""
self.assertFalse(enterprise_enabled())
self.assertEqual(insert_enterprise_pipeline_elements(None), None)
def test_utils_with_enterprise_enabled(self):
"""
Test that enabling enterprise integration (which is currently on by default) causes the
the utilities to return the expected values.
"""
self.assertTrue(enterprise_enabled())
pipeline = ['abc', 'social_core.pipeline.social_auth.load_extra_data', 'def']
insert_enterprise_pipeline_elements(pipeline)
self.assertEqual(pipeline, ['abc',
'enterprise.tpa_pipeline.handle_enterprise_logistration',
'social_core.pipeline.social_auth.load_extra_data',
'def'])
......@@ -47,7 +47,7 @@ edx-lint==0.4.3
astroid==1.3.8
edx-django-oauth2-provider==1.2.5
edx-django-sites-extensions==2.3.0
edx-enterprise==0.53.13
edx-enterprise==0.53.14
edx-oauth2-provider==1.2.2
edx-opaque-keys==0.4.0
edx-organizations==0.4.7
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment