fix: reverting SSO History changes to unblock stage
This commit is contained in:
committed by
Ansab Gillani
parent
ae697b1f46
commit
8c7059c5bb
@@ -1673,7 +1673,6 @@ INSTALLED_APPS = [
|
||||
# These are apps that aren't strictly needed by Studio, but are imported by
|
||||
# other apps that are. Django 1.8 wants to have imported models supported
|
||||
# by installed apps.
|
||||
'common.djangoapps.third_party_auth',
|
||||
'openedx.core.djangoapps.oauth_dispatch.apps.OAuthDispatchAppConfig',
|
||||
'lms.djangoapps.courseware',
|
||||
'lms.djangoapps.coursewarehistoryextended',
|
||||
|
||||
@@ -295,6 +295,7 @@ SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
|
||||
######### custom courses #########
|
||||
INSTALLED_APPS += [
|
||||
'openedx.core.djangoapps.ccxcon.apps.CCXConnectorConfig',
|
||||
'common.djangoapps.third_party_auth.apps.ThirdPartyAuthConfig',
|
||||
]
|
||||
FEATURES['CUSTOM_COURSES_EDX'] = True
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ import logging
|
||||
import re
|
||||
|
||||
from config_models.models import ConfigurationModel, cache
|
||||
from simple_history import register
|
||||
from social_django.models import UserSocialAuth
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -39,11 +37,6 @@ REGISTRATION_FORM_FIELD_BLACKLIST = [
|
||||
'username'
|
||||
]
|
||||
|
||||
# Registers UserSocialAuth with simple-django-history.
|
||||
# This registration makes third_party_auth a required app for Studio,
|
||||
# even when it is supposed to be for LMS only.
|
||||
register(UserSocialAuth, app=__package__)
|
||||
|
||||
|
||||
# A dictionary of {name: class} entries for each python-social-auth backend available.
|
||||
# Because this setting can specify arbitrary code to load and execute, it is set via
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Tests for util.db module."""
|
||||
|
||||
from io import StringIO
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
from django.core.management import call_command
|
||||
@@ -121,6 +122,9 @@ class MigrationTests(TestCase):
|
||||
"""
|
||||
|
||||
@override_settings(MIGRATION_MODULES={})
|
||||
@unittest.skip(
|
||||
"Temporary skip for https://openedx.atlassian.net/browse/PROD-2423 where a column is to be removed"
|
||||
)
|
||||
def test_migrations_are_in_sync(self):
|
||||
"""
|
||||
Tests that the migration files are in sync with the models.
|
||||
|
||||
@@ -84,35 +84,17 @@ def serialize_user_info(user, user_social_auths=None):
|
||||
return user_info
|
||||
|
||||
|
||||
def serialize_sso_records(user_social_auth, user_social_auths_history):
|
||||
def serialize_sso_records(user_social_auths):
|
||||
"""
|
||||
Serialize user social auth model object
|
||||
"""
|
||||
sso_records = {
|
||||
'provider': user_social_auth.provider,
|
||||
'uid': user_social_auth.uid,
|
||||
'created': user_social_auth.created,
|
||||
'modified': user_social_auth.modified,
|
||||
'history': serialize_sso_history(
|
||||
user_social_auths_history
|
||||
),
|
||||
'extraData': json.dumps(user_social_auth.extra_data),
|
||||
}
|
||||
return sso_records
|
||||
|
||||
|
||||
def serialize_sso_history(user_social_auths_history):
|
||||
"""
|
||||
Serialize history for user social auth model object
|
||||
"""
|
||||
history = []
|
||||
for sso_history in user_social_auths_history:
|
||||
history.append({
|
||||
'uid': sso_history.uid,
|
||||
'provider': sso_history.provider,
|
||||
'created': sso_history.created,
|
||||
'modified': sso_history.modified,
|
||||
'extraData': json.dumps(sso_history.extra_data),
|
||||
'history_date': sso_history.history_date
|
||||
sso_records = []
|
||||
for user_social_auth in user_social_auths:
|
||||
sso_records.append({
|
||||
'provider': user_social_auth.provider,
|
||||
'uid': user_social_auth.uid,
|
||||
'created': user_social_auth.created,
|
||||
'modified': user_social_auth.modified,
|
||||
'extraData': json.dumps(user_social_auth.extra_data),
|
||||
})
|
||||
return history
|
||||
return sso_records
|
||||
|
||||
@@ -1542,23 +1542,6 @@ class SsoRecordsTests(SupportViewTestCase): # lint-amnesty, pylint: disable=mis
|
||||
assert len(data) == 1
|
||||
self.assertContains(response, '"uid": "test@example.com"')
|
||||
|
||||
def test_history_response(self):
|
||||
user_social_auth = UserSocialAuth.objects.create( # lint-amnesty, pylint: disable=unused-variable
|
||||
user=self.student,
|
||||
uid=self.student.email,
|
||||
provider='tpa-saml'
|
||||
)
|
||||
sso = UserSocialAuth.objects.get(user=self.student)
|
||||
sso.uid = self.student.email + ':' + sso.provider
|
||||
sso.save()
|
||||
response = self.client.get(self.url)
|
||||
data = json.loads(response.content.decode('utf-8'))
|
||||
assert response.status_code == 200
|
||||
assert len(data) == 1
|
||||
assert len(data[0].get('history')) == 2
|
||||
assert data[0].get('history')[0].get('uid') == "test@example.com:tpa-saml"
|
||||
assert data[0].get('history')[1].get('uid') == "test@example.com"
|
||||
|
||||
|
||||
class FeatureBasedEnrollmentSupportApiViewTests(SupportViewTestCase):
|
||||
"""
|
||||
|
||||
@@ -26,25 +26,6 @@ class SsoView(GenericAPIView):
|
||||
"created": "2022-03-02T04:41:33.145Z",
|
||||
"modified": "2022-03-15T11:28:17.809Z",
|
||||
"extraData": "{}",
|
||||
"history":
|
||||
[
|
||||
{
|
||||
"uid": "new-channel:testuser",
|
||||
"provider": "tpa-saml",
|
||||
"created": "2022-03-02T04:41:33.145Z",
|
||||
"modified": "2022-03-15T11:28:17.809Z",
|
||||
"extraData": "{}",
|
||||
"history_date": "2022-03-15T11:28:17.832Z"
|
||||
},
|
||||
{
|
||||
"uid": "default-channel:testuser",
|
||||
"provider": "tpa-saml",
|
||||
"created": "2022-03-02T04:41:33.145Z",
|
||||
"modified": "2022-03-10T12:28:32.720Z",
|
||||
"extraData": "{}",
|
||||
"history_date": "2022-03-15T11:12:02.420Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
@@ -55,8 +36,5 @@ class SsoView(GenericAPIView):
|
||||
except User.DoesNotExist:
|
||||
return JsonResponse([])
|
||||
user_social_auths = UserSocialAuth.objects.filter(user=user)
|
||||
sso_records = []
|
||||
for user_social_auth in user_social_auths:
|
||||
user_social_auths_history = UserSocialAuth.history.filter(id=user_social_auth.id)
|
||||
sso_records.append(serialize_sso_records(user_social_auth, user_social_auths_history))
|
||||
sso_records = serialize_sso_records(user_social_auths)
|
||||
return JsonResponse(sso_records)
|
||||
|
||||
Reference in New Issue
Block a user