mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: validation for external id and external source
This commit is contained in:
parent
52c8195181
commit
a2eaed2aed
@ -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)
|
||||
|
@ -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()),
|
||||
)
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user