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
8 changes: 2 additions & 6 deletions apiserver/plane/api/views/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def get(self, request, slug, project_id, pk=None):
# Incomplete Cycles
if cycle_view == "incomplete":
queryset = queryset.filter(
Q(end_date__gte=timezone.now())
| Q(end_date__isnull=True),
Q(end_date__gte=timezone.now()) | Q(end_date__isnull=True),
)
return self.paginate(
request=request,
Expand Down Expand Up @@ -309,10 +308,7 @@ def patch(self, request, slug, project_id, pk):

request_data = request.data

if (
cycle.end_date is not None
and cycle.end_date < timezone.now()
):
if cycle.end_date is not None and cycle.end_date < timezone.now():
if "sort_order" in request_data:
# Can only change sort order
request_data = {
Expand Down
48 changes: 30 additions & 18 deletions apiserver/plane/app/serializers/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Meta:
fields = "__all__"
read_only_fields = [
"workspace",
"project",
"created_by",
"updated_by",
"created_at",
Expand Down Expand Up @@ -83,11 +82,13 @@ def create(self, validated_data):
modules = self.initial_data.get("module_ids", None)

workspace_id = self.context["workspace_id"]
project_id = self.context["project_id"]

# Create Issue
issue = DraftIssue.objects.create(
**validated_data,
workspace_id=workspace_id,
project_id=project_id,
)

# Issue Audit Users
Expand All @@ -99,8 +100,9 @@ def create(self, validated_data):
[
DraftIssueAssignee(
assignee=user,
issue=issue,
draft_issue=issue,
workspace_id=workspace_id,
project_id=project_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)
Expand All @@ -114,7 +116,8 @@ def create(self, validated_data):
[
DraftIssueLabel(
label=label,
issue=issue,
draft_issue=issue,
project_id=project_id,
workspace_id=workspace_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
Expand All @@ -128,6 +131,7 @@ def create(self, validated_data):
DraftIssueCycle.objects.create(
cycle_id=cycle_id,
draft_issue=issue,
project_id=project_id,
workspace_id=workspace_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
Expand All @@ -139,6 +143,7 @@ def create(self, validated_data):
DraftIssueModule(
module_id=module_id,
draft_issue=issue,
project_id=project_id,
workspace_id=workspace_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
Expand All @@ -153,22 +158,25 @@ def create(self, validated_data):
def update(self, instance, validated_data):
assignees = validated_data.pop("assignee_ids", None)
labels = validated_data.pop("label_ids", None)
cycle_id = self.initial_data.get("cycle_id", None)
cycle_id = self.context.get("cycle_id", None)
modules = self.initial_data.get("module_ids", None)

# Related models
workspace_id = instance.workspace_id
project_id = instance.project_id

created_by_id = instance.created_by_id
updated_by_id = instance.updated_by_id

if assignees is not None:
DraftIssueAssignee.objects.filter(issue=instance).delete()
DraftIssueAssignee.objects.filter(draft_issue=instance).delete()
DraftIssueAssignee.objects.bulk_create(
[
DraftIssueAssignee(
assignee=user,
issue=instance,
draft_issue=instance,
workspace_id=workspace_id,
project_id=project_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)
Expand All @@ -178,13 +186,14 @@ def update(self, instance, validated_data):
)

if labels is not None:
DraftIssueLabel.objects.filter(issue=instance).delete()
DraftIssueLabel.objects.filter(draft_issue=instance).delete()
DraftIssueLabel.objects.bulk_create(
[
DraftIssueLabel(
label=label,
issue=instance,
draft_issue=instance,
workspace_id=workspace_id,
project_id=project_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)
Expand All @@ -193,28 +202,31 @@ def update(self, instance, validated_data):
batch_size=10,
)

if cycle_id is not None:
if cycle_id != "not_provided":
DraftIssueCycle.objects.filter(draft_issue=instance).delete()
DraftIssueCycle.objects.create(
cycle_id=cycle_id,
draft_issue=instance,
workspace_id=workspace_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)
if cycle_id is not None:
DraftIssueCycle.objects.create(
cycle_id=cycle_id,
draft_issue=instance,
workspace_id=workspace_id,
project_id=project_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)

if modules is not None:
DraftIssueModule.objects.filter(draft_issue=instance).delete()
DraftIssueModule.objects.bulk_create(
[
DraftIssueModule(
module=module,
module_id=module_id,
draft_issue=instance,
workspace_id=workspace_id,
project_id=project_id,
created_by_id=created_by_id,
updated_by_id=updated_by_id,
)
for module in modules
for module_id in modules
],
batch_size=10,
)
Expand Down
5 changes: 5 additions & 0 deletions apiserver/plane/app/urls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,9 @@
),
name="workspace-drafts-issues",
),
path(
"workspaces/<str:slug>/draft-to-issue/<uuid:draft_id>/",
WorkspaceDraftIssueViewSet.as_view({"post": "create_draft_to_issue"}),
name="workspace-drafts-issues",
),
]
11 changes: 7 additions & 4 deletions apiserver/plane/app/views/cycle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def list(self, request, slug, project_id):
"completed_issues",
"assignee_ids",
"status",
"version",
"created_by",
)

Expand Down Expand Up @@ -216,6 +217,7 @@ def list(self, request, slug, project_id):
"completed_issues",
"assignee_ids",
"status",
"version",
"created_by",
)
return Response(data, status=status.HTTP_200_OK)
Expand Down Expand Up @@ -255,6 +257,7 @@ def create(self, request, slug, project_id):
"external_id",
"progress_snapshot",
"logo_props",
"version",
# meta fields
"is_favorite",
"total_issues",
Expand Down Expand Up @@ -306,10 +309,7 @@ def partial_update(self, request, slug, project_id, pk):

request_data = request.data

if (
cycle.end_date is not None
and cycle.end_date < timezone.now()
):
if cycle.end_date is not None and cycle.end_date < timezone.now():
if "sort_order" in request_data:
# Can only change sort order for a completed cycle``
request_data = {
Expand Down Expand Up @@ -347,6 +347,7 @@ def partial_update(self, request, slug, project_id, pk):
"external_id",
"progress_snapshot",
"logo_props",
"version",
# meta fields
"is_favorite",
"total_issues",
Expand Down Expand Up @@ -412,6 +413,7 @@ def retrieve(self, request, slug, project_id, pk):
"progress_snapshot",
"sub_issues",
"logo_props",
"version",
# meta fields
"is_favorite",
"total_issues",
Expand Down Expand Up @@ -1148,6 +1150,7 @@ def get(self, request, slug, project_id, cycle_id):
status=status.HTTP_200_OK,
)


class CycleAnalyticsEndpoint(BaseAPIView):

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
Expand Down
Loading