From 6d8eda98146c26bf0963018535e453393dc9af2d Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 30 Mar 2023 01:25:32 +0530 Subject: [PATCH] chore: update API endpoints for analytics (#574) * chore: return workspace details on project create and update * chore: update endpoints to return workspace and project details --------- Co-authored-by: Vamsi Kurama --- apiserver/plane/api/serializers/cycle.py | 7 ++++++- apiserver/plane/api/serializers/issue.py | 6 +++--- apiserver/plane/api/serializers/module.py | 16 ++++++++++++++-- apiserver/plane/api/serializers/page.py | 4 ++++ apiserver/plane/api/serializers/project.py | 4 +++- apiserver/plane/api/serializers/state.py | 5 +++++ apiserver/plane/api/serializers/view.py | 5 ++++- apiserver/plane/api/serializers/workspace.py | 15 +++++++++++---- apiserver/plane/api/views/issue.py | 3 --- 9 files changed, 50 insertions(+), 15 deletions(-) diff --git a/apiserver/plane/api/serializers/cycle.py b/apiserver/plane/api/serializers/cycle.py index fefd7b817..5c06a28e7 100644 --- a/apiserver/plane/api/serializers/cycle.py +++ b/apiserver/plane/api/serializers/cycle.py @@ -5,6 +5,8 @@ from rest_framework import serializers from .base import BaseSerializer from .user import UserLiteSerializer from .issue import IssueStateSerializer +from .workspace import WorkspaceLiteSerializer +from .project import ProjectLiteSerializer from plane.db.models import Cycle, CycleIssue, CycleFavorite @@ -17,7 +19,10 @@ class CycleSerializer(BaseSerializer): started_issues = serializers.IntegerField(read_only=True) unstarted_issues = serializers.IntegerField(read_only=True) backlog_issues = serializers.IntegerField(read_only=True) - + + workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") + project_detail = ProjectLiteSerializer(read_only=True, source="project") + class Meta: model = Cycle fields = "__all__" diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 4dc62f2d9..b8f86cdcf 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -7,7 +7,7 @@ from .user import UserLiteSerializer from .state import StateSerializer, StateLiteSerializer from .user import UserLiteSerializer from .project import ProjectSerializer, ProjectLiteSerializer -from .workspace import WorkSpaceSerializer +from .workspace import WorkspaceLiteSerializer from plane.db.models import ( User, Issue, @@ -50,8 +50,8 @@ class IssueFlatSerializer(BaseSerializer): class IssueCreateSerializer(BaseSerializer): state_detail = StateSerializer(read_only=True, source="state") created_by_detail = UserLiteSerializer(read_only=True, source="created_by") - project_detail = ProjectSerializer(read_only=True, source="project") - workspace_detail = WorkSpaceSerializer(read_only=True, source="workspace") + project_detail = ProjectLiteSerializer(read_only=True, source="project") + workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") assignees_list = serializers.ListField( child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()), diff --git a/apiserver/plane/api/serializers/module.py b/apiserver/plane/api/serializers/module.py index 4c26f24cf..8e976d318 100644 --- a/apiserver/plane/api/serializers/module.py +++ b/apiserver/plane/api/serializers/module.py @@ -4,10 +4,18 @@ from rest_framework import serializers # Module imports from .base import BaseSerializer from .user import UserLiteSerializer -from .project import ProjectSerializer +from .project import ProjectSerializer, ProjectLiteSerializer +from .workspace import WorkspaceLiteSerializer from .issue import IssueStateSerializer -from plane.db.models import User, Module, ModuleMember, ModuleIssue, ModuleLink, ModuleFavorite +from plane.db.models import ( + User, + Module, + ModuleMember, + ModuleIssue, + ModuleLink, + ModuleFavorite, +) class ModuleWriteSerializer(BaseSerializer): @@ -17,6 +25,9 @@ class ModuleWriteSerializer(BaseSerializer): required=False, ) + project_detail = ProjectLiteSerializer(source="project", read_only=True) + workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True) + class Meta: model = Module fields = "__all__" @@ -154,6 +165,7 @@ class ModuleSerializer(BaseSerializer): "updated_at", ] + class ModuleFavoriteSerializer(BaseSerializer): module_detail = ModuleFlatSerializer(source="module", read_only=True) diff --git a/apiserver/plane/api/serializers/page.py b/apiserver/plane/api/serializers/page.py index c7f9f0264..f0c121cfb 100644 --- a/apiserver/plane/api/serializers/page.py +++ b/apiserver/plane/api/serializers/page.py @@ -4,6 +4,8 @@ from rest_framework import serializers # Module imports from .base import BaseSerializer from .issue import IssueFlatSerializer, LabelSerializer +from .workspace import WorkspaceLiteSerializer +from .project import ProjectLiteSerializer from plane.db.models import Page, PageBlock, PageFavorite, PageLabel, Label @@ -29,6 +31,8 @@ class PageSerializer(BaseSerializer): required=False, ) blocks = PageBlockSerializer(read_only=True, many=True) + project_detail = ProjectLiteSerializer(source="project", read_only=True) + workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True) class Meta: model = Page diff --git a/apiserver/plane/api/serializers/project.py b/apiserver/plane/api/serializers/project.py index 2bdfdf02c..de9706d72 100644 --- a/apiserver/plane/api/serializers/project.py +++ b/apiserver/plane/api/serializers/project.py @@ -6,7 +6,7 @@ from rest_framework import serializers # Module imports from .base import BaseSerializer -from plane.api.serializers.workspace import WorkSpaceSerializer +from plane.api.serializers.workspace import WorkSpaceSerializer, WorkspaceLiteSerializer from plane.api.serializers.user import UserLiteSerializer from plane.db.models import ( Project, @@ -18,6 +18,8 @@ from plane.db.models import ( class ProjectSerializer(BaseSerializer): + workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True) + class Meta: model = Project fields = "__all__" diff --git a/apiserver/plane/api/serializers/state.py b/apiserver/plane/api/serializers/state.py index 37e94d661..097bc4c93 100644 --- a/apiserver/plane/api/serializers/state.py +++ b/apiserver/plane/api/serializers/state.py @@ -1,10 +1,15 @@ # Module imports from .base import BaseSerializer +from .workspace import WorkspaceLiteSerializer +from .project import ProjectLiteSerializer from plane.db.models import State class StateSerializer(BaseSerializer): + workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") + project_detail = ProjectLiteSerializer(read_only=True, source="project") + class Meta: model = State fields = "__all__" diff --git a/apiserver/plane/api/serializers/view.py b/apiserver/plane/api/serializers/view.py index b998aace3..021bcfb72 100644 --- a/apiserver/plane/api/serializers/view.py +++ b/apiserver/plane/api/serializers/view.py @@ -3,13 +3,16 @@ from rest_framework import serializers # Module imports from .base import BaseSerializer - +from .workspace import WorkspaceLiteSerializer +from .project import ProjectLiteSerializer from plane.db.models import IssueView, IssueViewFavorite from plane.utils.issue_filters import issue_filters class IssueViewSerializer(BaseSerializer): is_favorite = serializers.BooleanField(read_only=True) + project_detail = ProjectLiteSerializer(source="project", read_only=True) + workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True) class Meta: model = IssueView diff --git a/apiserver/plane/api/serializers/workspace.py b/apiserver/plane/api/serializers/workspace.py index 6936101ec..7b3cb1896 100644 --- a/apiserver/plane/api/serializers/workspace.py +++ b/apiserver/plane/api/serializers/workspace.py @@ -10,7 +10,6 @@ from plane.db.models import Workspace, WorkspaceMember, Team, WorkspaceMemberInv class WorkSpaceSerializer(BaseSerializer): - owner = UserLiteSerializer(read_only=True) total_members = serializers.IntegerField(read_only=True) @@ -28,7 +27,6 @@ class WorkSpaceSerializer(BaseSerializer): class WorkSpaceMemberSerializer(BaseSerializer): - member = UserLiteSerializer(read_only=True) workspace = WorkSpaceSerializer(read_only=True) @@ -38,7 +36,6 @@ class WorkSpaceMemberSerializer(BaseSerializer): class WorkSpaceMemberInviteSerializer(BaseSerializer): - workspace = WorkSpaceSerializer(read_only=True) class Meta: @@ -47,7 +44,6 @@ class WorkSpaceMemberInviteSerializer(BaseSerializer): class TeamSerializer(BaseSerializer): - members_detail = UserLiteSerializer(read_only=True, source="members", many=True) members = serializers.ListField( child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()), @@ -93,3 +89,14 @@ class TeamSerializer(BaseSerializer): return super().update(instance, validated_data) else: return super().update(instance, validated_data) + + +class WorkspaceLiteSerializer(BaseSerializer): + class Meta: + model = Workspace + fields = [ + "name", + "slug", + "id", + ] + read_only_fields = fields diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 116a13033..d0786c8f1 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -42,9 +42,6 @@ from plane.db.models import ( TimelineIssue, IssueProperty, Label, - IssueBlocker, - CycleIssue, - ModuleIssue, IssueLink, ) from plane.bgtasks.issue_activites_task import issue_activity