Skip to content

Commit

Permalink
chore: allow override of checked permission for POST-query-data reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 1, 2024
1 parent d435acd commit 3b3b991
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion chord_metadata_service/authz/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ async def view_request_has_data_type_permission(

p: Permission

if request.method == "GET":
if (p_to_check := getattr(request, "permission_to_check", None)) is not None:
p = p_to_check
elif request.method == "GET":
p = P_QUERY_DATA
elif request.method in ("POST", "PUT"):
p = P_INGEST_DATA
Expand Down
10 changes: 9 additions & 1 deletion chord_metadata_service/patients/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from adrf.views import APIView
from asgiref.sync import async_to_sync
from bento_lib.auth.permissions import P_QUERY_DATA
from bento_lib.responses import errors
from bento_lib.search import build_search_response
from copy import deepcopy
Expand Down Expand Up @@ -149,10 +150,17 @@ def list(self, request, *args, **kwargs):

@action(detail=True, methods=["GET", "POST"])
def phenopackets(self, request: DrfRequest, *_args, **_kwargs):
# ensure we have permissions for getting/posting (both are reading data)
# - override permission to check for POST request, as we're querying data not writing it here.
request.permission_to_check = P_QUERY_DATA
self.check_permissions(request)

scope = async_to_sync(get_request_discovery_scope)(request)

individual = self.get_object()

phenopackets = (
Phenopacket.objects
Phenopacket.get_model_scoped_queryset(scope)
.filter(subject=individual)
.prefetch_related(*PHENOPACKET_PREFETCH)
.order_by("id")
Expand Down

0 comments on commit 3b3b991

Please sign in to comment.