-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rest_framework.permissions import BasePermission | ||
|
||
class ReadAndCreate(BasePermission): | ||
""" | ||
Authenticated user can create but not delete or update. | ||
""" | ||
def has_permission(self, request, view): | ||
return True if request.method in ["GET", "HEAD", "OPTIONS", "POST"] else False | ||
|
||
class ReadCreateUpdate(BasePermission): | ||
""" | ||
Authenticated user can create and update but not delete. | ||
""" | ||
def has_permission(self, request, view): | ||
return True if request.method not in ["DELETE"] else False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
from rest_framework import viewsets | ||
from rest_framework import viewsets, mixins | ||
from involvement.serializers.position_serializer import PositionSerializer, PositionDepthSerializer | ||
from rest_framework.permissions import IsAuthenticatedOrReadOnly | ||
from rest_framework.permissions import IsAuthenticatedOrReadOnly, | ||
from involvement.models.position import Position | ||
|
||
class PositionViewSet(viewsets.ModelViewSet): | ||
class PositionViewSet(viewsets.ReadOnlyModelViewSet): | ||
serializer_class = PositionSerializer | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
queryset = Position.objects.all() | ||
|
||
class Position2ViewSet(viewsets.ModelViewSet): | ||
class Position2ViewSet(viewsets.ReadOnlyModelViewSet): | ||
serializer_class = PositionDepthSerializer | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
queryset = Position.objects.all() |