Commit 1ac44034 authored by Lukas Burgey's avatar Lukas Burgey

Remove unique_username from User

parent 1408eb8b
......@@ -468,7 +468,6 @@ class NewDeploymentStateItem(models.Model):
try:
credential_state = self.credential_states.get(credential=credential)
credential_state.credential_deleted()
self.parent.publish()
except CredentialState.DoesNotExist:
LOGGER.error(self.msg('Credential {} has no CredentialState'.format(credential)))
......
......@@ -126,19 +126,12 @@ class User(AbstractUser):
except cls.DoesNotExist:
return cls.construct_from_userinfo(userinfo, idp)
@staticmethod
def unique_username(userinfo, idp):
if 'sub' not in userinfo:
raise ValueError("unique_username needs a 'sub' in the userinfo")
return "{}@{}".format(userinfo['sub'], idp.id)
@classmethod
def construct_from_userinfo(cls, userinfo, idp):
if 'sub' not in userinfo:
raise ValueError('Missing attribute in userinfo: sub')
username = cls.unique_username(userinfo, idp)
username = '{}@{}'.format(userinfo['sub'], idp.id)
if cls.objects.filter(
username=username,
......@@ -310,14 +303,15 @@ class User(AbstractUser):
# is the idp key changed?
if key.key != unity_key_value:
key.delete_key()
key = SSHPublicKey(
self.user_changed_key_removed(key)
new_key = SSHPublicKey(
name=unity_key_name,
key=unity_key_value,
user=self,
)
key.save()
self.user_changed_key_changed(key)
new_key.save()
self.user_changed_key_added(new_key)
return True
......@@ -362,27 +356,15 @@ class User(AbstractUser):
if changed:
self.user_changed()
# TODO implement
def user_changed(self):
LOGGER.info('user_changed')
pass
# TODO implement all user_changed_ triggers
# The user_changed methods are triggerd in user_changed
# They serve to assure the correct state at the backend and clients
#
def user_changed_key_added(self, key):
LOGGER.debug('user_changed_key_added: %s %s', self, key)
for dep in self.deployments.all():
dep.user_credential_added(key)
def user_changed_key_changed(self, key):
LOGGER.debug('user_changed_key_changed: %s %s', self, key)
for credential_state in key.credential_states.all():
LOGGER.debug('user_changed_key_changed: need to handle credential state %s', credential_state)
def user_changed_key_removed(self, key):
LOGGER.debug('user_changed_key_removed: %s %s', self, key)
......
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