Hotfix 2
This commit is contained in:
@@ -9,7 +9,7 @@ urlpatterns = [
|
|||||||
name="create-post",
|
name="create-post",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"/<uuid:post_id>",
|
"/<str:post_id>",
|
||||||
api.posts.views.PostDetailApiView.as_view(),
|
api.posts.views.PostDetailApiView.as_view(),
|
||||||
name="post-detail",
|
name="post-detail",
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from rest_framework import serializers, status
|
from rest_framework import serializers, status
|
||||||
from rest_framework.exceptions import NotFound, ValidationError
|
from rest_framework.exceptions import NotFound, ValidationError
|
||||||
from rest_framework.generics import ListAPIView
|
from rest_framework.generics import ListAPIView
|
||||||
@@ -26,6 +28,11 @@ class PostDetailApiView(APIView):
|
|||||||
permission_classes = [IsAuthenticated, CanAccessPost]
|
permission_classes = [IsAuthenticated, CanAccessPost]
|
||||||
|
|
||||||
def get(self, request, post_id):
|
def get(self, request, post_id):
|
||||||
|
try:
|
||||||
|
uuid.UUID(post_id)
|
||||||
|
except ValueError:
|
||||||
|
raise NotFound from None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
post = Post.objects.get(id=post_id)
|
post = Post.objects.get(id=post_id)
|
||||||
self.check_object_permissions(request, post)
|
self.check_object_permissions(request, post)
|
||||||
@@ -90,6 +97,11 @@ class LikePostApiView(APIView):
|
|||||||
permission_classes = [IsAuthenticated, CanAccessPost]
|
permission_classes = [IsAuthenticated, CanAccessPost]
|
||||||
|
|
||||||
def post(self, request, post_id):
|
def post(self, request, post_id):
|
||||||
|
try:
|
||||||
|
uuid.UUID(post_id)
|
||||||
|
except ValueError:
|
||||||
|
raise NotFound from None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
post = Post.objects.get(id=post_id)
|
post = Post.objects.get(id=post_id)
|
||||||
self.check_object_permissions(request, post)
|
self.check_object_permissions(request, post)
|
||||||
@@ -108,6 +120,11 @@ class DislikePostApiView(APIView):
|
|||||||
permission_classes = [IsAuthenticated, CanAccessPost]
|
permission_classes = [IsAuthenticated, CanAccessPost]
|
||||||
|
|
||||||
def post(self, request, post_id):
|
def post(self, request, post_id):
|
||||||
|
try:
|
||||||
|
uuid.UUID(post_id)
|
||||||
|
except ValueError:
|
||||||
|
raise NotFound from None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
post = Post.objects.get(id=post_id)
|
post = Post.objects.get(id=post_id)
|
||||||
self.check_object_permissions(request, post)
|
self.check_object_permissions(request, post)
|
||||||
|
|||||||
Reference in New Issue
Block a user