Skip to content

Commit 75a9b71

Browse files
authored
[WEB-3513] fix: return cycle start and end dates in project's timezone
1 parent ef42ce0 commit 75a9b71

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

apiserver/plane/api/serializers/cycle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Third party imports
2+
import pytz
23
from rest_framework import serializers
34

45
# Module imports
@@ -18,6 +19,14 @@ class CycleSerializer(BaseSerializer):
1819
completed_estimates = serializers.FloatField(read_only=True)
1920
started_estimates = serializers.FloatField(read_only=True)
2021

22+
def __init__(self, *args, **kwargs):
23+
super().__init__(*args, **kwargs)
24+
project = self.context.get("project")
25+
if project and project.timezone:
26+
project_timezone = pytz.timezone(project.timezone)
27+
self.fields["start_date"].timezone = project_timezone
28+
self.fields["end_date"].timezone = project_timezone
29+
2130
def validate(self, data):
2231
if (
2332
data.get("start_date", None) is not None

apiserver/plane/api/views/cycle.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ def get_queryset(self):
137137
)
138138

139139
def get(self, request, slug, project_id, pk=None):
140+
project = Project.objects.get(workspace__slug=slug, pk=project_id)
140141
if pk:
141142
queryset = self.get_queryset().filter(archived_at__isnull=True).get(pk=pk)
142143
data = CycleSerializer(
143-
queryset, fields=self.fields, expand=self.expand
144+
queryset, fields=self.fields,
145+
expand=self.expand, context={"project": project}
144146
).data
145147
return Response(data, status=status.HTTP_200_OK)
146148
queryset = self.get_queryset().filter(archived_at__isnull=True)
@@ -152,7 +154,8 @@ def get(self, request, slug, project_id, pk=None):
152154
start_date__lte=timezone.now(), end_date__gte=timezone.now()
153155
)
154156
data = CycleSerializer(
155-
queryset, many=True, fields=self.fields, expand=self.expand
157+
queryset, many=True, fields=self.fields,
158+
expand=self.expand, context={"project": project}
156159
).data
157160
return Response(data, status=status.HTTP_200_OK)
158161

@@ -163,7 +166,8 @@ def get(self, request, slug, project_id, pk=None):
163166
request=request,
164167
queryset=(queryset),
165168
on_results=lambda cycles: CycleSerializer(
166-
cycles, many=True, fields=self.fields, expand=self.expand
169+
cycles, many=True, fields=self.fields,
170+
expand=self.expand, context={"project": project}
167171
).data,
168172
)
169173

@@ -174,7 +178,8 @@ def get(self, request, slug, project_id, pk=None):
174178
request=request,
175179
queryset=(queryset),
176180
on_results=lambda cycles: CycleSerializer(
177-
cycles, many=True, fields=self.fields, expand=self.expand
181+
cycles, many=True, fields=self.fields,
182+
expand=self.expand, context={"project": project}
178183
).data,
179184
)
180185

@@ -185,7 +190,8 @@ def get(self, request, slug, project_id, pk=None):
185190
request=request,
186191
queryset=(queryset),
187192
on_results=lambda cycles: CycleSerializer(
188-
cycles, many=True, fields=self.fields, expand=self.expand
193+
cycles, many=True, fields=self.fields,
194+
expand=self.expand, context={"project": project}
189195
).data,
190196
)
191197

@@ -198,14 +204,16 @@ def get(self, request, slug, project_id, pk=None):
198204
request=request,
199205
queryset=(queryset),
200206
on_results=lambda cycles: CycleSerializer(
201-
cycles, many=True, fields=self.fields, expand=self.expand
207+
cycles, many=True, fields=self.fields,
208+
expand=self.expand, context={"project": project}
202209
).data,
203210
)
204211
return self.paginate(
205212
request=request,
206213
queryset=(queryset),
207214
on_results=lambda cycles: CycleSerializer(
208-
cycles, many=True, fields=self.fields, expand=self.expand
215+
cycles, many=True, fields=self.fields,
216+
expand=self.expand, context={"project": project}
209217
).data,
210218
)
211219

apiserver/plane/app/views/cycle/base.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def list(self, request, slug, project_id):
268268
)
269269
datetime_fields = ["start_date", "end_date"]
270270
data = user_timezone_converter(
271-
data, datetime_fields, request.user.user_timezone
271+
data, datetime_fields, project_timezone
272272
)
273273
return Response(data, status=status.HTTP_200_OK)
274274

@@ -318,9 +318,13 @@ def create(self, request, slug, project_id):
318318
.first()
319319
)
320320

321+
# Fetch the project timezone
322+
project = Project.objects.get(id=self.kwargs.get("project_id"))
323+
project_timezone = project.timezone
324+
321325
datetime_fields = ["start_date", "end_date"]
322326
cycle = user_timezone_converter(
323-
cycle, datetime_fields, request.user.user_timezone
327+
cycle, datetime_fields, project_timezone
324328
)
325329

326330
# Send the model activity
@@ -407,9 +411,13 @@ def partial_update(self, request, slug, project_id, pk):
407411
"created_by",
408412
).first()
409413

414+
# Fetch the project timezone
415+
project = Project.objects.get(id=self.kwargs.get("project_id"))
416+
project_timezone = project.timezone
417+
410418
datetime_fields = ["start_date", "end_date"]
411419
cycle = user_timezone_converter(
412-
cycle, datetime_fields, request.user.user_timezone
420+
cycle, datetime_fields, project_timezone
413421
)
414422

415423
# Send the model activity
@@ -480,10 +488,11 @@ def retrieve(self, request, slug, project_id, pk):
480488
)
481489

482490
queryset = queryset.first()
491+
# Fetch the project timezone
492+
project = Project.objects.get(id=self.kwargs.get("project_id"))
493+
project_timezone = project.timezone
483494
datetime_fields = ["start_date", "end_date"]
484-
data = user_timezone_converter(
485-
data, datetime_fields, request.user.user_timezone
486-
)
495+
data = user_timezone_converter(data, datetime_fields, project_timezone)
487496

488497
recent_visited_task.delay(
489498
slug=slug,

0 commit comments

Comments
 (0)