From 3a61b52ba6cf07d4df3bf55ded77bc4f6d47666b Mon Sep 17 00:00:00 2001 From: popeye88 Date: Sun, 8 Dec 2024 12:01:05 +0200 Subject: [PATCH] fix: default settings implemented for permissions and authorization --- cinema/views.py | 14 -------------- cinema_service/settings.py | 9 +++++++++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cinema/views.py b/cinema/views.py index 7b6c974b..253fa877 100644 --- a/cinema/views.py +++ b/cinema/views.py @@ -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, @@ -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, @@ -37,8 +35,6 @@ class GenreViewSet( ): queryset = Genre.objects.all() serializer_class = GenreSerializer - authentication_classes = (TokenAuthentication,) - permission_classes = (IsAdminOrIfAuthenticatedReadOnly,) class ActorViewSet( @@ -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( @@ -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): @@ -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") @@ -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": diff --git a/cinema_service/settings.py b/cinema_service/settings.py index af1bede4..3b31f8f6 100644 --- a/cinema_service/settings.py +++ b/cinema_service/settings.py @@ -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", + ], +}