From 8c7059c5bbc40579435fee5794aa9dae914baa3c Mon Sep 17 00:00:00 2001 From: ansabgillani Date: Wed, 27 Apr 2022 20:17:11 +0500 Subject: [PATCH] fix: reverting SSO History changes to unblock stage --- cms/envs/common.py | 1 - cms/envs/test.py | 1 + common/djangoapps/third_party_auth/models.py | 7 ---- common/djangoapps/util/tests/test_db.py | 4 +++ lms/djangoapps/support/serializers.py | 38 ++++++-------------- lms/djangoapps/support/tests/test_views.py | 17 --------- lms/djangoapps/support/views/sso_records.py | 24 +------------ 7 files changed, 16 insertions(+), 76 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 1e55de90b9..d05ef07b6f 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -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', diff --git a/cms/envs/test.py b/cms/envs/test.py index 09cb504f7e..a42b73336a 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -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 diff --git a/common/djangoapps/third_party_auth/models.py b/common/djangoapps/third_party_auth/models.py index 4cd636dedb..f0a37616a3 100644 --- a/common/djangoapps/third_party_auth/models.py +++ b/common/djangoapps/third_party_auth/models.py @@ -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 diff --git a/common/djangoapps/util/tests/test_db.py b/common/djangoapps/util/tests/test_db.py index 4a16c2a20a..bea01df633 100644 --- a/common/djangoapps/util/tests/test_db.py +++ b/common/djangoapps/util/tests/test_db.py @@ -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. diff --git a/lms/djangoapps/support/serializers.py b/lms/djangoapps/support/serializers.py index f1a28640ca..0d4daa83e9 100644 --- a/lms/djangoapps/support/serializers.py +++ b/lms/djangoapps/support/serializers.py @@ -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 diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index 57c36ffb11..a6b8e43947 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -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): """ diff --git a/lms/djangoapps/support/views/sso_records.py b/lms/djangoapps/support/views/sso_records.py index 3649575320..372a4f4c53 100644 --- a/lms/djangoapps/support/views/sso_records.py +++ b/lms/djangoapps/support/views/sso_records.py @@ -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)