From 7504be1c67431e84999294ad6e703994db50db61 Mon Sep 17 00:00:00 2001 From: zubair-arbi Date: Mon, 1 Jan 2018 16:24:03 +0500 Subject: [PATCH] Remove username from force syncing in third party auth pipeline --- common/djangoapps/third_party_auth/pipeline.py | 3 +++ .../third_party_auth/tests/test_pipeline_integration.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index 4fd41e85da..02a578414b 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -751,6 +751,9 @@ def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **k 'country': (user.profile, 'country'), }) + # Remove username from list of fields for update + field_mapping.pop('username', None) + # Track any fields that would raise an integrity error if there was a conflict. integrity_conflict_fields = {'email': user.email, 'username': user.username} diff --git a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py index 953a6098bb..5d9ca5b6e3 100644 --- a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py +++ b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py @@ -379,10 +379,12 @@ class UserDetailsForceSyncTestCase(testutil.TestCase, test.TestCase): # User now has updated information in the DB. user = User.objects.get() assert user.email == 'new+{}'.format(self.old_email) - assert user.username == 'new_{}'.format(self.old_username) assert user.profile.name == 'Grown Up {}'.format(self.old_fullname) assert user.profile.country == 'PK' + # Now verify that username field is not updated + assert user.username == self.old_username + assert len(mail.outbox) == 1 def test_user_details_force_sync_email_conflict(self): @@ -403,10 +405,12 @@ class UserDetailsForceSyncTestCase(testutil.TestCase, test.TestCase): # The email is not changed, but everything else is. user = User.objects.get(pk=self.user.pk) assert user.email == self.old_email - assert user.username == 'new_{}'.format(self.old_username) assert user.profile.name == 'Grown Up {}'.format(self.old_fullname) assert user.profile.country == 'PK' + # Now verify that username field is not updated + assert user.username == self.old_username + # No email should be sent for an email change. assert len(mail.outbox) == 0