Commit fc2b5401 by Clinton Blackburn Committed by Ned Batchelder

Upgraded to Python Social Auth 0.2.21 to resolve migration issue

(cherry picked from commit 14db9be0c25df477a43a358e37c37d3df9207230)
parent 0dd85460
...@@ -10,10 +10,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement ...@@ -10,10 +10,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement
from openedx.core.lib.django_startup import autostartup from openedx.core.lib.django_startup import autostartup
import django import django
from openedx.core.djangoapps.monkey_patch import ( from openedx.core.djangoapps.monkey_patch import django_db_models_options
third_party_auth,
django_db_models_options
)
from openedx.core.lib.xblock_utils import xblock_local_resource_url from openedx.core.lib.xblock_utils import xblock_local_resource_url
import xmodule.x_module import xmodule.x_module
...@@ -28,7 +25,6 @@ def run(): ...@@ -28,7 +25,6 @@ def run():
""" """
Executed during django startup Executed during django startup
""" """
third_party_auth.patch()
django_db_models_options.patch() django_db_models_options.patch()
# Comprehensive theming needs to be set up before django startup, # Comprehensive theming needs to be set up before django startup,
......
...@@ -44,11 +44,6 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method ...@@ -44,11 +44,6 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
log.error('SAML authentication is not enabled') log.error('SAML authentication is not enabled')
raise Http404 raise Http404
# TODO: remove this check once the fix is merged upstream:
# https://github.com/omab/python-social-auth/pull/821
if 'idp' not in self.strategy.request_data():
raise AuthMissingParameter(self, 'idp')
return super(SAMLAuthBackend, self).auth_url() return super(SAMLAuthBackend, self).auth_url()
def _check_entitlements(self, idp, attributes): def _check_entitlements(self, idp, attributes):
......
...@@ -412,8 +412,10 @@ class IntegrationTest(testutil.TestCase, test.TestCase): ...@@ -412,8 +412,10 @@ class IntegrationTest(testutil.TestCase, test.TestCase):
def assert_redirect_to_dashboard_looks_correct(self, response): def assert_redirect_to_dashboard_looks_correct(self, response):
"""Asserts a response would redirect to /dashboard.""" """Asserts a response would redirect to /dashboard."""
self.assertEqual(302, response.status_code) self.assertEqual(302, response.status_code)
# NOTE: Ideally we should use assertRedirects(), however it errors out due to the hostname, testserver,
# not being properly set. This may be an issue with the call made by PSA, but we are not certain.
# pylint: disable=protected-access # pylint: disable=protected-access
self.assertEqual(auth_settings._SOCIAL_AUTH_LOGIN_REDIRECT_URL, response.get('Location')) self.assertTrue(response.get('Location').endswith(django_settings.SOCIAL_AUTH_LOGIN_REDIRECT_URL))
def assert_redirect_to_login_looks_correct(self, response): def assert_redirect_to_login_looks_correct(self, response):
"""Asserts a response would redirect to /login.""" """Asserts a response would redirect to /login."""
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
import json import json
import httpretty import httpretty
from provider.constants import PUBLIC from provider.constants import PUBLIC
from provider.oauth2.models import Client from provider.oauth2.models import Client
from social.apps.django_app.default.models import UserSocialAuth from social.apps.django_app.default.models import UserSocialAuth
from social.backends.facebook import FacebookOAuth2
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from .testutil import ThirdPartyAuthTestMixin from .testutil import ThirdPartyAuthTestMixin
...@@ -81,7 +80,7 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin): ...@@ -81,7 +80,7 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin):
class ThirdPartyOAuthTestMixinFacebook(object): class ThirdPartyOAuthTestMixinFacebook(object):
"""Tests oauth with the Facebook backend""" """Tests oauth with the Facebook backend"""
BACKEND = "facebook" BACKEND = "facebook"
USER_URL = "https://graph.facebook.com/v2.3/me" USER_URL = FacebookOAuth2.USER_DATA_URL
# In facebook responses, the "id" field is used as the user's identifier # In facebook responses, the "id" field is used as the user's identifier
UID_FIELD = "id" UID_FIELD = "id"
......
...@@ -2159,11 +2159,6 @@ INSTALLED_APPS = ( ...@@ -2159,11 +2159,6 @@ INSTALLED_APPS = (
'database_fixups', 'database_fixups',
) )
# Migrations which are not in the standard module "migrations"
MIGRATION_MODULES = {
'social.apps.django_app.default': 'social.apps.django_app.default.south_migrations'
}
######################### CSRF ######################################### ######################### CSRF #########################################
# Forwards-compatibility with Django 1.7 # Forwards-compatibility with Django 1.7
......
...@@ -12,10 +12,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement ...@@ -12,10 +12,7 @@ settings.INSTALLED_APPS # pylint: disable=pointless-statement
from openedx.core.lib.django_startup import autostartup from openedx.core.lib.django_startup import autostartup
import logging import logging
import analytics import analytics
from openedx.core.djangoapps.monkey_patch import ( from openedx.core.djangoapps.monkey_patch import django_db_models_options
third_party_auth,
django_db_models_options
)
import xmodule.x_module import xmodule.x_module
import lms_xblock.runtime import lms_xblock.runtime
...@@ -33,7 +30,6 @@ def run(): ...@@ -33,7 +30,6 @@ def run():
""" """
Executed during django startup Executed during django startup
""" """
third_party_auth.patch()
django_db_models_options.patch() django_db_models_options.patch()
# To override the settings before executing the autostartup() for python-social-auth # To override the settings before executing the autostartup() for python-social-auth
......
"""
Monkey patch implementation for a python_social_auth Django ORM method that is not Django 1.8-compatible.
Remove once the module fully supports Django 1.8!
"""
from django.db import transaction
from social.storage.django_orm import DjangoUserMixin
from social.apps.django_app.default.models import (
UserSocialAuth, Nonce, Association, Code
)
def patch():
"""
Monkey-patch the DjangoUserMixin class.
"""
def create_social_auth_wrapper(wrapped_func):
# pylint: disable=missing-docstring
wrapped_func = wrapped_func.__func__
def _create_social_auth(*args, **kwargs):
# The entire reason for this monkey-patch is to wrap the create_social_auth call
# in an atomic transaction. The call can sometime raise an IntegrityError, which is
# caught and dealt with by python_social_auth - but not inside of an atomic transaction.
# In Django 1.8, unless the exception is raised in an atomic transaction, the transaction
# becomes unusable after the IntegrityError exception is raised.
with transaction.atomic():
return wrapped_func(*args, **kwargs)
return classmethod(_create_social_auth)
DjangoUserMixin.create_social_auth = create_social_auth_wrapper(DjangoUserMixin.create_social_auth)
# Monkey-patch some social auth models' Meta class to squelch Django19 warnings.
# pylint: disable=protected-access
UserSocialAuth._meta.app_label = "default"
Nonce._meta.app_label = "default"
Association._meta.app_label = "default"
Code._meta.app_label = "default"
...@@ -84,12 +84,7 @@ pymongo==2.9.1 ...@@ -84,12 +84,7 @@ pymongo==2.9.1
python-memcached==1.48 python-memcached==1.48
python-openid==2.2.5 python-openid==2.2.5
python-dateutil==2.1 python-dateutil==2.1
python-social-auth==0.2.21
# This module gets monkey-patched in third_party_auth.py to fix a Django 1.8 incompatibility.
# When this dependency gets upgraded, the monkey patch should be removed, if possible.
# We can also remove the fix to auth_url in third_party_auth/saml.py when that fix is included upstream.
python-social-auth==0.2.12
pytz==2016.7 pytz==2016.7
pysrt==0.4.7 pysrt==0.4.7
PyYAML==3.10 PyYAML==3.10
......
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