Skip to content

Commit

Permalink
Fold the new endpoint into the old one, but triggered if userID is "me"
Browse files Browse the repository at this point in the history
  • Loading branch information
OrdiNeu committed Dec 19, 2024
1 parent 2773da6 commit ab21bca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
13 changes: 1 addition & 12 deletions ingest_openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,14 @@ paths:
application/json:
schema:
type: object
/user/self/authorize:
get:
summary: List own program authorizations
description: List authorizations for programs for the authenticated user
operationId: ingest_operations.list_programs_for_self
responses:
200:
description: Success
content:
application/json:
schema:
type: object
/user/{user_id}/authorize:
parameters:
- in: path
name: user_id
schema:
type: string
required: true
description: The user ID to check. If "me", return information about the requesting user
get:
summary: List program authorizations
description: List authorizations for programs for a user
Expand Down
25 changes: 15 additions & 10 deletions ingest_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,29 +362,34 @@ def clear_pending_users():
# DAC authorization for users
####

@app.route('/user/self/authorize')
def list_programs_for_self():
token = connexion.request.headers['Authorization'].split("Bearer ")[1]
def list_programs_for_self(token):
response, status_code = auth.get_self_in_opa(token)
if status_code == 404:
# We next check if the user is pending
response, status_code = auth.is_self_pending(token)
# NB: The results is a string if unauthorized or pending, and a list otherwise
return {"results": "Pending" if response else "Unauthorized"}, status_code
return "Pending" if response else "Unauthorized", status_code
print(response)
# NB: The results is a list if authorized, and a string otherwise
return {"results": list(response["programs"].values())}, status_code
return list(response["programs"].values()), status_code


@app.route('/user/<path:user_id>/authorize')
def list_programs_for_user(user_id):
token = connexion.request.headers['Authorization'].split("Bearer ")[1]
user_name = urllib.parse.unquote_plus(user_id)
response, status_code = auth.get_user_in_opa(user_name, token)
if status_code != 200:
return response, status_code
response = ""
status_code = 0
if user_id == "me":
# Grab the user's own authorization
response, status_code = list_programs_for_self(token)
else:
user_name = urllib.parse.unquote_plus(user_id)
response, status_code = auth.get_user_in_opa(user_name, token)
if status_code != 200:
return response, status_code
response = list(response["programs"].values())
print(response)
return {"results": list(response["programs"].values())}, status_code
return {"results": response}, status_code


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

0 comments on commit ab21bca

Please sign in to comment.