Commit abbdb6ba authored by redmitry@list.ru's avatar redmitry@list.ru

also process challenge roles

parent a711c1ba
......@@ -84,13 +84,16 @@ def updatePrivileges(headers):
if (community_id != None):
addContactToCommunity(groups, user, community_id, headers)
else:
r = role.get('role')
challenge_id = role.get('challenge_id')
if (r != None and challenge_id != None):
addContactToChallenge(user, r, challenge_id, headers)
# Assigns the user to the community group (owner)
def addContactToCommunity(groups, user, community_id, headers):
print('adding user ' + user['username'] + ' to the community ' + community_id)
for group in groups:
attributes = group['attributes']
roles = attributes.get('roles')
......@@ -99,6 +102,23 @@ def addContactToCommunity(groups, user, community_id, headers):
if (role.startswith('owner:') and community_id == role[6:]):
addKeycloakUserToGroup(user, group, headers)
# Assigns the user role to the challenge
def addContactToChallenge(user, role, challenge_id, headers):
print('adding user ' + role + ':' + user['username'] + ' to the challenge ' + challenge_id)
r = role + ':' + challenge_id
attributes = user['attributes']
rz = attributes.get('roles')
if (rz == None):
attributes['roles'] = [r]
updateKeycloakUser(user, headers)
elif (not r in rz):
rz.append(r)
updateKeycloakUser(user, headers)
# Update the openebench community ('group')
def updateCommunityGroup(group, headers):
......@@ -217,6 +237,7 @@ def addKeycloakUserToGroup(user, group, headers):
if(user_res.getcode() >= 400):
print("error assigning the user to a group", user_req)
# Get OpenEBench communities via the REST API
def getOpenebenchCommunities():
......
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