Commit edeba838 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add change detection to update_userinfo

parent 27adaffe
......@@ -233,6 +233,7 @@ class User(AbstractUser):
def update_userinfo_groups(self, userinfo):
changed = False
groups = userinfo.get('groups', [])
# check if groups were removed
......@@ -246,6 +247,9 @@ class User(AbstractUser):'Deactivating, as user left the group'), group)
if not changed:
changed = True
# check if groups were added
for group_name in groups:
group = None
......@@ -259,6 +263,9 @@ class User(AbstractUser):
for dep in self.deployments.filter(group=group):
if not changed:
changed = True
except Group.DoesNotExist:'New group from IdP: %s', group_name)
group = Group(name=group_name)
......@@ -269,6 +276,11 @@ class User(AbstractUser):'Reactivating, as user is back in the group'), group)
if not changed:
changed = True
return changed
def update_userinfo_ssh_key(self, userinfo):
unity_key_value = userinfo.get('ssh_key', '')
unity_key_name = 'unity_key'
......@@ -276,8 +288,19 @@ class User(AbstractUser):
key = self._ssh_keys.get(name=unity_key_name)
if key.key != unity_key_value:
LOGGER.debug('unity_key of user %s changed', self)
raise SSHPublicKey.DoesNotExist()
key = SSHPublicKey(
# changed
return True
# not changed
return False
except SSHPublicKey.DoesNotExist:
key = SSHPublicKey(
......@@ -287,7 +310,11 @@ class User(AbstractUser):
# changed
return True
def update_userinfo(self, userinfo):
if 'email' in userinfo: = userinfo['email']
......@@ -299,13 +326,22 @@ class User(AbstractUser):
self.userinfo = userinfo
changed = False
if self.update_userinfo_groups(userinfo):
changed = True
if self.update_userinfo_ssh_key(userinfo):
changed = True
if changed:
LOGGER.debug('update_userinfo caused changes to the user')
# TODO implement
# The user object was changed.
# Call if the user or its keys are changed
def user_changed(self):
LOGGER.debug('User changed. Propagating changes')
......@@ -334,30 +370,13 @@ class SSHPublicKey(models.Model):
# somewhere
# the receiver 'delete_removen_ssh_key' does the actual deletion
def delete_key(self):'Deletion of key started'))
self.deleted = True
#'Deletion of key started'))
# self.deleted = True
#'Direct deletion of SSH key')
# delete implies removeing the key from all clients
# TODO dep don't have remove_key anymore
#for dep in self.user.deployments.all():
# dep.remove_key(self)
# when a key is removed by a client we try to finally delete it
def try_final_deletion(self):
if self.deleted:
if not self.deployed_anywhere:'All clients have removen this key. Final deletion'))
def _final_deletion(self):
_self = self
for dep in self.deployments.all():
#for item in state.state_items.all():
# item.delete()
# we do not update the user object from here: update_userinfo does that anyway
def __str__(self):
if self.deleted:
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