Skip to content

Commit 1e1520b

Browse files
authored
[SILO-699] chore: add check for feature enabled for module and cycle create (#8146)
* add check for feature enabled for module and cycle create * add more checks
1 parent 0bc45e3 commit 1e1520b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

apps/api/plane/api/serializers/cycle.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Module imports
66
from .base import BaseSerializer
7-
from plane.db.models import Cycle, CycleIssue, User
7+
from plane.db.models import Cycle, CycleIssue, User, Project
88
from plane.utils.timezone_converter import convert_to_utc
99

1010

@@ -55,6 +55,18 @@ class Meta:
5555
]
5656

5757
def validate(self, data):
58+
project_id = self.initial_data.get("project_id") or (
59+
self.instance.project_id if self.instance and hasattr(self.instance, "project_id") else None
60+
)
61+
62+
if not project_id:
63+
raise serializers.ValidationError("Project ID is required")
64+
65+
project = Project.objects.filter(id=project_id).first()
66+
if not project:
67+
raise serializers.ValidationError("Project not found")
68+
if not project.cycle_view:
69+
raise serializers.ValidationError("Cycles are not enabled for this project")
5870
if (
5971
data.get("start_date", None) is not None
6072
and data.get("end_date", None) is not None
@@ -63,13 +75,6 @@ def validate(self, data):
6375
raise serializers.ValidationError("Start date cannot exceed end date")
6476

6577
if data.get("start_date", None) is not None and data.get("end_date", None) is not None:
66-
project_id = self.initial_data.get("project_id") or (
67-
self.instance.project_id if self.instance and hasattr(self.instance, "project_id") else None
68-
)
69-
70-
if not project_id:
71-
raise serializers.ValidationError("Project ID is required")
72-
7378
data["start_date"] = convert_to_utc(
7479
date=str(data.get("start_date").date()),
7580
project_id=project_id,

apps/api/plane/api/serializers/module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ModuleMember,
1111
ModuleIssue,
1212
ProjectMember,
13+
Project,
1314
)
1415

1516

@@ -53,6 +54,14 @@ class Meta:
5354
]
5455

5556
def validate(self, data):
57+
project_id = self.context.get("project_id")
58+
if not project_id:
59+
raise serializers.ValidationError("Project ID is required")
60+
project = Project.objects.get(id=project_id)
61+
if not project:
62+
raise serializers.ValidationError("Project not found")
63+
if not project.module_view:
64+
raise serializers.ValidationError("Modules are not enabled for this project")
5665
if (
5766
data.get("start_date", None) is not None
5867
and data.get("target_date", None) is not None

0 commit comments

Comments
 (0)