Skip to content

Commit

Permalink
list authz for user
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Jan 17, 2025
1 parent 499c2af commit 8997a58
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions ingest_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,28 @@ def list_authz_for_user(user_id):

if user_id == "me":
user_id = authx.auth.get_user_id(request)
response, status_code = authx.auth.get_user_in_opa(user_id)

user_result, status_code = authx.auth.get_user_in_opa(user_id)
if status_code != 200:
# We next check if the user is pending
response, status_code = authx.auth.is_user_pending(token)
# NB: The results is a string if unauthorized or pending, and a list otherwise
return "Pending" if response else "Unauthorized", status_code
response = list(response["programs"].values())
return {"results": response}, status_code
return user_result, status_code

user_result["site_roles"] = []
role_types, status_code = authx.auth.list_role_types_in_opa()
if status_code == 200:
for role_type in role_types:
users, status_code = authx.auth.get_role_type_in_opa(role_type)
if user_id in users[role_type]:
user_result["site_roles"].append(role_type)

user_result["program_authorizations"] = {}
opa_permissions, status_code = authx.auth.get_opa_permissions(user_result["userinfo"]["sample_jwt"])
if status_code == 200:
user_result["program_authorizations"]["team_member"] = opa_permissions["team_member_programs"]
user_result["program_authorizations"]["program_curator"] = opa_permissions["curator_programs"]

user_result["program_authorizations"]["dac_authorizations"] = user_result.pop("dac_authorizations")

return user_result, status_code


@app.route('/user/<path:user_id>')
Expand Down

0 comments on commit 8997a58

Please sign in to comment.