Skip to content

Commit d2c4f0c

Browse files
committed
Fix the bug that unpublished event would leak through /event/{id}
1 parent 1245a37 commit d2c4f0c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

server/game_dev/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ class EventDetailAPIView(generics.RetrieveAPIView):
6060
lookup_url_kwarg = "id"
6161

6262
def get_queryset(self):
63-
return Event.objects.filter(id=self.kwargs["id"])
63+
now = timezone.now().date()
64+
return Event.objects.filter(id=self.kwargs["id"], publicationDate__lte=now)
65+
66+
def get_object(self):
67+
queryset = self.get_queryset()
68+
try:
69+
return queryset.get()
70+
except Event.DoesNotExist:
71+
from rest_framework.exceptions import NotFound
72+
raise NotFound(detail="The event is not yet published by admin or does not exist.")
6473

6574

6675
class GameshowcaseAPIView(APIView):

0 commit comments

Comments
 (0)