diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index 3288c1750..3e27ffdc4 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -141,8 +141,10 @@ class CycleAPIEndpoint(BaseAPIView): if pk: queryset = self.get_queryset().filter(archived_at__isnull=True).get(pk=pk) data = CycleSerializer( - queryset, fields=self.fields, - expand=self.expand, context={"project": project} + queryset, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data return Response(data, status=status.HTTP_200_OK) queryset = self.get_queryset().filter(archived_at__isnull=True) @@ -154,8 +156,11 @@ class CycleAPIEndpoint(BaseAPIView): start_date__lte=timezone.now(), end_date__gte=timezone.now() ) data = CycleSerializer( - queryset, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + queryset, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data return Response(data, status=status.HTTP_200_OK) @@ -166,8 +171,11 @@ class CycleAPIEndpoint(BaseAPIView): request=request, queryset=(queryset), on_results=lambda cycles: CycleSerializer( - cycles, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + cycles, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data, ) @@ -178,8 +186,11 @@ class CycleAPIEndpoint(BaseAPIView): request=request, queryset=(queryset), on_results=lambda cycles: CycleSerializer( - cycles, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + cycles, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data, ) @@ -190,8 +201,11 @@ class CycleAPIEndpoint(BaseAPIView): request=request, queryset=(queryset), on_results=lambda cycles: CycleSerializer( - cycles, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + cycles, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data, ) @@ -204,16 +218,22 @@ class CycleAPIEndpoint(BaseAPIView): request=request, queryset=(queryset), on_results=lambda cycles: CycleSerializer( - cycles, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + cycles, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data, ) return self.paginate( request=request, queryset=(queryset), on_results=lambda cycles: CycleSerializer( - cycles, many=True, fields=self.fields, - expand=self.expand, context={"project": project} + cycles, + many=True, + fields=self.fields, + expand=self.expand, + context={"project": project}, ).data, ) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index e0aee3a20..efbdf07f9 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -57,6 +57,7 @@ from plane.settings.storage import S3Storage from plane.bgtasks.storage_metadata_task import get_asset_object_metadata from .base import BaseAPIView from plane.utils.host import base_host +from plane.bgtasks.webhook_task import model_activity class WorkspaceIssueAPIEndpoint(BaseAPIView): @@ -322,6 +323,17 @@ class IssueAPIEndpoint(BaseAPIView): current_instance=None, epoch=int(timezone.now().timestamp()), ) + + # Send the model activity + model_activity.delay( + model_name="issue", + model_id=str(serializer.data["id"]), + requested_data=request.data, + current_instance=None, + actor_id=request.user.id, + slug=slug, + origin=base_host(request=request, is_app=True), + ) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 289f1d014..5ceb06a63 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -32,6 +32,7 @@ from plane.bgtasks.webhook_task import model_activity, webhook_activity from .base import BaseAPIView from plane.utils.host import base_host + class ProjectAPIEndpoint(BaseAPIView): """Project Endpoints to create, update, list, retrieve and delete endpoint""" @@ -238,7 +239,7 @@ class ProjectAPIEndpoint(BaseAPIView): if "already exists" in str(e): return Response( {"name": "The project name is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) except Workspace.DoesNotExist: return Response( @@ -247,7 +248,7 @@ class ProjectAPIEndpoint(BaseAPIView): except ValidationError: return Response( {"identifier": "The project identifier is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) def patch(self, request, slug, pk): @@ -305,7 +306,7 @@ class ProjectAPIEndpoint(BaseAPIView): if "already exists" in str(e): return Response( {"name": "The project name is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) except (Project.DoesNotExist, Workspace.DoesNotExist): return Response( @@ -314,7 +315,7 @@ class ProjectAPIEndpoint(BaseAPIView): except ValidationError: return Response( {"identifier": "The project identifier is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) def delete(self, request, slug, pk): diff --git a/apiserver/plane/app/views/project/base.py b/apiserver/plane/app/views/project/base.py index f5089b44f..46290d7a5 100644 --- a/apiserver/plane/app/views/project/base.py +++ b/apiserver/plane/app/views/project/base.py @@ -41,6 +41,7 @@ from plane.bgtasks.recent_visited_task import recent_visited_task from plane.utils.exception_logger import log_exception from plane.utils.host import base_host + class ProjectViewSet(BaseViewSet): serializer_class = ProjectListSerializer model = Project @@ -341,7 +342,7 @@ class ProjectViewSet(BaseViewSet): if "already exists" in str(e): return Response( {"name": "The project name is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) except Workspace.DoesNotExist: return Response( @@ -350,7 +351,7 @@ class ProjectViewSet(BaseViewSet): except serializers.ValidationError: return Response( {"identifier": "The project identifier is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) def partial_update(self, request, slug, pk=None): @@ -419,7 +420,7 @@ class ProjectViewSet(BaseViewSet): if "already exists" in str(e): return Response( {"name": "The project name is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) except (Project.DoesNotExist, Workspace.DoesNotExist): return Response( @@ -428,7 +429,7 @@ class ProjectViewSet(BaseViewSet): except serializers.ValidationError: return Response( {"identifier": "The project identifier is already taken"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) def destroy(self, request, slug, pk): diff --git a/apiserver/plane/app/views/webhook/base.py b/apiserver/plane/app/views/webhook/base.py index d7ff5cf3a..0ed4ba9e0 100644 --- a/apiserver/plane/app/views/webhook/base.py +++ b/apiserver/plane/app/views/webhook/base.py @@ -29,7 +29,7 @@ class WebhookEndpoint(BaseAPIView): if "already exists" in str(e): return Response( {"error": "URL already exists for the workspace"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) raise IntegrityError diff --git a/apiserver/plane/app/views/workspace/base.py b/apiserver/plane/app/views/workspace/base.py index 5be9a7558..c627f19b6 100644 --- a/apiserver/plane/app/views/workspace/base.py +++ b/apiserver/plane/app/views/workspace/base.py @@ -119,7 +119,9 @@ class WorkSpaceViewSet(BaseViewSet): ) # Get total members and role - total_members=WorkspaceMember.objects.filter(workspace_id=serializer.data["id"]).count() + total_members = WorkspaceMember.objects.filter( + workspace_id=serializer.data["id"] + ).count() data = serializer.data data["total_members"] = total_members data["role"] = 20 @@ -134,7 +136,7 @@ class WorkSpaceViewSet(BaseViewSet): if "already exists" in str(e): return Response( {"slug": "The workspace with the slug already exists"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) @allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST], level="WORKSPACE") @@ -167,10 +169,9 @@ class UserWorkSpacesEndpoint(BaseAPIView): .values("count") ) - role = ( - WorkspaceMember.objects.filter(workspace=OuterRef("id"), member=request.user, is_active=True) - .values("role") - ) + role = WorkspaceMember.objects.filter( + workspace=OuterRef("id"), member=request.user, is_active=True + ).values("role") workspace = ( Workspace.objects.prefetch_related( diff --git a/apiserver/plane/bgtasks/issue_activities_task.py b/apiserver/plane/bgtasks/issue_activities_task.py index 13bef73a2..827534a21 100644 --- a/apiserver/plane/bgtasks/issue_activities_task.py +++ b/apiserver/plane/bgtasks/issue_activities_task.py @@ -307,6 +307,10 @@ def track_labels( # Set of newly added labels for added_label in added_labels: + # validate uuids + if not is_valid_uuid(added_label): + continue + label = Label.objects.get(pk=added_label) issue_activities.append( IssueActivity( @@ -327,6 +331,10 @@ def track_labels( # Set of dropped labels for dropped_label in dropped_labels: + # validate uuids + if not is_valid_uuid(dropped_label): + continue + label = Label.objects.get(pk=dropped_label) issue_activities.append( IssueActivity( @@ -373,6 +381,10 @@ def track_assignees( bulk_subscribers = [] for added_asignee in added_assignees: + # validate uuids + if not is_valid_uuid(added_asignee): + continue + assignee = User.objects.get(pk=added_asignee) issue_activities.append( IssueActivity( @@ -406,6 +418,10 @@ def track_assignees( ) for dropped_assignee in dropped_assginees: + # validate uuids + if not is_valid_uuid(dropped_assignee): + continue + assignee = User.objects.get(pk=dropped_assignee) issue_activities.append( IssueActivity( diff --git a/apiserver/plane/license/api/views/workspace.py b/apiserver/plane/license/api/views/workspace.py index 607016cc3..8b5eaac6b 100644 --- a/apiserver/plane/license/api/views/workspace.py +++ b/apiserver/plane/license/api/views/workspace.py @@ -109,5 +109,5 @@ class InstanceWorkSpaceEndpoint(BaseAPIView): if "already exists" in str(e): return Response( {"slug": "The workspace with the slug already exists"}, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) diff --git a/apiserver/plane/tests/api/test_workspace.py b/apiserver/plane/tests/api/test_workspace.py index c1e487fbe..d63eab2e0 100644 --- a/apiserver/plane/tests/api/test_workspace.py +++ b/apiserver/plane/tests/api/test_workspace.py @@ -41,4 +41,4 @@ class WorkSpaceCreateReadUpdateDelete(AuthenticatedAPITest): response = self.client.post( url, {"name": "Plane", "slug": "pla-ne"}, format="json" ) - self.assertEqual(response.status_code, status.HTTP_410_GONE) + self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)