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

correct handling for individual records by id #64

Merged
merged 1 commit into from
Dec 5, 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
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