diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index 41280c19e..7a9cfb1b5 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -264,7 +264,7 @@ class CycleAPIEndpoint(WebhookMixin, BaseAPIView): "error": "Cycle with the same external id and external source already exists", "cycle": str(cycle.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save( project_id=project_id, @@ -315,15 +315,10 @@ class CycleAPIEndpoint(WebhookMixin, BaseAPIView): if ( request.data.get("external_id") and (cycle.external_id != request.data.get("external_id")) - and request.data.get("external_source") - and ( - cycle.external_source - != request.data.get("external_source") - ) and Cycle.objects.filter( project_id=project_id, workspace__slug=slug, - external_source=request.data.get("external_source"), + external_source=request.data.get("external_source", cycle.external_source), external_id=request.data.get("external_id"), ).exists() ): @@ -332,7 +327,7 @@ class CycleAPIEndpoint(WebhookMixin, BaseAPIView): "error": "Cycle with the same external id and external source already exists", "cycle_id": str(cycle.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index b475e0caf..530eef5bf 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -241,7 +241,7 @@ class IssueAPIEndpoint(WebhookMixin, BaseAPIView): "error": "Issue with the same external id and external source already exists", "issue_id": str(issue.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() @@ -283,24 +283,19 @@ class IssueAPIEndpoint(WebhookMixin, BaseAPIView): if ( str(request.data.get("external_id")) and (issue.external_id != str(request.data.get("external_id"))) - and request.data.get("external_source") - and ( - issue.external_source - != request.data.get("external_source") - ) and Issue.objects.filter( project_id=project_id, workspace__slug=slug, - external_source=request.data.get("external_source"), + external_source=request.data.get("external_source", issue.external_source), external_id=request.data.get("external_id"), ).exists() ): return Response( { "error": "Issue with the same external id and external source already exists", - "issue_id": str(issue.id) + "issue_id": str(issue.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() @@ -310,6 +305,8 @@ class IssueAPIEndpoint(WebhookMixin, BaseAPIView): actor_id=str(request.user.id), issue_id=str(pk), project_id=str(project_id), + external_id__isnull=False, + external_source__isnull=False, current_instance=current_instance, epoch=int(timezone.now().timestamp()), ) diff --git a/apiserver/plane/api/views/module.py b/apiserver/plane/api/views/module.py index 83e888d3c..e2d59e126 100644 --- a/apiserver/plane/api/views/module.py +++ b/apiserver/plane/api/views/module.py @@ -153,7 +153,7 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView): "error": "Module with the same external id and external source already exists", "module_id": str(module.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() module = Module.objects.get(pk=serializer.data["id"]) @@ -175,15 +175,10 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView): if ( request.data.get("external_id") and (module.external_id != request.data.get("external_id")) - and request.data.get("external_source") - and ( - module.external_source - != request.data.get("external_source") - ) and Module.objects.filter( project_id=project_id, workspace__slug=slug, - external_source=request.data.get("external_source"), + external_source=request.data.get("external_source", module.external_source), external_id=request.data.get("external_id"), ).exists() ): @@ -192,10 +187,10 @@ class ModuleAPIEndpoint(WebhookMixin, BaseAPIView): "error": "Module with the same external id and external source already exists", "module_id": str(module.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) + return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) def get(self, request, slug, project_id, pk=None): diff --git a/apiserver/plane/api/views/state.py b/apiserver/plane/api/views/state.py index 4ac91903f..88fb083f0 100644 --- a/apiserver/plane/api/views/state.py +++ b/apiserver/plane/api/views/state.py @@ -59,7 +59,7 @@ class StateAPIEndpoint(BaseAPIView): "error": "State with the same external id and external source already exists", "state_id": str(state.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save(project_id=project_id) @@ -118,24 +118,19 @@ class StateAPIEndpoint(BaseAPIView): if ( str(request.data.get("external_id")) and (state.external_id != str(request.data.get("external_id"))) - and request.data.get("external_source") - and ( - state.external_source - != request.data.get("external_source") - ) - and Issue.objects.filter( + and State.objects.filter( project_id=project_id, workspace__slug=slug, - external_source=request.data.get("external_source"), + external_source=request.data.get("external_source", state.external_source), external_id=request.data.get("external_id"), ).exists() ): return Response( { - "error": "Issue with the same external id and external source already exists", + "error": "State with the same external id and external source already exists", "state_id": str(state.id), }, - status=status.HTTP_410_GONE, + status=status.HTTP_409_CONFLICT, ) serializer.save() return Response(serializer.data, status=status.HTTP_200_OK)