Skip to content

Commit db91942

Browse files
[WEB-2693] chore: removed the deleted cycles from the issue list (#5868)
* chore: added the deleted cycles from list * chore: removed the extra annotation * chore: removed the frontend comment
1 parent 2982cd4 commit db91942

File tree

12 files changed

+174
-28
lines changed

12 files changed

+174
-28
lines changed

apiserver/plane/api/views/issue.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ def get(self, request, slug, project_id, pk=None):
202202

203203
issue_queryset = (
204204
self.get_queryset()
205-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
205+
.annotate(
206+
cycle_id=Case(
207+
When(
208+
Q(issue_cycle__cycle__deleted_at__isnull=True),
209+
then=F("issue_cycle__cycle_id"),
210+
),
211+
default=None,
212+
)
213+
)
206214
.annotate(
207215
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
208216
.order_by()

apiserver/plane/app/views/cycle/issue.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Django imports
55
from django.core import serializers
6-
from django.db.models import F, Func, OuterRef, Q
6+
from django.db.models import F, Func, OuterRef, Q, Case, When
77
from django.utils import timezone
88
from django.utils.decorators import method_decorator
99
from django.views.decorators.gzip import gzip_page
@@ -102,7 +102,15 @@ def list(self, request, slug, project_id, cycle_id):
102102
"issue_cycle__cycle",
103103
)
104104
.filter(**filters)
105-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
105+
.annotate(
106+
cycle_id=Case(
107+
When(
108+
issue_cycle__cycle__deleted_at__isnull=True,
109+
then=F("issue_cycle__cycle_id"),
110+
),
111+
default=None,
112+
)
113+
)
106114
.annotate(
107115
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
108116
.order_by()

apiserver/plane/app/views/inbox/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Django import
55
from django.utils import timezone
6-
from django.db.models import Q, Count, OuterRef, Func, F, Prefetch
6+
from django.db.models import Q, Count, OuterRef, Func, F, Prefetch, Case, When
77
from django.core.serializers.json import DjangoJSONEncoder
88
from django.contrib.postgres.aggregates import ArrayAgg
99
from django.contrib.postgres.fields import ArrayField
@@ -112,7 +112,15 @@ def get_queryset(self):
112112
),
113113
)
114114
)
115-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
115+
.annotate(
116+
cycle_id=Case(
117+
When(
118+
issue_cycle__cycle__deleted_at__isnull=True,
119+
then=F("issue_cycle__cycle_id"),
120+
),
121+
default=None,
122+
)
123+
)
116124
.annotate(
117125
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
118126
.order_by()

apiserver/plane/app/views/issue/archive.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33

44
# Django imports
55
from django.core.serializers.json import DjangoJSONEncoder
6-
from django.db.models import (
7-
F,
8-
Func,
9-
OuterRef,
10-
Q,
11-
Prefetch,
12-
Exists,
13-
)
6+
from django.db.models import F, Func, OuterRef, Q, Prefetch, Exists, Case, When
147
from django.utils import timezone
158
from django.utils.decorators import method_decorator
169
from django.views.decorators.gzip import gzip_page
@@ -71,7 +64,15 @@ def get_queryset(self):
7164
.filter(workspace__slug=self.kwargs.get("slug"))
7265
.select_related("workspace", "project", "state", "parent")
7366
.prefetch_related("assignees", "labels", "issue_module__module")
74-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
67+
.annotate(
68+
cycle_id=Case(
69+
When(
70+
issue_cycle__cycle__deleted_at__isnull=True,
71+
then=F("issue_cycle__cycle_id"),
72+
),
73+
default=None,
74+
)
75+
)
7576
.annotate(
7677
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
7778
.order_by()

apiserver/plane/app/views/issue/base.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
Q,
1515
UUIDField,
1616
Value,
17+
When,
18+
Case,
1719
)
1820
from django.db.models.functions import Coalesce
1921
from django.utils import timezone
@@ -83,7 +85,15 @@ def get(self, request, slug, project_id):
8385
.filter(workspace__slug=self.kwargs.get("slug"))
8486
.select_related("workspace", "project", "state", "parent")
8587
.prefetch_related("assignees", "labels", "issue_module__module")
86-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
88+
.annotate(
89+
cycle_id=Case(
90+
When(
91+
issue_cycle__cycle__deleted_at__isnull=True,
92+
then=F("issue_cycle__cycle_id"),
93+
),
94+
default=None,
95+
)
96+
)
8797
.annotate(
8898
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
8999
.order_by()
@@ -207,7 +217,15 @@ def get_queryset(self):
207217
.filter(workspace__slug=self.kwargs.get("slug"))
208218
.select_related("workspace", "project", "state", "parent")
209219
.prefetch_related("assignees", "labels", "issue_module__module")
210-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
220+
.annotate(
221+
cycle_id=Case(
222+
When(
223+
issue_cycle__cycle__deleted_at__isnull=True,
224+
then=F("issue_cycle__cycle_id"),
225+
),
226+
default=None,
227+
)
228+
)
211229
.annotate(
212230
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
213231
.order_by()
@@ -757,7 +775,15 @@ def get_queryset(self):
757775
"workspace", "project", "state", "parent"
758776
)
759777
.prefetch_related("assignees", "labels", "issue_module__module")
760-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
778+
.annotate(
779+
cycle_id=Case(
780+
When(
781+
issue_cycle__cycle__deleted_at__isnull=True,
782+
then=F("issue_cycle__cycle_id"),
783+
),
784+
default=None,
785+
)
786+
)
761787
.annotate(
762788
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
763789
.order_by()

apiserver/plane/app/views/issue/relation.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
# Django imports
55
from django.utils import timezone
6-
from django.db.models import Q, OuterRef, F, Func, UUIDField, Value, CharField
6+
from django.db.models import (
7+
Q,
8+
OuterRef,
9+
F,
10+
Func,
11+
UUIDField,
12+
Value,
13+
CharField,
14+
Case,
15+
When,
16+
)
717
from django.core.serializers.json import DjangoJSONEncoder
818
from django.db.models.functions import Coalesce
919
from django.contrib.postgres.aggregates import ArrayAgg
@@ -83,7 +93,15 @@ def list(self, request, slug, project_id, issue_id):
8393
Issue.issue_objects.filter(workspace__slug=slug)
8494
.select_related("workspace", "project", "state", "parent")
8595
.prefetch_related("assignees", "labels", "issue_module__module")
86-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
96+
.annotate(
97+
cycle_id=Case(
98+
When(
99+
issue_cycle__cycle__deleted_at__isnull=True,
100+
then=F("issue_cycle__cycle_id"),
101+
),
102+
default=None,
103+
)
104+
)
87105
.annotate(
88106
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
89107
.order_by()

apiserver/plane/app/views/issue/sub_issue.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
Q,
1111
Value,
1212
UUIDField,
13+
Case,
14+
When,
1315
)
1416
from django.utils.decorators import method_decorator
1517
from django.views.decorators.gzip import gzip_page
@@ -48,7 +50,15 @@ def get(self, request, slug, project_id, issue_id):
4850
)
4951
.select_related("workspace", "project", "state", "parent")
5052
.prefetch_related("assignees", "labels", "issue_module__module")
51-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
53+
.annotate(
54+
cycle_id=Case(
55+
When(
56+
issue_cycle__cycle__deleted_at__isnull=True,
57+
then=F("issue_cycle__cycle_id"),
58+
),
59+
default=None,
60+
)
61+
)
5262
.annotate(
5363
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
5464
.order_by()

apiserver/plane/app/views/module/issue.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Func,
77
OuterRef,
88
Q,
9+
Case,
10+
When,
911
)
1012

1113
# Django Imports
@@ -65,7 +67,15 @@ def get_queryset(self):
6567
)
6668
.select_related("workspace", "project", "state", "parent")
6769
.prefetch_related("assignees", "labels", "issue_module__module")
68-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
70+
.annotate(
71+
cycle_id=Case(
72+
When(
73+
issue_cycle__cycle__deleted_at__isnull=True,
74+
then=F("issue_cycle__cycle_id"),
75+
),
76+
default=None,
77+
)
78+
)
6979
.annotate(
7080
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
7181
.order_by()

apiserver/plane/app/views/view/base.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Q,
1010
UUIDField,
1111
Value,
12+
Case,
13+
When,
1214
)
1315
from django.db.models.functions import Coalesce
1416
from django.utils.decorators import method_decorator
@@ -205,7 +207,15 @@ def get_queryset(self):
205207
)
206208
.select_related("workspace", "project", "state", "parent")
207209
.prefetch_related("assignees", "labels", "issue_module__module")
208-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
210+
.annotate(
211+
cycle_id=Case(
212+
When(
213+
issue_cycle__cycle__deleted_at__isnull=True,
214+
then=F("issue_cycle__cycle_id"),
215+
),
216+
default=None,
217+
)
218+
)
209219
.annotate(
210220
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
211221
.order_by()
@@ -275,7 +285,15 @@ def list(self, request, slug):
275285
issue_queryset = (
276286
self.get_queryset()
277287
.filter(**filters)
278-
.annotate(cycle_id=F("issue_cycle__cycle_id"))
288+
.annotate(
289+
cycle_id=Case(
290+
When(
291+
issue_cycle__cycle__deleted_at__isnull=True,
292+
then=F("issue_cycle__cycle_id"),
293+
),
294+
default=None,
295+
)
296+
)
279297
)
280298

281299
# 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

apiserver/plane/app/views/workspace/draft.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
Q,
1313
UUIDField,
1414
Value,
15+
Case,
16+
When,
1517
)
1618
from django.db.models.functions import Coalesce
1719
from django.utils.decorators import method_decorator
@@ -55,6 +57,15 @@ def get_queryset(self):
5557
"assignees", "labels", "draft_issue_module__module"
5658
)
5759
.annotate(cycle_id=F("draft_issue_cycle__cycle_id"))
60+
.annotate(
61+
cycle_id=Case(
62+
When(
63+
issue_cycle__cycle__deleted_at__isnull=True,
64+
then=F("issue_cycle__cycle_id"),
65+
),
66+
default=None,
67+
)
68+
)
5869
.annotate(
5970
label_ids=Coalesce(
6071
ArrayAgg(
@@ -81,8 +92,12 @@ def get_queryset(self):
8192
"draft_issue_module__module_id",
8293
distinct=True,
8394
filter=~Q(draft_issue_module__module_id__isnull=True)
84-
& Q(draft_issue_module__module__archived_at__isnull=True)
85-
& Q(draft_issue_module__module__deleted_at__isnull=True),
95+
& Q(
96+
draft_issue_module__module__archived_at__isnull=True
97+
)
98+
& Q(
99+
draft_issue_module__module__deleted_at__isnull=True
100+
),
86101
),
87102
Value([], output_field=ArrayField(UUIDField())),
88103
),

0 commit comments

Comments
 (0)