diff --git a/apiserver/plane/app/serializers/__init__.py b/apiserver/plane/app/serializers/__init__.py index 094328fff..60c292336 100644 --- a/apiserver/plane/app/serializers/__init__.py +++ b/apiserver/plane/app/serializers/__init__.py @@ -104,6 +104,7 @@ from .estimate import ( EstimateSerializer, EstimatePointSerializer, EstimateReadSerializer, + WorkspaceEstimateSerializer, ) from .inbox import ( diff --git a/apiserver/plane/app/serializers/estimate.py b/apiserver/plane/app/serializers/estimate.py index a563c6956..675390080 100644 --- a/apiserver/plane/app/serializers/estimate.py +++ b/apiserver/plane/app/serializers/estimate.py @@ -61,3 +61,18 @@ class EstimateReadSerializer(BaseSerializer): "name", "description", ] + + +class WorkspaceEstimateSerializer(BaseSerializer): + points = EstimatePointSerializer(read_only=True, many=True) + + class Meta: + model = Estimate + fields = "__all__" + read_only_fields = [ + "points", + "name", + "description", + ] + + diff --git a/apiserver/plane/app/urls/workspace.py b/apiserver/plane/app/urls/workspace.py index d2d8f5c06..7e64e586a 100644 --- a/apiserver/plane/app/urls/workspace.py +++ b/apiserver/plane/app/urls/workspace.py @@ -20,6 +20,8 @@ from plane.app.views import ( WorkspaceLabelsEndpoint, WorkspaceProjectMemberEndpoint, WorkspaceUserPropertiesEndpoint, + WorkspaceStatesEndpoint, + WorkspaceEstimatesEndpoint, ) @@ -207,4 +209,14 @@ urlpatterns = [ WorkspaceUserPropertiesEndpoint.as_view(), name="workspace-user-filters", ), + path( + "workspaces//states/", + WorkspaceStatesEndpoint.as_view(), + name="workspace-state", + ), + path( + "workspaces//estimates/", + WorkspaceEstimatesEndpoint.as_view(), + name="workspace-estimate", + ), ] diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index 24684b7fa..5d9502790 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -47,6 +47,8 @@ from .workspace import ( WorkspaceLabelsEndpoint, WorkspaceProjectMemberEndpoint, WorkspaceUserPropertiesEndpoint, + WorkspaceStatesEndpoint, + WorkspaceEstimatesEndpoint, ) from .state import StateViewSet from .view import ( diff --git a/apiserver/plane/app/views/state.py b/apiserver/plane/app/views/state.py index 9c83cf006..2a4312e6b 100644 --- a/apiserver/plane/app/views/state.py +++ b/apiserver/plane/app/views/state.py @@ -9,9 +9,12 @@ from rest_framework.response import Response from rest_framework import status # Module imports -from . import BaseViewSet +from . import BaseViewSet, BaseAPIView from plane.app.serializers import StateSerializer -from plane.app.permissions import ProjectEntityPermission +from plane.app.permissions import ( + ProjectEntityPermission, + WorkspaceEntityPermission, +) from plane.db.models import State, Issue diff --git a/apiserver/plane/app/views/workspace.py b/apiserver/plane/app/views/workspace.py index 9cedff8f4..40e677c30 100644 --- a/apiserver/plane/app/views/workspace.py +++ b/apiserver/plane/app/views/workspace.py @@ -46,10 +46,12 @@ from plane.app.serializers import ( WorkspaceMemberMeSerializer, ProjectMemberRoleSerializer, WorkspaceUserPropertiesSerializer, + WorkspaceEstimateSerializer, ) from plane.app.views.base import BaseAPIView from . import BaseViewSet from plane.db.models import ( + State, User, Workspace, WorkspaceMemberInvite, @@ -67,6 +69,8 @@ from plane.db.models import ( CycleIssue, IssueReaction, WorkspaceUserProperties, + Estimate, + EstimatePoint, ) from plane.app.permissions import ( WorkSpaceBasePermission, @@ -1453,6 +1457,44 @@ class WorkspaceLabelsEndpoint(BaseAPIView): return Response(labels, status=status.HTTP_200_OK) +class WorkspaceStatesEndpoint(BaseAPIView): + permission_classes = [ + WorkspaceEntityPermission, + ] + + def get(self, request, slug): + states = State.objects.filter( + workspace__slug=slug, + project__project_projectmember__member=request.user, + ).values( + "id", "project_id", "workspace__slug", "name", "color", "group" + ) + return Response(states, status=status.HTTP_200_OK) + + +class WorkspaceEstimatesEndpoint(BaseAPIView): + permission_classes = [ + WorkspaceEntityPermission, + ] + + def get(self, request, slug): + estimate_ids = Project.objects.filter( + workspace__slug=slug, estimate__isnull=False + ).values_list("estimate_id", flat=True) + estimates = Estimate.objects.filter( + pk__in=estimate_ids + ).prefetch_related( + Prefetch( + "points", + queryset=EstimatePoint.objects.select_related( + "estimate", "workspace", "project" + ), + ) + ) + serializer = WorkspaceEstimateSerializer(estimates, many=True) + return Response(serializer.data, status=status.HTTP_200_OK) + + class WorkspaceUserPropertiesEndpoint(BaseAPIView): permission_classes = [ WorkspaceViewerPermission,