diff --git a/common/djangoapps/third_party_auth/settings.py b/common/djangoapps/third_party_auth/settings.py index 6f4cb29f7c..9b4389c70c 100644 --- a/common/djangoapps/third_party_auth/settings.py +++ b/common/djangoapps/third_party_auth/settings.py @@ -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' diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index a300124d22..a8c4ffe29c 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -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) diff --git a/openedx/features/enterprise_support/tests/test_api.py b/openedx/features/enterprise_support/tests/test_api.py index e791fb63f5..7207f4c5c4 100644 --- a/openedx/features/enterprise_support/tests/test_api.py +++ b/openedx/features/enterprise_support/tests/test_api.py @@ -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']) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 7b14a0ee16..956fc9ed15 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -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