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

Refactor update_userinfo

parent b6a5affc
......@@ -215,40 +215,49 @@ class User(AbstractUser):
def update_userinfo(self, userinfo):
if 'sub' not in userinfo:
raise Exception('Missing attribute in userinfo: sub')
self.userinfo = userinfo
groups = userinfo.get('groups', [])
# check if groups were removed
for group in self.groups.all():
if not in groups:'User left the group %s'), group)
# remove group from user and deactivate deployments
for dep in self.deployments.filter(group=group):'Deactivating, as user left the group'), group)
self.userinfo = userinfo
if 'sub' not in userinfo:
raise Exception('Missing attribute in userinfo: sub')
# check if groups were added
for group_name in groups:
group = None
group = Group.objects.get(name=group_name)
# check if user needs to be in this group
if not self.groups.filter(name=group_name).exists():'User is now in the group %s'), group)
for dep in self.deployments.filter(group=group):
except Group.DoesNotExist:'Adding group %s', group_name)'New group from IdP: %s', group_name)
group = Group(name=group_name)
for dep in self.deployments.filter(group=group):'Reactivating, as user is back in the group'), group)
from . import NewDeployment
dep = NewDeployment.get_deployment(self, group=group)
# include the ssh key from unity
unity_key_value = userinfo.get('ssh_key', '')
unity_key_name = 'unity_key'
Supports Markdown
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