[WEB-5666] chore: set project timezone same as workspace timezone in project (#8340)
This commit is contained in:
parent
e8047b6f1c
commit
df710e00dc
4 changed files with 18 additions and 8 deletions
|
|
@ -3,13 +3,7 @@ import random
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.db.models import (
|
from plane.db.models import Project, ProjectIdentifier, WorkspaceMember, State, Estimate
|
||||||
Project,
|
|
||||||
ProjectIdentifier,
|
|
||||||
WorkspaceMember,
|
|
||||||
State,
|
|
||||||
Estimate,
|
|
||||||
)
|
|
||||||
|
|
||||||
from plane.utils.content_validator import (
|
from plane.utils.content_validator import (
|
||||||
validate_html_content,
|
validate_html_content,
|
||||||
|
|
@ -123,6 +117,7 @@ class ProjectCreateSerializer(BaseSerializer):
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
identifier = validated_data.get("identifier", "").strip().upper()
|
identifier = validated_data.get("identifier", "").strip().upper()
|
||||||
|
|
||||||
if identifier == "":
|
if identifier == "":
|
||||||
raise serializers.ValidationError(detail="Project Identifier is required")
|
raise serializers.ValidationError(detail="Project Identifier is required")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,9 @@ class ProjectListCreateAPIEndpoint(BaseAPIView):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
workspace = Workspace.objects.get(slug=slug)
|
workspace = Workspace.objects.get(slug=slug)
|
||||||
|
|
||||||
serializer = ProjectCreateSerializer(data={**request.data}, context={"workspace_id": workspace.id})
|
serializer = ProjectCreateSerializer(data={**request.data}, context={"workspace_id": workspace.id})
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ from plane.db.models import (
|
||||||
ProjectIdentifier,
|
ProjectIdentifier,
|
||||||
DeployBoard,
|
DeployBoard,
|
||||||
ProjectPublicMember,
|
ProjectPublicMember,
|
||||||
IssueSequence
|
IssueSequence,
|
||||||
)
|
)
|
||||||
from plane.utils.content_validator import (
|
from plane.utils.content_validator import (
|
||||||
validate_html_content,
|
validate_html_content,
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,11 @@ class Project(BaseModel):
|
||||||
external_source = models.CharField(max_length=255, null=True, blank=True)
|
external_source = models.CharField(max_length=255, null=True, blank=True)
|
||||||
external_id = models.CharField(max_length=255, blank=True, null=True)
|
external_id = models.CharField(max_length=255, blank=True, null=True)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
# Track if timezone is provided, if so, don't override it with the workspace timezone when saving
|
||||||
|
self.is_timezone_provided = kwargs.get("timezone") is not None
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cover_image_url(self):
|
def cover_image_url(self):
|
||||||
# Return cover image url
|
# Return cover image url
|
||||||
|
|
@ -155,7 +160,15 @@ class Project(BaseModel):
|
||||||
ordering = ("-created_at",)
|
ordering = ("-created_at",)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
from plane.db.models import Workspace
|
||||||
|
|
||||||
self.identifier = self.identifier.strip().upper()
|
self.identifier = self.identifier.strip().upper()
|
||||||
|
is_creating = self._state.adding
|
||||||
|
|
||||||
|
if is_creating and not self.is_timezone_provided:
|
||||||
|
workspace = Workspace.objects.get(id=self.workspace_id)
|
||||||
|
self.timezone = workspace.timezone
|
||||||
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue