Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-2693] chore: removed the deleted cycles from the issue list (#5868)

Bavisetti Narayandb919420a74a
diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py
index 77f0fad623..27c7042b49 100644
--- a/apiserver/plane/api/views/issue.py
+++ b/apiserver/plane/api/views/issue.py
@@ -202,7 +202,15 @@ class IssueAPIEndpoint(BaseAPIView):
issue_queryset = (
self.get_queryset()
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ Q(issue_cycle__cycle__deleted_at__isnull=True),
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/cycle/issue.py b/apiserver/plane/app/views/cycle/issue.py
index cdd6b11ad6..a9a3305990 100644
--- a/apiserver/plane/app/views/cycle/issue.py
+++ b/apiserver/plane/app/views/cycle/issue.py
@@ -3,7 +3,7 @@ import json
# Django imports
from django.core import serializers
-from django.db.models import F, Func, OuterRef, Q
+from django.db.models import F, Func, OuterRef, Q, Case, When
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
@@ -102,7 +102,15 @@ class CycleIssueViewSet(BaseViewSet):
"issue_cycle__cycle",
)
.filter(**filters)
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/inbox/base.py b/apiserver/plane/app/views/inbox/base.py
index ac4da95370..59a9cf955e 100644
--- a/apiserver/plane/app/views/inbox/base.py
+++ b/apiserver/plane/app/views/inbox/base.py
@@ -3,7 +3,7 @@ import json
# Django import
from django.utils import timezone
-from django.db.models import Q, Count, OuterRef, Func, F, Prefetch
+from django.db.models import Q, Count, OuterRef, Func, F, Prefetch, Case, When
from django.core.serializers.json import DjangoJSONEncoder
from django.contrib.postgres.aggregates import ArrayAgg
from django.contrib.postgres.fields import ArrayField
@@ -112,7 +112,15 @@ class InboxIssueViewSet(BaseViewSet):
),
)
)
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/issue/archive.py b/apiserver/plane/app/views/issue/archive.py
index 83fc5d0c2c..283f1ad99a 100644
--- a/apiserver/plane/app/views/issue/archive.py
+++ b/apiserver/plane/app/views/issue/archive.py
@@ -3,14 +3,7 @@ import json
# Django imports
from django.core.serializers.json import DjangoJSONEncoder
-from django.db.models import (
- F,
- Func,
- OuterRef,
- Q,
- Prefetch,
- Exists,
-)
+from django.db.models import F, Func, OuterRef, Q, Prefetch, Exists, Case, When
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
@@ -71,7 +64,15 @@ class IssueArchiveViewSet(BaseViewSet):
.filter(workspace__slug=self.kwargs.get("slug"))
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/issue/base.py b/apiserver/plane/app/views/issue/base.py
index a1cca7f431..0488a5471d 100644
--- a/apiserver/plane/app/views/issue/base.py
+++ b/apiserver/plane/app/views/issue/base.py
@@ -14,6 +14,8 @@ from django.db.models import (
Q,
UUIDField,
Value,
+ When,
+ Case,
)
from django.db.models.functions import Coalesce
from django.utils import timezone
@@ -83,7 +85,15 @@ class IssueListEndpoint(BaseAPIView):
.filter(workspace__slug=self.kwargs.get("slug"))
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
@@ -207,7 +217,15 @@ class IssueViewSet(BaseViewSet):
.filter(workspace__slug=self.kwargs.get("slug"))
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
@@ -757,7 +775,15 @@ class IssuePaginatedViewSet(BaseViewSet):
"workspace", "project", "state", "parent"
)
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/issue/relation.py b/apiserver/plane/app/views/issue/relation.py
index 4bf622f28a..83385d83d7 100644
--- a/apiserver/plane/app/views/issue/relation.py
+++ b/apiserver/plane/app/views/issue/relation.py
@@ -3,7 +3,17 @@ import json
# Django imports
from django.utils import timezone
-from django.db.models import Q, OuterRef, F, Func, UUIDField, Value, CharField
+from django.db.models import (
+ Q,
+ OuterRef,
+ F,
+ Func,
+ UUIDField,
+ Value,
+ CharField,
+ Case,
+ When,
+)
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models.functions import Coalesce
from django.contrib.postgres.aggregates import ArrayAgg
@@ -83,7 +93,15 @@ class IssueRelationViewSet(BaseViewSet):
Issue.issue_objects.filter(workspace__slug=slug)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/issue/sub_issue.py b/apiserver/plane/app/views/issue/sub_issue.py
index cf9c0f709c..700d6db5b3 100644
--- a/apiserver/plane/app/views/issue/sub_issue.py
+++ b/apiserver/plane/app/views/issue/sub_issue.py
@@ -10,6 +10,8 @@ from django.db.models import (
Q,
Value,
UUIDField,
+ Case,
+ When,
)
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
@@ -48,7 +50,15 @@ class SubIssuesEndpoint(BaseAPIView):
)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/module/issue.py b/apiserver/plane/app/views/module/issue.py
index 8edced252d..f58e477567 100644
--- a/apiserver/plane/app/views/module/issue.py
+++ b/apiserver/plane/app/views/module/issue.py
@@ -6,6 +6,8 @@ from django.db.models import (
Func,
OuterRef,
Q,
+ Case,
+ When,
)
# Django Imports
@@ -65,7 +67,15 @@ class ModuleIssueViewSet(BaseViewSet):
)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/app/views/view/base.py b/apiserver/plane/app/views/view/base.py
index 56f03cda65..59cfcecd57 100644
--- a/apiserver/plane/app/views/view/base.py
+++ b/apiserver/plane/app/views/view/base.py
@@ -9,6 +9,8 @@ from django.db.models import (
Q,
UUIDField,
Value,
+ Case,
+ When,
)
from django.db.models.functions import Coalesce
from django.utils.decorators import method_decorator
@@ -205,7 +207,15 @@ class WorkspaceViewIssuesViewSet(BaseViewSet):
)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
@@ -275,7 +285,15 @@ class WorkspaceViewIssuesViewSet(BaseViewSet):
issue_queryset = (
self.get_queryset()
.filter(**filters)
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
)
# check for the project member role, if the role is 5 then check for the guest_view_all_features if it is true then show all the issues else show only the issues created by the user
diff --git a/apiserver/plane/app/views/workspace/draft.py b/apiserver/plane/app/views/workspace/draft.py
index ee899be682..d116c42147 100644
--- a/apiserver/plane/app/views/workspace/draft.py
+++ b/apiserver/plane/app/views/workspace/draft.py
@@ -12,6 +12,8 @@ from django.db.models import (
Q,
UUIDField,
Value,
+ Case,
+ When,
)
from django.db.models.functions import Coalesce
from django.utils.decorators import method_decorator
@@ -55,6 +57,15 @@ class WorkspaceDraftIssueViewSet(BaseViewSet):
"assignees", "labels", "draft_issue_module__module"
)
.annotate(cycle_id=F("draft_issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
label_ids=Coalesce(
ArrayAgg(
@@ -81,8 +92,12 @@ class WorkspaceDraftIssueViewSet(BaseViewSet):
"draft_issue_module__module_id",
distinct=True,
filter=~Q(draft_issue_module__module_id__isnull=True)
- & Q(draft_issue_module__module__archived_at__isnull=True)
- & Q(draft_issue_module__module__deleted_at__isnull=True),
+ & Q(
+ draft_issue_module__module__archived_at__isnull=True
+ )
+ & Q(
+ draft_issue_module__module__deleted_at__isnull=True
+ ),
),
Value([], output_field=ArrayField(UUIDField())),
),
diff --git a/apiserver/plane/app/views/workspace/user.py b/apiserver/plane/app/views/workspace/user.py
index 57cde8d8bc..fae917af29 100644
--- a/apiserver/plane/app/views/workspace/user.py
+++ b/apiserver/plane/app/views/workspace/user.py
@@ -120,7 +120,15 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
.filter(**filters)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
diff --git a/apiserver/plane/space/views/issue.py b/apiserver/plane/space/views/issue.py
index d79940e1c9..bd9d499d60 100644
--- a/apiserver/plane/space/views/issue.py
+++ b/apiserver/plane/space/views/issue.py
@@ -106,7 +106,15 @@ class ProjectIssuesPublicEndpoint(BaseAPIView):
queryset=IssueVote.objects.select_related("actor"),
)
)
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
.order_by()
@@ -695,7 +703,15 @@ class IssueRetrievePublicEndpoint(BaseAPIView):
)
.select_related("workspace", "project", "state", "parent")
.prefetch_related("assignees", "labels", "issue_module__module")
- .annotate(cycle_id=F("issue_cycle__cycle_id"))
+ .annotate(
+ cycle_id=Case(
+ When(
+ issue_cycle__cycle__deleted_at__isnull=True,
+ then=F("issue_cycle__cycle_id"),
+ ),
+ default=None,
+ )
+ )
.annotate(
label_ids=Coalesce(
ArrayAgg(