mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
dev: updated error handling for project deploy board attributes (#2062)
* dev: updated error handling for project deploy board attributes * dev: reaction integrity handling
This commit is contained in:
parent
63d799310b
commit
874d6e951b
@ -21,7 +21,7 @@ from django.db.models import (
|
|||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.gzip import gzip_page
|
from django.views.decorators.gzip import gzip_page
|
||||||
from django.db.models.functions import Coalesce
|
from django.db import IntegrityError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
# Third Party imports
|
# Third Party imports
|
||||||
@ -1545,32 +1545,35 @@ class IssueCommentPublicViewSet(BaseViewSet):
|
|||||||
return super(IssueCommentPublicViewSet, self).get_permissions()
|
return super(IssueCommentPublicViewSet, self).get_permissions()
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(
|
try:
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
project_deploy_board = ProjectDeployBoard.objects.get(
|
||||||
project_id=self.kwargs.get("project_id"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
)
|
project_id=self.kwargs.get("project_id"),
|
||||||
if project_deploy_board.comments:
|
)
|
||||||
return self.filter_queryset(
|
if project_deploy_board.comments:
|
||||||
super()
|
return self.filter_queryset(
|
||||||
.get_queryset()
|
super()
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
.get_queryset()
|
||||||
.filter(issue_id=self.kwargs.get("issue_id"))
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
.filter(access="EXTERNAL")
|
.filter(issue_id=self.kwargs.get("issue_id"))
|
||||||
.select_related("project")
|
.filter(access="EXTERNAL")
|
||||||
.select_related("workspace")
|
.select_related("project")
|
||||||
.select_related("issue")
|
.select_related("workspace")
|
||||||
.annotate(
|
.select_related("issue")
|
||||||
is_member=Exists(
|
.annotate(
|
||||||
ProjectMember.objects.filter(
|
is_member=Exists(
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
ProjectMember.objects.filter(
|
||||||
project_id=self.kwargs.get("project_id"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
member_id=self.request.user.id,
|
project_id=self.kwargs.get("project_id"),
|
||||||
|
member_id=self.request.user.id,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.distinct()
|
||||||
)
|
)
|
||||||
.distinct()
|
else:
|
||||||
)
|
return IssueComment.objects.none()
|
||||||
else:
|
except ProjectDeployBoard.DoesNotExist:
|
||||||
return IssueComment.objects.none()
|
return IssueComment.objects.none()
|
||||||
|
|
||||||
def create(self, request, slug, project_id, issue_id):
|
def create(self, request, slug, project_id, issue_id):
|
||||||
@ -1703,21 +1706,24 @@ class IssueReactionPublicViewSet(BaseViewSet):
|
|||||||
model = IssueReaction
|
model = IssueReaction
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(
|
try:
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
project_deploy_board = ProjectDeployBoard.objects.get(
|
||||||
project_id=self.kwargs.get("project_id"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
)
|
project_id=self.kwargs.get("project_id"),
|
||||||
if project_deploy_board.reactions:
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(issue_id=self.kwargs.get("issue_id"))
|
|
||||||
.order_by("-created_at")
|
|
||||||
.distinct()
|
|
||||||
)
|
)
|
||||||
else:
|
if project_deploy_board.reactions:
|
||||||
|
return (
|
||||||
|
super()
|
||||||
|
.get_queryset()
|
||||||
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
|
.filter(project_id=self.kwargs.get("project_id"))
|
||||||
|
.filter(issue_id=self.kwargs.get("issue_id"))
|
||||||
|
.order_by("-created_at")
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return IssueReaction.objects.none()
|
||||||
|
except ProjectDeployBoard.DoesNotExist:
|
||||||
return IssueReaction.objects.none()
|
return IssueReaction.objects.none()
|
||||||
|
|
||||||
def create(self, request, slug, project_id, issue_id):
|
def create(self, request, slug, project_id, issue_id):
|
||||||
@ -1818,21 +1824,24 @@ class CommentReactionPublicViewSet(BaseViewSet):
|
|||||||
model = CommentReaction
|
model = CommentReaction
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
project_deploy_board = ProjectDeployBoard.objects.get(
|
try:
|
||||||
workspace__slug=self.kwargs.get("slug"),
|
project_deploy_board = ProjectDeployBoard.objects.get(
|
||||||
project_id=self.kwargs.get("project_id"),
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
)
|
project_id=self.kwargs.get("project_id"),
|
||||||
if project_deploy_board.reactions:
|
|
||||||
return (
|
|
||||||
super()
|
|
||||||
.get_queryset()
|
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
|
||||||
.filter(comment_id=self.kwargs.get("comment_id"))
|
|
||||||
.order_by("-created_at")
|
|
||||||
.distinct()
|
|
||||||
)
|
)
|
||||||
else:
|
if project_deploy_board.reactions:
|
||||||
|
return (
|
||||||
|
super()
|
||||||
|
.get_queryset()
|
||||||
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
|
.filter(project_id=self.kwargs.get("project_id"))
|
||||||
|
.filter(comment_id=self.kwargs.get("comment_id"))
|
||||||
|
.order_by("-created_at")
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return CommentReaction.objects.none()
|
||||||
|
except ProjectDeployBoard.DoesNotExist:
|
||||||
return CommentReaction.objects.none()
|
return CommentReaction.objects.none()
|
||||||
|
|
||||||
def create(self, request, slug, project_id, comment_id):
|
def create(self, request, slug, project_id, comment_id):
|
||||||
@ -1939,13 +1948,23 @@ class IssueVotePublicViewSet(BaseViewSet):
|
|||||||
serializer_class = IssueVoteSerializer
|
serializer_class = IssueVoteSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return (
|
try:
|
||||||
super()
|
project_deploy_board = ProjectDeployBoard.objects.get(
|
||||||
.get_queryset()
|
workspace__slug=self.kwargs.get("slug"),
|
||||||
.filter(issue_id=self.kwargs.get("issue_id"))
|
project_id=self.kwargs.get("project_id"),
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"))
|
)
|
||||||
.filter(project_id=self.kwargs.get("project_id"))
|
if project_deploy_board.votes:
|
||||||
)
|
return (
|
||||||
|
super()
|
||||||
|
.get_queryset()
|
||||||
|
.filter(issue_id=self.kwargs.get("issue_id"))
|
||||||
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
||||||
|
.filter(project_id=self.kwargs.get("project_id"))
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return IssueVote.objects.none()
|
||||||
|
except ProjectDeployBoard.DoesNotExist:
|
||||||
|
return IssueVote.objects.none()
|
||||||
|
|
||||||
def create(self, request, slug, project_id, issue_id):
|
def create(self, request, slug, project_id, issue_id):
|
||||||
try:
|
try:
|
||||||
@ -1974,6 +1993,8 @@ class IssueVotePublicViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
serializer = IssueVoteSerializer(issue_vote)
|
serializer = IssueVoteSerializer(issue_vote)
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
except IntegrityError:
|
||||||
|
return Response({"error": "Reaction already exists"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
return Response(
|
return Response(
|
||||||
|
Loading…
Reference in New Issue
Block a user