Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YDA-5470 - Tested invitation flows in SRAM acceptance environment #341

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,17 +1145,16 @@ def api_group_delete(ctx, group_name):
# Delete SRAM collaboration if group is a SRAM group.
if config.enable_sram:
sram_group, co_identifier = sram_enabled(ctx, group_name)
if sram_group:
if sram.sram_delete_collaboration(ctx, co_identifier):
return api.Error('sram_error', 'Something went wrong deleting group "{}"'.format(group_name))

response = ctx.uuGroupRemove(group_name, '', '')['arguments']
status = response[1]
message = response[2]
if status == '0':
return api.Result.ok()
else:
if status != '0':
return api.Error('policy_error', message)

if sram_group:
if not sram.sram_delete_collaboration(ctx, co_identifier):
return api.Error('sram_error', 'Something went wrong deleting group "{}" in SRAM'.format(group_name))
except Exception:
return api.Error('error_internal', 'Something went wrong deleting group "{}". Please contact a system administrator'.format(group_name))

Expand Down Expand Up @@ -1248,7 +1247,7 @@ def api_group_user_update_role(ctx, username, group_name, new_role):
if uid == '':
return api.Error('sram_error', 'Something went wrong getting the unique user id for user {} from SRAM. Please contact a system administrator.'.format(username))
else:
if sram.sram_update_collaboration_membership(ctx, co_identifier, uid, new_role):
if not sram.sram_update_collaboration_membership(ctx, co_identifier, uid, new_role):
return api.Error('sram_error', 'Something went wrong updating role for {} user.'.format(username))

response = ctx.uuGroupUserChangeRole(group_name, username, new_role, '', '')['arguments']
Expand Down Expand Up @@ -1289,21 +1288,20 @@ def api_group_remove_user_from_group(ctx, username, group_name):
try:
if config.enable_sram:
sram_group, co_identifier = sram_enabled(ctx, group_name)
if sram_group:
uid = sram.sram_get_uid(ctx, co_identifier, username)
if uid == '':
return api.Error('sram_error', 'Something went wrong getting the unique user id for user {} from SRAM. Please contact a system administrator.'.format(username))
else:
if sram.sram_delete_collaboration_membership(ctx, co_identifier, uid):
return api.Error('sram_error', 'Something went wrong removing {} from group "{}"'.format(username, group_name))

response = ctx.uuGroupUserRemove(group_name, username, '', '')['arguments']
status = response[2]
message = response[3]
if status == '0':
return api.Result.ok()
else:
if status != '0':
return api.Error('policy_error', message)

if sram_group:
uid = sram.sram_get_uid(ctx, co_identifier, username)
if uid == '':
return api.Error('sram_error', 'Something went wrong getting the unique user id for user {} from SRAM. Please contact a system administrator.'.format(username))
else:
if not sram.sram_delete_collaboration_membership(ctx, co_identifier, uid):
return api.Error('sram_error', 'Something went wrong removing {} from group "{}" in SRAM'.format(username, group_name))
except Exception:
return api.Error('error_internal', 'Something went wrong removing {} from group "{}". Please contact a system administrator'.format(username, group_name))

Expand Down
9 changes: 4 additions & 5 deletions sram.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ def sram_put_collaboration_invitation(ctx, group_name, username, co_identifier):
# Get epoch expiry date.
date = datetime.datetime.strptime(expiration_date, "%Y-%m-%d")
epoch = datetime.datetime.utcfromtimestamp(0)
epoch_date = int((date - epoch).total_seconds())
epoch_date = int((date - epoch).total_seconds()) * 1000

# Build SRAM payload.
payload = {
"short_name": group_name,
"collaboration_identifier": co_identifier,
"message": "Invitation to join Yoda group {}".format(group_name),
"intended_role": "member",
Expand All @@ -176,9 +175,9 @@ def sram_put_collaboration_invitation(ctx, group_name, username, co_identifier):
}

if config.sram_verbose_logging:
log.write(ctx, "post {}: {}".format(url, payload))
log.write(ctx, "put {}: {}".format(url, payload))

response = requests.post(url, json=payload, headers=headers, timeout=30, verify=config.sram_tls_verify)
response = requests.put(url, json=payload, headers=headers, timeout=30, verify=config.sram_tls_verify)

if config.sram_verbose_logging:
log.write(ctx, "response: {}".format(response.status_code))
Expand Down Expand Up @@ -244,4 +243,4 @@ def sram_update_collaboration_membership(ctx, co_identifier, uuid, new_role):
if config.sram_verbose_logging:
log.write(ctx, "response: {}".format(response.status_code))

return response.status_code == 204
return response.status_code == 201