mirror of
https://github.com/makeplane/plane.git
synced 2025-12-16 11:57:56 +01:00
[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
This commit is contained in:
@@ -4,7 +4,7 @@ from rest_framework import serializers
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
@@ -55,6 +55,18 @@ class CycleCreateSerializer(BaseSerializer):
|
||||
]
|
||||
|
||||
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
|
||||
@@ -63,13 +75,6 @@ class CycleCreateSerializer(BaseSerializer):
|
||||
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,
|
||||
|
||||
@@ -10,6 +10,7 @@ from plane.db.models import (
|
||||
ModuleMember,
|
||||
ModuleIssue,
|
||||
ProjectMember,
|
||||
Project,
|
||||
)
|
||||
|
||||
|
||||
@@ -53,6 +54,14 @@ class ModuleCreateSerializer(BaseSerializer):
|
||||
]
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user