feat: assign multiple sub issues

This commit is contained in:
pablohashescobar 2023-02-14 15:33:53 +05:30
parent 7950f191e7
commit c9dce08842

View File

@ -75,7 +75,6 @@ class IssueViewSet(BaseViewSet):
self.get_queryset().filter(pk=self.kwargs.get("pk", None)).first() self.get_queryset().filter(pk=self.kwargs.get("pk", None)).first()
) )
if current_instance is not None: if current_instance is not None:
issue_activity.delay( issue_activity.delay(
{ {
"type": "issue.activity", "type": "issue.activity",
@ -92,7 +91,6 @@ class IssueViewSet(BaseViewSet):
return super().perform_update(serializer) return super().perform_update(serializer)
def get_queryset(self): def get_queryset(self):
return ( return (
super() super()
.get_queryset() .get_queryset()
@ -277,7 +275,6 @@ class UserWorkSpaceIssues(BaseAPIView):
class WorkSpaceIssuesEndpoint(BaseAPIView): class WorkSpaceIssuesEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
WorkSpaceAdminPermission, WorkSpaceAdminPermission,
] ]
@ -298,7 +295,6 @@ class WorkSpaceIssuesEndpoint(BaseAPIView):
class IssueActivityEndpoint(BaseAPIView): class IssueActivityEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
ProjectEntityPermission, ProjectEntityPermission,
] ]
@ -333,7 +329,6 @@ class IssueActivityEndpoint(BaseAPIView):
class IssueCommentViewSet(BaseViewSet): class IssueCommentViewSet(BaseViewSet):
serializer_class = IssueCommentSerializer serializer_class = IssueCommentSerializer
model = IssueComment model = IssueComment
permission_classes = [ permission_classes = [
@ -436,7 +431,6 @@ class IssuePropertyViewSet(BaseViewSet):
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try: try:
issue_property, created = IssueProperty.objects.get_or_create( issue_property, created = IssueProperty.objects.get_or_create(
user=request.user, user=request.user,
project_id=project_id, project_id=project_id,
@ -463,7 +457,6 @@ class IssuePropertyViewSet(BaseViewSet):
class LabelViewSet(BaseViewSet): class LabelViewSet(BaseViewSet):
serializer_class = LabelSerializer serializer_class = LabelSerializer
model = Label model = Label
permission_classes = [ permission_classes = [
@ -490,14 +483,12 @@ class LabelViewSet(BaseViewSet):
class BulkDeleteIssuesEndpoint(BaseAPIView): class BulkDeleteIssuesEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
ProjectEntityPermission, ProjectEntityPermission,
] ]
def delete(self, request, slug, project_id): def delete(self, request, slug, project_id):
try: try:
issue_ids = request.data.get("issue_ids", []) issue_ids = request.data.get("issue_ids", [])
if not len(issue_ids): if not len(issue_ids):
@ -527,14 +518,12 @@ class BulkDeleteIssuesEndpoint(BaseAPIView):
class SubIssuesEndpoint(BaseAPIView): class SubIssuesEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
ProjectEntityPermission, ProjectEntityPermission,
] ]
def get(self, request, slug, project_id, issue_id): def get(self, request, slug, project_id, issue_id):
try: try:
sub_issues = ( sub_issues = (
Issue.objects.filter( Issue.objects.filter(
parent_id=issue_id, workspace__slug=slug, project_id=project_id parent_id=issue_id, workspace__slug=slug, project_id=project_id
@ -583,3 +572,39 @@ class SubIssuesEndpoint(BaseAPIView):
{"error": "Something went wrong please try again later"}, {"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
# Assign multiple sub issues
def post(self, request, slug, project_id, issue_id):
try:
parent_issue = Issue.objects.get(pk=issue_id)
sub_issue_ids = request.data.get("sub_issue_ids", [])
if len(sub_issue_ids):
return Response(
{"error": "Sub Issue IDs are required"},
status=status.HTTP_400_BAD_REQUEST,
)
sub_issues = Issue.objects.filter(id__in=sub_issue_ids)
for sub_issue in sub_issues:
sub_issue.parent = parent_issue
updated_sub_issues = Issue.objects.bulk_update(
sub_issues, ["parent"], batch_size=10
)
return Response(
IssueSerializer(updated_sub_issues, many=True).data,
status=status.HTTP_200_OK,
)
except Issue.DoesNotExist:
return Response(
{"Parent Issue does not exists"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)