Skip to content
Open
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
21 changes: 13 additions & 8 deletions apps/api/plane/api/serializers/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Module imports
from .base import BaseSerializer
from plane.db.models import Cycle, CycleIssue, User
from plane.db.models import Cycle, CycleIssue, User, Project
from plane.utils.timezone_converter import convert_to_utc


Expand Down Expand Up @@ -55,6 +55,18 @@ class Meta:
]

def validate(self, data):
project_id = self.initial_data.get("project_id") or (
self.instance.project_id if self.instance and hasattr(self.instance, "project_id") else None
)

if not project_id:
raise serializers.ValidationError("Project ID is required")

project = Project.objects.filter(id=project_id).first()
if not project:
raise serializers.ValidationError("Project not found")
if not project.cycle_view:
raise serializers.ValidationError("Cycles are not enabled for this project")
if (
data.get("start_date", None) is not None
and data.get("end_date", None) is not None
Expand All @@ -63,13 +75,6 @@ def validate(self, data):
raise serializers.ValidationError("Start date cannot exceed end date")

if data.get("start_date", None) is not None and data.get("end_date", None) is not None:
project_id = self.initial_data.get("project_id") or (
self.instance.project_id if self.instance and hasattr(self.instance, "project_id") else None
)

if not project_id:
raise serializers.ValidationError("Project ID is required")

data["start_date"] = convert_to_utc(
date=str(data.get("start_date").date()),
project_id=project_id,
Expand Down
9 changes: 9 additions & 0 deletions apps/api/plane/api/serializers/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ModuleMember,
ModuleIssue,
ProjectMember,
Project,
)


Expand Down Expand Up @@ -53,6 +54,14 @@ class Meta:
]

def validate(self, data):
project_id = self.context.get("project_id")
if not project_id:
raise serializers.ValidationError("Project ID is required")
project = Project.objects.get(id=project_id)
if not project:
raise serializers.ValidationError("Project not found")
if not project.module_view:
raise serializers.ValidationError("Modules are not enabled for this project")
if (
data.get("start_date", None) is not None
and data.get("target_date", None) is not None
Expand Down
Loading