Skip to content

Commit

Permalink
fix: default settings implemented for permissions and authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
popeye88 committed Dec 8, 2024
1 parent 1996eb0 commit 3a61b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
14 changes: 0 additions & 14 deletions cinema/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime

from django.db.models import Count, F
from rest_framework.authentication import TokenAuthentication
from rest_framework.mixins import (
CreateModelMixin,
DestroyModelMixin,
Expand All @@ -14,7 +13,6 @@
from rest_framework.viewsets import GenericViewSet

from cinema.models import Actor, CinemaHall, Genre, Movie, MovieSession, Order
from cinema.permissions import IsAdminOrIfAuthenticatedReadOnly
from cinema.serializers import (
ActorSerializer,
CinemaHallSerializer,
Expand All @@ -37,8 +35,6 @@ class GenreViewSet(
):
queryset = Genre.objects.all()
serializer_class = GenreSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)


class ActorViewSet(
Expand All @@ -48,15 +44,11 @@ class ActorViewSet(
):
queryset = Actor.objects.all()
serializer_class = ActorSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)


class CinemaHallViewSet(ListModelMixin, CreateModelMixin, GenericViewSet):
queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)


class MovieViewSet(
Expand All @@ -67,8 +59,6 @@ class MovieViewSet(
):
queryset = Movie.objects.prefetch_related("genres", "actors")
serializer_class = MovieSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)

@staticmethod
def _params_to_ints(qs):
Expand Down Expand Up @@ -124,8 +114,6 @@ class MovieSessionViewSet(
)
)
serializer_class = MovieSessionSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)

def get_queryset(self):
date = self.request.query_params.get("date")
Expand Down Expand Up @@ -163,8 +151,6 @@ class OrderViewSet(ListModelMixin, CreateModelMixin, GenericViewSet):
)
serializer_class = OrderSerializer
pagination_class = OrderPagination
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)

def get_permissions(self):
if self.action == "create":
Expand Down
9 changes: 9 additions & 0 deletions cinema_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,12 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.TokenAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"cinema.permissions.IsAdminOrIfAuthenticatedReadOnly",
],
}

0 comments on commit 3a61b52

Please sign in to comment.