Skip to content

Commit c7bf912

Browse files
fix: state group choices (#8198)
1 parent 2980836 commit c7bf912

File tree

14 files changed

+87
-142
lines changed

14 files changed

+87
-142
lines changed

apps/api/plane/api/serializers/intake.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Module imports
22
from .base import BaseSerializer
33
from .issue import IssueExpandSerializer
4-
from plane.db.models import IntakeIssue, Issue
4+
from plane.db.models import IntakeIssue, Issue, State, StateGroup
55
from rest_framework import serializers
66

77

@@ -108,15 +108,14 @@ def validate(self, attrs):
108108
Validate that if status is being changed to accepted (1),
109109
the project has a default state to transition to.
110110
"""
111-
from plane.db.models import State
112111

113112
# Check if status is being updated to accepted
114113
if attrs.get("status") == 1:
115114
intake_issue = self.instance
116115
issue = intake_issue.issue
117116

118117
# Check if issue is in TRIAGE state
119-
if issue.state and issue.state.group == State.TRIAGE:
118+
if issue.state and issue.state.group == StateGroup.TRIAGE.value:
120119
# Verify default state exists before allowing the update
121120
default_state = State.objects.filter(
122121
workspace=intake_issue.workspace, project=intake_issue.project, default=True
@@ -133,15 +132,14 @@ def update(self, instance, validated_data):
133132
"""
134133
Update intake issue and transition associated issue state if accepted.
135134
"""
136-
from plane.db.models import State
137135

138136
# Update the intake issue with validated data
139137
instance = super().update(instance, validated_data)
140138

141139
# If status is accepted (1), update the associated issue state from TRIAGE to default
142140
if validated_data.get("status") == 1:
143141
issue = instance.issue
144-
if issue.state and issue.state.group == State.TRIAGE:
142+
if issue.state and issue.state.group == StateGroup.TRIAGE.value:
145143
# Get the default project state
146144
default_state = State.objects.filter(
147145
workspace=instance.workspace, project=instance.project, default=True

apps/api/plane/api/serializers/state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Module imports
22
from .base import BaseSerializer
3-
from plane.db.models import State
3+
from plane.db.models import State, StateGroup
44
from rest_framework import serializers
55

66

@@ -17,7 +17,7 @@ def validate(self, data):
1717
if data.get("default", False):
1818
State.objects.filter(project_id=self.context.get("project_id")).update(default=False)
1919

20-
if data.get("group", None) == State.TRIAGE:
20+
if data.get("group", None) == StateGroup.TRIAGE.value:
2121
raise serializers.ValidationError("Cannot create triage state")
2222
return data
2323

apps/api/plane/api/views/intake.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from plane.app.permissions import ProjectLitePermission
2525
from plane.bgtasks.issue_activities_task import issue_activity
26-
from plane.db.models import Intake, IntakeIssue, Issue, Project, ProjectMember, State
26+
from plane.db.models import Intake, IntakeIssue, Issue, Project, ProjectMember, State, StateGroup
2727
from plane.utils.host import base_host
2828
from .base import BaseAPIView
2929
from plane.db.models.intake import SourceType
@@ -170,8 +170,8 @@ def post(self, request, slug, project_id):
170170

171171
if not triage_state:
172172
triage_state = State.objects.create(
173-
name="Intake Triage",
174-
group=State.TRIAGE,
173+
name="Triage",
174+
group=StateGroup.TRIAGE.value,
175175
project_id=project_id,
176176
workspace_id=project.workspace_id,
177177
color="#4E5355",

apps/api/plane/api/views/project.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
DeployBoard,
2525
ProjectMember,
2626
State,
27+
DEFAULT_STATES,
2728
Workspace,
2829
UserFavorite,
2930
)
@@ -232,47 +233,6 @@ def post(self, request, slug):
232233
user_id=serializer.instance.project_lead,
233234
)
234235

235-
# Default states
236-
states = [
237-
{
238-
"name": "Backlog",
239-
"color": "#60646C",
240-
"sequence": 15000,
241-
"group": "backlog",
242-
"default": True,
243-
},
244-
{
245-
"name": "Todo",
246-
"color": "#60646C",
247-
"sequence": 25000,
248-
"group": "unstarted",
249-
},
250-
{
251-
"name": "In Progress",
252-
"color": "#F59E0B",
253-
"sequence": 35000,
254-
"group": "started",
255-
},
256-
{
257-
"name": "Done",
258-
"color": "#46A758",
259-
"sequence": 45000,
260-
"group": "completed",
261-
},
262-
{
263-
"name": "Cancelled",
264-
"color": "#9AA4BC",
265-
"sequence": 55000,
266-
"group": "cancelled",
267-
},
268-
{
269-
"name": "Intake Triage",
270-
"color": "#4E5355",
271-
"sequence": 65000,
272-
"group": State.TRIAGE,
273-
},
274-
]
275-
276236
State.objects.bulk_create(
277237
[
278238
State(
@@ -285,7 +245,7 @@ def post(self, request, slug):
285245
default=state.get("default", False),
286246
created_by=request.user,
287247
)
288-
for state in states
248+
for state in DEFAULT_STATES
289249
]
290250
)
291251

apps/api/plane/app/serializers/intake.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .project import ProjectLiteSerializer
88
from .state import StateLiteSerializer
99
from .user import UserLiteSerializer
10-
from plane.db.models import Intake, IntakeIssue, Issue
10+
from plane.db.models import Intake, IntakeIssue, Issue, StateGroup, State
1111

1212

1313
class IntakeSerializer(BaseSerializer):
@@ -41,15 +41,14 @@ def validate(self, attrs):
4141
Validate that if status is being changed to accepted (1),
4242
the project has a default state to transition to.
4343
"""
44-
from plane.db.models import State
4544

4645
# Check if status is being updated to accepted
4746
if attrs.get("status") == 1:
4847
intake_issue = self.instance
4948
issue = intake_issue.issue
5049

5150
# Check if issue is in TRIAGE state
52-
if issue.state and issue.state.group == State.TRIAGE:
51+
if issue.state and issue.state.group == StateGroup.TRIAGE.value:
5352
# Verify default state exists before allowing the update
5453
default_state = State.objects.filter(
5554
workspace=intake_issue.workspace, project=intake_issue.project, default=True
@@ -63,20 +62,16 @@ def validate(self, attrs):
6362
return attrs
6463

6564
def update(self, instance, validated_data):
66-
from plane.db.models import State
67-
6865
# Update the intake issue
6966
instance = super().update(instance, validated_data)
7067

7168
# If status is accepted (1), transition the issue state from TRIAGE to default
7269
if validated_data.get("status") == 1:
7370
issue = instance.issue
74-
if issue.state and issue.state.group == State.TRIAGE:
71+
if issue.state and issue.state.group == StateGroup.TRIAGE.value:
7572
# Get the default project state
7673
default_state = State.objects.filter(
77-
workspace=instance.workspace,
78-
project=instance.project,
79-
default=True
74+
workspace=instance.workspace, project=instance.project, default=True
8075
).first()
8176
if default_state:
8277
issue.state = default_state

apps/api/plane/app/serializers/state.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .base import BaseSerializer
33
from rest_framework import serializers
44

5-
from plane.db.models import State
5+
from plane.db.models import State, StateGroup
66

77

88
class StateSerializer(BaseSerializer):
@@ -25,8 +25,7 @@ class Meta:
2525
read_only_fields = ["workspace", "project"]
2626

2727
def validate(self, attrs):
28-
29-
if attrs.get("group") == State.TRIAGE:
28+
if attrs.get("group") == StateGroup.TRIAGE.value:
3029
raise serializers.ValidationError("Cannot create triage state")
3130
return attrs
3231

apps/api/plane/app/views/intake/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
IntakeIssue,
2323
Issue,
2424
State,
25+
StateGroup,
2526
IssueLink,
2627
FileAsset,
2728
Project,
@@ -234,8 +235,8 @@ def create(self, request, slug, project_id):
234235
triage_state = State.triage_objects.filter(project_id=project_id, workspace__slug=slug).first()
235236
if not triage_state:
236237
triage_state = State.objects.create(
237-
name="Intake Triage",
238-
group=State.TRIAGE,
238+
name="Triage",
239+
group=StateGroup.TRIAGE.value,
239240
project_id=project_id,
240241
workspace_id=project.workspace_id,
241242
color="#4E5355",

apps/api/plane/app/views/project/base.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
ProjectIdentifier,
3232
ProjectMember,
3333
State,
34+
DEFAULT_STATES,
3435
Workspace,
3536
WorkspaceMember,
3637
)
@@ -264,47 +265,6 @@ def create(self, request, slug):
264265
user_id=serializer.data["project_lead"],
265266
)
266267

267-
# Default states
268-
states = [
269-
{
270-
"name": "Backlog",
271-
"color": "#60646C",
272-
"sequence": 15000,
273-
"group": "backlog",
274-
"default": True,
275-
},
276-
{
277-
"name": "Todo",
278-
"color": "#60646C",
279-
"sequence": 25000,
280-
"group": "unstarted",
281-
},
282-
{
283-
"name": "In Progress",
284-
"color": "#F59E0B",
285-
"sequence": 35000,
286-
"group": "started",
287-
},
288-
{
289-
"name": "Done",
290-
"color": "#46A758",
291-
"sequence": 45000,
292-
"group": "completed",
293-
},
294-
{
295-
"name": "Cancelled",
296-
"color": "#9AA4BC",
297-
"sequence": 55000,
298-
"group": "cancelled",
299-
},
300-
{
301-
"name": "Intake Triage",
302-
"color": "#4E5355",
303-
"sequence": 65000,
304-
"group": State.TRIAGE,
305-
},
306-
]
307-
308268
State.objects.bulk_create(
309269
[
310270
State(
@@ -317,7 +277,7 @@ def create(self, request, slug):
317277
default=state.get("default", False),
318278
created_by=request.user,
319279
)
320-
for state in states
280+
for state in DEFAULT_STATES
321281
]
322282
)
323283

apps/api/plane/app/views/state/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get(self, request, slug, project_id):
135135
state = State.triage_objects.filter(workspace__slug=slug, project_id=project_id).first()
136136
if not state:
137137
return Response(
138-
{"error": "Intake triage state not found"},
138+
{"error": "Triage state not found"},
139139
status=status.HTTP_404_NOT_FOUND,
140140
)
141141

apps/api/plane/bgtasks/dummy_data_task.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Project,
1818
ProjectMember,
1919
State,
20+
StateGroup,
2021
Label,
2122
Cycle,
2223
Module,
@@ -264,7 +265,9 @@ def create_issues(workspace, project, user_id, issue_count):
264265
Faker.seed(0)
265266

266267
states = (
267-
State.objects.filter(workspace=workspace, project=project).exclude(group=State.TRIAGE).values_list("id", flat=True)
268+
State.objects.filter(workspace=workspace, project=project)
269+
.exclude(group=StateGroup.TRIAGE.value)
270+
.values_list("id", flat=True)
268271
)
269272
creators = ProjectMember.objects.filter(workspace=workspace, project=project).values_list("member_id", flat=True)
270273

0 commit comments

Comments
 (0)