From 6a40dd911f3daa3e62da58a63f4aeadb55a5c1b0 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 30 Mar 2023 01:26:14 +0530 Subject: [PATCH] fix: cycles date check for null and incomplete cycles endpoint (#580) Co-authored-by: Vamsi Kurama --- apiserver/plane/api/urls.py | 6 ++++++ apiserver/plane/api/views/__init__.py | 1 + apiserver/plane/api/views/cycle.py | 23 +++++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index 16e292fb4..d408be37e 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -95,6 +95,7 @@ from plane.api.views import ( CycleFavoriteViewSet, DraftCyclesEndpoint, TransferCycleIssueEndpoint, + InCompleteCyclesEndpoint, ## End Cycles # Modules ModuleViewSet, @@ -637,6 +638,11 @@ urlpatterns = [ TransferCycleIssueEndpoint.as_view(), name="transfer-issues", ), + path( + "workspaces//projects//incomplete-cycles/", + InCompleteCyclesEndpoint.as_view(), + name="transfer-issues", + ), ## End Cycles # Issue path( diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index 9338ca404..b6171d68b 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -53,6 +53,7 @@ from .cycle import ( CycleFavoriteViewSet, DraftCyclesEndpoint, TransferCycleIssueEndpoint, + InCompleteCyclesEndpoint, ) from .asset import FileAssetEndpoint, UserAssetsEndpoint from .issue import ( diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index 13ee8b1e3..6f1eb1aa6 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -135,7 +135,7 @@ class CycleViewSet(BaseViewSet): workspace__slug=slug, project_id=project_id, pk=pk ) - if cycle.end_date < timezone.now().date(): + if cycle.end_date is not None and cycle.end_date < timezone.now().date(): return Response( { "error": "The Cycle has already been completed so it cannot be edited" @@ -260,7 +260,7 @@ class CycleIssueViewSet(BaseViewSet): workspace__slug=slug, project_id=project_id, pk=cycle_id ) - if cycle.end_date < timezone.now().date(): + if cycle.end_date is not None and cycle.end_date < timezone.now().date(): return Response( { "error": "The Cycle has already been completed so no new issues can be added" @@ -776,3 +776,22 @@ class TransferCycleIssueEndpoint(BaseAPIView): {"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST, ) + + +class InCompleteCyclesEndpoint(BaseAPIView): + def get(self, request, slug, project_id): + try: + cycles = Cycle.objects.filter( + Q(end_date__gte=timezone.now().date()) | Q(end_date__isnull=True), + workspace__slug=slug, + project_id=project_id, + ).select_related("owned_by") + + serializer = CycleSerializer(cycles, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + )