Skip to content

Commit

Permalink
Creation, Deletion and Update of Application implemented, it only wor…
Browse files Browse the repository at this point in the history
…ks on own application
  • Loading branch information
ankurr0y committed Jan 19, 2024
1 parent f370981 commit d8b8234
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ class ReadCreateUpdate(BasePermission):
def has_permission(self, request, view):
return True if request.method not in ["DELETE"] else False

class OwnApplicationPermission(BasePermission):
"""
Object-level permission to only allow updating his own profile
"""
def has_object_permission(self, request, view, obj):
return obj.applicant == request.user
9 changes: 6 additions & 3 deletions src/involvement/views/application_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from rest_framework import viewsets
from rest_framework import viewsets, mixins
from involvement.serializers.application_serializer import ApplicationSerializer
from rest_framework.permissions import IsAuthenticated
from involvement.models.application import Application
from involvement.customPermissions import OwnApplicationPermission

#Role view
class ApplicationViewSet(viewsets.ReadOnlyModelViewSet):
class ApplicationViewSet(viewsets.ModelViewSet):
serializer_class = ApplicationSerializer
permission_classes = [IsAuthenticated]
permission_classes = [IsAuthenticated, OwnApplicationPermission]

def get_queryset(self):
user = self.request.user
queryset = Application.objects.filter(applicant=user)
return queryset


0 comments on commit d8b8234

Please sign in to comment.