Skip to content

Commit

Permalink
correct handling for individual records by id
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Dec 4, 2023
1 parent ae0a1ac commit c0eca94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bento_beacon/endpoints/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from ..utils.search import biosample_id_search
from ..utils.handover_utils import handover_for_ids
from ..utils.exceptions import NotFoundException

individuals = Blueprint("individuals", __name__)

Expand Down Expand Up @@ -122,11 +123,18 @@ def individuals_full_results(ids):
return result_sets, numTotalResults


# forbidden / unauthorized if no permissions
@individuals.route("/individuals/<id>", methods=['GET', 'POST'])
@authz_middleware.deco_require_permissions_on_resource({P_QUERY_DATA})
def individual_by_id(id):
# forbidden / unauthorized if no permissions
return beacon_result_set_response([id], 1)
result_sets, numTotalResults = individuals_full_results([id])

# return 404 if not found
# only authorized users will get 404 here, so this can't be used to probe ids
if not result_sets:
raise NotFoundException()

return beacon_result_set_response(result_sets, numTotalResults)


# -------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions bento_beacon/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ def __init__(self, message="Invalid query", status_code=400):
self.message = message
self.status_code = status_code


class NotFoundException(APIException):
def __init__(self, message="Not found", status_code=404):
super().__init__()
self.message = message
self.status_code = status_code

0 comments on commit c0eca94

Please sign in to comment.