forked from github/plane
fix: cycles date check for null and incomplete cycles endpoint (#580)
Co-authored-by: Vamsi Kurama <vamsi.kurama@gmail.com>
This commit is contained in:
parent
9064709d5d
commit
6a40dd911f
@ -95,6 +95,7 @@ from plane.api.views import (
|
|||||||
CycleFavoriteViewSet,
|
CycleFavoriteViewSet,
|
||||||
DraftCyclesEndpoint,
|
DraftCyclesEndpoint,
|
||||||
TransferCycleIssueEndpoint,
|
TransferCycleIssueEndpoint,
|
||||||
|
InCompleteCyclesEndpoint,
|
||||||
## End Cycles
|
## End Cycles
|
||||||
# Modules
|
# Modules
|
||||||
ModuleViewSet,
|
ModuleViewSet,
|
||||||
@ -637,6 +638,11 @@ urlpatterns = [
|
|||||||
TransferCycleIssueEndpoint.as_view(),
|
TransferCycleIssueEndpoint.as_view(),
|
||||||
name="transfer-issues",
|
name="transfer-issues",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/incomplete-cycles/",
|
||||||
|
InCompleteCyclesEndpoint.as_view(),
|
||||||
|
name="transfer-issues",
|
||||||
|
),
|
||||||
## End Cycles
|
## End Cycles
|
||||||
# Issue
|
# Issue
|
||||||
path(
|
path(
|
||||||
|
@ -53,6 +53,7 @@ from .cycle import (
|
|||||||
CycleFavoriteViewSet,
|
CycleFavoriteViewSet,
|
||||||
DraftCyclesEndpoint,
|
DraftCyclesEndpoint,
|
||||||
TransferCycleIssueEndpoint,
|
TransferCycleIssueEndpoint,
|
||||||
|
InCompleteCyclesEndpoint,
|
||||||
)
|
)
|
||||||
from .asset import FileAssetEndpoint, UserAssetsEndpoint
|
from .asset import FileAssetEndpoint, UserAssetsEndpoint
|
||||||
from .issue import (
|
from .issue import (
|
||||||
|
@ -135,7 +135,7 @@ class CycleViewSet(BaseViewSet):
|
|||||||
workspace__slug=slug, project_id=project_id, pk=pk
|
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(
|
return Response(
|
||||||
{
|
{
|
||||||
"error": "The Cycle has already been completed so it cannot be edited"
|
"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
|
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(
|
return Response(
|
||||||
{
|
{
|
||||||
"error": "The Cycle has already been completed so no new issues can be added"
|
"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"},
|
{"error": "Something went wrong please try again later"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
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,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user