From a6757e47a489084ea60def0a75bbe6791fe99b4c Mon Sep 17 00:00:00 2001 From: John Eskew Date: Thu, 19 Oct 2017 15:25:55 -0400 Subject: [PATCH 1/2] Move third_party_auth settings code to ready method. --- .../djangoapps/third_party_auth/__init__.py | 3 +++ common/djangoapps/third_party_auth/apps.py | 22 +++++++++++++++++++ lms/startup.py | 15 ------------- 3 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 common/djangoapps/third_party_auth/apps.py diff --git a/common/djangoapps/third_party_auth/__init__.py b/common/djangoapps/third_party_auth/__init__.py index 8646ed434c..13f12c70de 100644 --- a/common/djangoapps/third_party_auth/__init__.py +++ b/common/djangoapps/third_party_auth/__init__.py @@ -3,6 +3,9 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +default_app_config = 'third_party_auth.apps.ThirdPartyAuthConfig' + + def is_enabled(): """Check whether third party authentication has been enabled. """ diff --git a/common/djangoapps/third_party_auth/apps.py b/common/djangoapps/third_party_auth/apps.py new file mode 100644 index 0000000000..3836836af9 --- /dev/null +++ b/common/djangoapps/third_party_auth/apps.py @@ -0,0 +1,22 @@ + +from django.apps import AppConfig +from django.conf import settings + + +class ThirdPartyAuthConfig(AppConfig): + name = 'third_party_auth' + verbose_name = "Third-party authentication" + + def ready(self): + # To override the settings before loading social_django. + if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False): + self._enable_third_party_auth() + + def _enable_third_party_auth(self): + """ + Enable the use of third_party_auth, which allows users to sign in to edX + using other identity providers. For configuration details, see + common/djangoapps/third_party_auth/settings.py. + """ + from third_party_auth import settings as auth_settings + auth_settings.apply_settings(settings) diff --git a/lms/startup.py b/lms/startup.py index 4a928edb02..169976743c 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -35,10 +35,6 @@ def run(): """ django_db_models_options.patch() - # To override the settings before executing the autostartup() for python-social-auth - if settings.FEATURES.get('ENABLE_THIRD_PARTY_AUTH', False): - enable_third_party_auth() - # Comprehensive theming needs to be set up before django startup, # because modifying django template paths after startup has no effect. if is_comprehensive_theming_enabled(): @@ -114,14 +110,3 @@ def enable_microsites(): Here for backwards compatibility """ microsite.enable_microsites(log) - - -def enable_third_party_auth(): - """ - Enable the use of third_party_auth, which allows users to sign in to edX - using other identity providers. For configuration details, see - common/djangoapps/third_party_auth/settings.py. - """ - - from third_party_auth import settings as auth_settings - auth_settings.apply_settings(settings) From 54441488dcaced5edc537b73802c99ae5d83d2b4 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Fri, 20 Oct 2017 07:59:32 -0400 Subject: [PATCH 2/2] Add comments to docstring forbidding additional code. --- cms/startup.py | 3 +++ lms/startup.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cms/startup.py b/cms/startup.py index 17ac47474e..29b11e1716 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -23,6 +23,9 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement def run(): """ Executed during django startup + + NOTE: DO **NOT** add additional code to this method or this file! The Platform Team + is moving all startup code to more standard locations using Django best practices. """ django_db_models_options.patch() diff --git a/lms/startup.py b/lms/startup.py index 169976743c..05b4ff18f9 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -32,6 +32,9 @@ log = logging.getLogger(__name__) def run(): """ Executed during django startup + + NOTE: DO **NOT** add additional code to this method or this file! The Platform Team + is moving all startup code to more standard locations using Django best practices. """ django_db_models_options.patch()