Synd HEP data

This commit is contained in:
Christian Cueni 2020-02-26 11:12:13 +01:00
parent 4e2c47d00a
commit a5e1b323a2
3 changed files with 22 additions and 7 deletions

View File

@ -66,6 +66,26 @@ class User(AbstractUser):
else:
return None
def sync_with_hep_data(self, hep_data):
data_has_changed = False
if self.email != hep_data['email']:
self.email = hep_data['email']
self.username = hep_data['email']
data_has_changed = True
if self.first_name != hep_data['firstname']:
self.first_name = hep_data['firstname']
data_has_changed = True
if self.last_name != hep_data['lastname']:
self.last_name = hep_data['lastname']
data_has_changed = True
if data_has_changed:
self.save()
@property
def full_name(self):
return self.get_full_name()

View File

@ -67,12 +67,7 @@ class Login(relay.ClientIDMutation):
return cls.return_login_message(UNKNOWN_ERROR)
user, status_msg = handle_user_and_verify_products(user_data)
# sync email if user changed it on hep account
if user.email != user_data['email']:
user.email = user_data['email']
user.username = user_data['email']
user.save()
user.sync_with_hep_data(user_data)
if user and status_msg != EMAIL_NOT_VERIFIED:
login(info.context, user)

View File

@ -102,7 +102,7 @@ class LoginTests(TestCase):
self.assertEqual(reloaded_user.license_expiry_date, expiry_date2.date())
@patch.object(HepClient, 'customer_me', return_value=ME_DATA)
def test_user_can_login_with_updated_email(self, me_mock):
def test_user_data_is_synced_on_login(self, me_mock):
old_mail = 'aschi@iterativ.ch'