Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apiserver/plane/api/views/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def post(self, request, slug, project_id):
return Response(
{
"error": "Cycle with the same external id and external source already exists",
"cycle": str(cycle.id),
"id": str(cycle.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down Expand Up @@ -325,7 +325,7 @@ def patch(self, request, slug, project_id, pk):
return Response(
{
"error": "Cycle with the same external id and external source already exists",
"cycle_id": str(cycle.id),
"id": str(cycle.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down
61 changes: 56 additions & 5 deletions apiserver/plane/api/views/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def post(self, request, slug, project_id):
return Response(
{
"error": "Issue with the same external id and external source already exists",
"issue_id": str(issue.id),
"id": str(issue.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down Expand Up @@ -286,14 +286,16 @@ def patch(self, request, slug, project_id, pk=None):
and Issue.objects.filter(
project_id=project_id,
workspace__slug=slug,
external_source=request.data.get("external_source", issue.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),
"id": str(issue.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down Expand Up @@ -362,6 +364,30 @@ def post(self, request, slug, project_id):
try:
serializer = LabelSerializer(data=request.data)
if serializer.is_valid():
if (
request.data.get("external_id")
and request.data.get("external_source")
and Label.objects.filter(
project_id=project_id,
workspace__slug=slug,
external_source=request.data.get("external_source"),
external_id=request.data.get("external_id"),
).exists()
):
label = Label.objects.filter(
workspace__slug=slug,
project_id=project_id,
external_id=request.data.get("external_id"),
external_source=request.data.get("external_source"),
).first()
return Response(
{
"error": "Label with the same external id and external source already exists",
"id": str(label.id),
},
status=status.HTTP_409_CONFLICT,
)

serializer.save(project_id=project_id)
return Response(
serializer.data, status=status.HTTP_201_CREATED
Expand All @@ -370,11 +396,17 @@ def post(self, request, slug, project_id):
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
except IntegrityError:
label = Label.objects.filter(
workspace__slug=slug,
project_id=project_id,
name=request.data.get("name"),
).first()
return Response(
{
"error": "Label with the same name already exists in the project"
"error": "Label with the same name already exists in the project",
"id": str(label.id),
},
status=status.HTTP_400_BAD_REQUEST,
status=status.HTTP_409_CONFLICT,
)

def get(self, request, slug, project_id, pk=None):
Expand All @@ -401,6 +433,25 @@ def patch(self, request, slug, project_id, pk=None):
label = self.get_queryset().get(pk=pk)
serializer = LabelSerializer(label, data=request.data, partial=True)
if serializer.is_valid():
if (
str(request.data.get("external_id"))
and (label.external_id != str(request.data.get("external_id")))
and Issue.objects.filter(
project_id=project_id,
workspace__slug=slug,
external_source=request.data.get(
"external_source", label.external_source
),
external_id=request.data.get("external_id"),
).exists()
):
return Response(
{
"error": "Label with the same external id and external source already exists",
"id": str(label.id),
},
status=status.HTTP_409_CONFLICT,
)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/api/views/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def post(self, request, slug, project_id):
return Response(
{
"error": "Module with the same external id and external source already exists",
"module_id": str(module.id),
"id": str(module.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down Expand Up @@ -185,7 +185,7 @@ def patch(self, request, slug, project_id, pk):
return Response(
{
"error": "Module with the same external id and external source already exists",
"module_id": str(module.id),
"id": str(module.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/api/views/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def post(self, request, slug, project_id):
return Response(
{
"error": "State with the same external id and external source already exists",
"state_id": str(state.id),
"id": str(state.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def patch(self, request, slug, project_id, state_id=None):
return Response(
{
"error": "State with the same external id and external source already exists",
"state_id": str(state.id),
"id": str(state.id),
},
status=status.HTTP_409_CONFLICT,
)
Expand Down