Skip to content

Commit

Permalink
API for event application for own events
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurr0y committed Jan 21, 2024
1 parent d8b8234 commit df3d09a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/events/customPermissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework.permissions import BasePermission

class OwnApplicationPermission(BasePermission):
"""
Object-level permission to only allow updating his own profile
"""
def has_object_permission(self, request, view, obj):
return obj.event_applicant == request.user
1 change: 1 addition & 0 deletions src/events/serializers/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class EventApplicationSerializer(serializers.ModelSerializer):
class Meta:
model = EventApplication
fields = '__all__'
depth = 1

class TicketSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
11 changes: 8 additions & 3 deletions src/events/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from events.models.participant import Participant
from events.models.application import EventApplication
from events.models.ticket import Ticket
from events.customPermissions import OwnApplicationPermission

class CostsViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = CostsSerializer
Expand All @@ -22,10 +23,14 @@ class ParticipantViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = [IsAuthenticatedOrReadOnly]
queryset = Participant.objects.all()

class EventApplicationViewSet(viewsets.ReadOnlyModelViewSet):
class EventApplicationViewSet(viewsets.ModelViewSet):
serializer_class = EventApplicationSerializer
permission_classes = [IsAuthenticatedOrReadOnly]
queryset = EventApplication.objects.all()
permission_classes = [IsAuthenticated, OwnApplicationPermission]

def get_queryset(self):
user = self.request.user
queryset = EventApplication.objects.filter(event_applicant=user)
return queryset

class TicketViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = TicketSerializer
Expand Down

0 comments on commit df3d09a

Please sign in to comment.