Skip to content

Commit

Permalink
refact: include list mixin with generic scoped model viewset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 9, 2025
1 parent 4846699 commit bf223b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 3 additions & 4 deletions chord_metadata_service/authz/viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from .permissions import BentoDataTypePermission

__all__ = [
"BentoAuthzScopedModelGenericViewSet",
"BentoAuthzScopedModelGenericListViewSet",
"BentoAuthzScopedModelViewSet",
]


class BentoAuthzScopedModelGenericViewSet(viewsets.GenericViewSet):
class BentoAuthzScopedModelGenericListViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
"""
An extension of the DRF generic viewset which adds utility functions for Bento Django permissions classes.
These work together to properly implement scoped Bento permissions based on the request being made.
Expand Down Expand Up @@ -67,8 +67,7 @@ class BentoAuthzScopedModelViewSet(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin,
BentoAuthzScopedModelGenericViewSet
BentoAuthzScopedModelGenericListViewSet
):
"""
This class is equivalent to the DRF viewsets.ModelViewSet class, except with our BentoAuthzModelGenericViewSet
Expand Down
6 changes: 3 additions & 3 deletions chord_metadata_service/experiments/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from bento_lib.auth.permissions import P_QUERY_DATA
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import mixins, serializers, status
from rest_framework import serializers, status
from rest_framework.settings import api_settings
from rest_framework.decorators import api_view, permission_classes
from rest_framework.request import Request as DrfRequest
from rest_framework.response import Response

from chord_metadata_service.authz.permissions import BentoAllowAny
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericViewSet
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericListViewSet
from chord_metadata_service.chord.data_types import DATA_TYPE_EXPERIMENT
from chord_metadata_service.discovery.scope import get_request_discovery_scope
from chord_metadata_service.restapi.api_renderers import (
Expand Down Expand Up @@ -72,7 +72,7 @@ async def get_queryset(self):
)


class ExperimentBatchViewSet(mixins.ListModelMixin, BentoAuthzScopedModelGenericViewSet):
class ExperimentBatchViewSet(BentoAuthzScopedModelGenericListViewSet):
"""
get:
Return a list of all existing experiments
Expand Down
6 changes: 3 additions & 3 deletions chord_metadata_service/patients/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
from django.http.request import QueryDict
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import filters, mixins, serializers, status
from rest_framework import filters, serializers, status
from rest_framework.decorators import action
from rest_framework.request import Request as DrfRequest
from rest_framework.response import Response
from rest_framework.settings import api_settings

from chord_metadata_service.authz.middleware import authz_middleware
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericViewSet
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericListViewSet
from chord_metadata_service.authz.types import DataTypeDiscoveryPermissions
from chord_metadata_service.chord import data_types as dts
from chord_metadata_service.discovery import responses as dres
Expand Down Expand Up @@ -167,7 +167,7 @@ def phenopackets(self, request: DrfRequest, *_args, **_kwargs):
)


class IndividualBatchViewSet(mixins.ListModelMixin, BentoAuthzScopedModelGenericViewSet):
class IndividualBatchViewSet(BentoAuthzScopedModelGenericListViewSet):

serializer_class = IndividualSerializer
pagination_class = BatchResultsSetPagination
Expand Down
9 changes: 3 additions & 6 deletions chord_metadata_service/phenopackets/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from bento_lib.auth.permissions import P_QUERY_DATA
from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import mixins, serializers, status
from rest_framework import serializers, status
from rest_framework.settings import api_settings
from rest_framework.decorators import api_view, permission_classes
from rest_framework.request import Request as DrfRequest
from rest_framework.response import Response

from chord_metadata_service.authz.permissions import BentoAllowAny
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericViewSet
from chord_metadata_service.authz.viewset import BentoAuthzScopedModelViewSet, BentoAuthzScopedModelGenericListViewSet
from chord_metadata_service.chord.data_types import DATA_TYPE_PHENOPACKET
from chord_metadata_service.discovery.scope import get_request_discovery_scope
from chord_metadata_service.restapi.api_renderers import (
Expand Down Expand Up @@ -62,10 +62,7 @@ async def get_queryset(self):
)


class BiosampleBatchViewSet(
mixins.ListModelMixin,
BentoAuthzScopedModelGenericViewSet,
):
class BiosampleBatchViewSet(BentoAuthzScopedModelGenericListViewSet):
"""
get:
Return a list of all existing biosamples
Expand Down

0 comments on commit bf223b8

Please sign in to comment.