Skip to content
Draft
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
25 changes: 6 additions & 19 deletions apps/api/plane/api/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,32 +289,19 @@ def update(self, instance, validated_data):
def to_representation(self, instance):
data = super().to_representation(instance)
if "assignees" in self.fields:
assignees = instance.assignees.all()
if "assignees" in self.expand:
from .user import UserLiteSerializer

data["assignees"] = UserLiteSerializer(
User.objects.filter(
pk__in=IssueAssignee.objects.filter(issue=instance).values_list("assignee_id", flat=True)
),
many=True,
).data
data["assignees"] = UserLiteSerializer(assignees, many=True).data
else:
data["assignees"] = [
str(assignee)
for assignee in IssueAssignee.objects.filter(issue=instance).values_list("assignee_id", flat=True)
]
data["assignees"] = [str(assignee.id) for assignee in assignees]
if "labels" in self.fields:
labels = instance.labels.all()
if "labels" in self.expand:
data["labels"] = LabelSerializer(
Label.objects.filter(
pk__in=IssueLabel.objects.filter(issue=instance).values_list("label_id", flat=True)
),
many=True,
).data
data["labels"] = LabelSerializer(labels, many=True).data
else:
data["labels"] = [
str(label) for label in IssueLabel.objects.filter(issue=instance).values_list("label_id", flat=True)
]
data["labels"] = [str(label.id) for label in labels]

return data

Expand Down
26 changes: 9 additions & 17 deletions apps/api/plane/api/views/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,21 @@ def post(self, request, slug, project_id):
):
serializer = CycleCreateSerializer(data=request.data, context={"request": request})
if serializer.is_valid():
if (
request.data.get("external_id")
and request.data.get("external_source")
and Cycle.objects.filter(
project_id=project_id,
workspace__slug=slug,
external_source=request.data.get("external_source"),
external_id=request.data.get("external_id"),
).exists()
):
if request.data.get("external_id") and request.data.get("external_source"):
cycle = Cycle.objects.filter(
workspace__slug=slug,
project_id=project_id,
external_source=request.data.get("external_source"),
external_id=request.data.get("external_id"),
).first()
return Response(
{
"error": "Cycle with the same external id and external source already exists",
"id": str(cycle.id),
},
status=status.HTTP_409_CONFLICT,
)
if cycle:
return Response(
{
"error": "Cycle with the same external id and external source already exists",
"id": str(cycle.id),
},
status=status.HTTP_409_CONFLICT,
)
serializer.save(project_id=project_id)
# Send the model activity
model_activity.delay(
Expand Down