Skip to content

Commit

Permalink
feat: Добавил jwt-аутентификацию и доступ по роли курьера.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonVagabond committed Mar 4, 2024
1 parent a29eecf commit ea77329
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions delivers/views/vehicle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from drf_spectacular.utils import extend_schema_view, extend_schema
from rest_framework import permissions
from rest_framework_simplejwt import authentication as jwt_authentication

from common.views.mixins import CRUDListViewSet
from delivers.models.couriers import Vehicle
from delivers.serializers.api import vehicle as vehicle_s
from ..models.couriers import Vehicle
from ..permission import couriers as permissions_cour
from ..serializers.api import vehicle as vehicle_s


@extend_schema_view(
Expand All @@ -30,11 +31,17 @@
)
class VehicleViewSet(CRUDListViewSet):
"""Представление транспорта."""

queryset = Vehicle.objects.all()

permission_classes = (permissions.IsAuthenticated,)
authentication_classes = (jwt_authentication.JWTAuthentication,)

permission_classes = (permissions_cour.IsCourierOrStaff,)
multi_permission_classes = {
'partial_update': (permissions_cour.IsCurrentCourierOrStaff,),
'destroy': (permissions_cour.IsCurrentCourierOrStaff,),
}

permission_classes = (permissions.IsAuthenticated,)
multi_permission_classes = {
'create': (permissions.IsAdminUser,),
'retrieve': (permissions.AllowAny,),
Expand All @@ -43,14 +50,12 @@ class VehicleViewSet(CRUDListViewSet):
'list': (permissions.AllowAny,)
}

http_method_names = ('get', 'patch', 'post', 'delete')

serializer_class = vehicle_s.VehicleListSerializer

multi_serializer_class = {
'create': vehicle_s.VehicleCreateSerializer,
'retrieve': vehicle_s.VehicleRetrieveSerializer,
'partial_update': vehicle_s.VehicleUpdateSerializer,
'destroy': vehicle_s.VehicleDeleteSerializer,
'list': vehicle_s.VehicleListSerializer
}
http_method_names = ('get', 'patch', 'post', 'delete')

0 comments on commit ea77329

Please sign in to comment.