forked from github/plane
fix: changed the serializers
This commit is contained in:
parent
f7a596c113
commit
77977d7d32
@ -1,13 +1,11 @@
|
||||
from .base import BaseSerializer
|
||||
from .user import UserSerializer, UserLiteSerializer, ChangePasswordSerializer, ResetPasswordSerializer, UserAdminLiteSerializer
|
||||
from .user import UserSerializer, ChangePasswordSerializer, ResetPasswordSerializer
|
||||
from .workspace import (
|
||||
WorkSpaceSerializer,
|
||||
WorkSpaceMemberSerializer,
|
||||
TeamSerializer,
|
||||
WorkSpaceMemberInviteSerializer,
|
||||
WorkspaceLiteSerializer,
|
||||
WorkspaceThemeSerializer,
|
||||
WorkspaceMemberAdminSerializer,
|
||||
)
|
||||
from .project import (
|
||||
ProjectSerializer,
|
||||
|
@ -3,3 +3,22 @@ from rest_framework import serializers
|
||||
|
||||
class BaseSerializer(serializers.ModelSerializer):
|
||||
id = serializers.PrimaryKeyRelatedField(read_only=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Don't pass the 'fields' arg up to the superclass
|
||||
fields = kwargs.pop("fields", None)
|
||||
remove_nested_fields = kwargs.pop("remove_nested_fields", None)
|
||||
|
||||
# Instantiate the superclass normally
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if fields is not None:
|
||||
# Drop any fields that are not specified in the `fields` argument.
|
||||
allowed = set(fields)
|
||||
existing = set(self.fields)
|
||||
for field_name in existing - allowed:
|
||||
self.fields.pop(field_name)
|
||||
if remove_nested_fields:
|
||||
for field_name in remove_nested_fields:
|
||||
for fields in remove_nested_fields[field_name]:
|
||||
self.fields[field_name].fields.pop(fields)
|
||||
|
@ -6,9 +6,9 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from .issue import IssueStateSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from plane.db.models import Cycle, CycleIssue, CycleFavorite
|
||||
|
||||
@ -20,7 +20,10 @@ class CycleWriteSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class CycleSerializer(BaseSerializer):
|
||||
owned_by = UserLiteSerializer(read_only=True)
|
||||
owned_by = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
is_favorite = serializers.BooleanField(read_only=True)
|
||||
total_issues = serializers.IntegerField(read_only=True)
|
||||
cancelled_issues = serializers.IntegerField(read_only=True)
|
||||
@ -33,9 +36,13 @@ class CycleSerializer(BaseSerializer):
|
||||
total_estimates = serializers.IntegerField(read_only=True)
|
||||
completed_estimates = serializers.IntegerField(read_only=True)
|
||||
started_estimates = serializers.IntegerField(read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
|
||||
|
||||
def get_assignees(self, obj):
|
||||
members = [
|
||||
{
|
||||
@ -54,7 +61,7 @@ class CycleSerializer(BaseSerializer):
|
||||
unique_list = [dict(item) for item in unique_objects]
|
||||
|
||||
return unique_list
|
||||
|
||||
|
||||
def get_labels(self, obj):
|
||||
labels = [
|
||||
{
|
||||
|
@ -2,11 +2,15 @@
|
||||
from .base import BaseSerializer
|
||||
|
||||
from plane.db.models import Estimate, EstimatePoint
|
||||
from plane.api.serializers import WorkspaceLiteSerializer, ProjectLiteSerializer
|
||||
from plane.api.serializers import WorkSpaceSerializer, ProjectLiteSerializer
|
||||
|
||||
|
||||
class EstimateSerializer(BaseSerializer):
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
|
||||
class Meta:
|
||||
@ -31,7 +35,11 @@ class EstimatePointSerializer(BaseSerializer):
|
||||
|
||||
class EstimateReadSerializer(BaseSerializer):
|
||||
points = EstimatePointSerializer(read_only=True, many=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
|
||||
class Meta:
|
||||
|
@ -1,11 +1,15 @@
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from plane.db.models import ExporterHistory
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
|
||||
|
||||
class ExporterHistorySerializer(BaseSerializer):
|
||||
initiated_by_detail = UserLiteSerializer(source="initiated_by", read_only=True)
|
||||
initiated_by_detail = UserSerializer(
|
||||
source="initiated_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ExporterHistory
|
||||
|
@ -1,15 +1,19 @@
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from plane.db.models import Importer
|
||||
|
||||
|
||||
class ImporterSerializer(BaseSerializer):
|
||||
initiated_by_detail = UserLiteSerializer(source="initiated_by", read_only=True)
|
||||
initiated_by_detail = UserSerializer(
|
||||
source="initiated_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(source="workspace", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Importer
|
||||
|
@ -7,7 +7,7 @@ from .issue import IssueFlatSerializer, LabelLiteSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from .state import StateLiteSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from plane.db.models import Inbox, InboxIssue, Issue
|
||||
|
||||
|
||||
@ -48,7 +48,12 @@ class IssueStateInboxSerializer(BaseSerializer):
|
||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||
assignee_details = UserSerializer(
|
||||
source="assignees",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||
bridge_id = serializers.UUIDField(read_only=True)
|
||||
issue_inbox = InboxIssueLiteSerializer(read_only=True, many=True)
|
||||
|
@ -6,11 +6,10 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from .state import StateSerializer, StateLiteSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .project import ProjectSerializer, ProjectLiteSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from plane.db.models import (
|
||||
User,
|
||||
Issue,
|
||||
@ -71,9 +70,17 @@ class IssueProjectLiteSerializer(BaseSerializer):
|
||||
## Find a better approach to save manytomany?
|
||||
class IssueCreateSerializer(BaseSerializer):
|
||||
state_detail = StateSerializer(read_only=True, source="state")
|
||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||
created_by_detail = UserSerializer(
|
||||
source="created_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
assignees_list = serializers.ListField(
|
||||
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
||||
@ -113,7 +120,11 @@ class IssueCreateSerializer(BaseSerializer):
|
||||
]
|
||||
|
||||
def validate(self, data):
|
||||
if data.get("start_date", None) is not None and data.get("target_date", None) is not None and data.get("start_date", None) > data.get("target_date", None):
|
||||
if (
|
||||
data.get("start_date", None) is not None
|
||||
and data.get("target_date", None) is not None
|
||||
and data.get("start_date", None) > data.get("target_date", None)
|
||||
):
|
||||
raise serializers.ValidationError("Start date cannot exceed target date")
|
||||
return data
|
||||
|
||||
@ -296,7 +307,11 @@ class IssueCreateSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueActivitySerializer(BaseSerializer):
|
||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||
actor_detail = UserSerializer(
|
||||
source="actor",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
|
||||
@ -306,10 +321,18 @@ class IssueActivitySerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueCommentSerializer(BaseSerializer):
|
||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||
actor_detail = UserSerializer(
|
||||
source="actor",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IssueComment
|
||||
@ -337,7 +360,9 @@ class IssuePropertySerializer(BaseSerializer):
|
||||
|
||||
|
||||
class LabelSerializer(BaseSerializer):
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace", fields=("id", "name", "slug"), read_only=True
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||
|
||||
class Meta:
|
||||
@ -400,7 +425,11 @@ class BlockerIssueSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueAssigneeSerializer(BaseSerializer):
|
||||
assignee_details = UserLiteSerializer(read_only=True, source="assignee")
|
||||
assignee_details = UserSerializer(
|
||||
source="assignee",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IssueAssignee
|
||||
@ -468,7 +497,11 @@ class IssueModuleDetailSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueLinkSerializer(BaseSerializer):
|
||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||
created_by_detail = UserSerializer(
|
||||
source="created_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IssueLink
|
||||
@ -522,7 +555,11 @@ class IssueReactionSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueReactionLiteSerializer(BaseSerializer):
|
||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||
actor_detail = UserSerializer(
|
||||
source="actor",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IssueReaction
|
||||
@ -535,7 +572,11 @@ class IssueReactionLiteSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class CommentReactionLiteSerializer(BaseSerializer):
|
||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||
actor_detail = UserSerializer(
|
||||
source="actor",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = CommentReaction
|
||||
@ -554,9 +595,7 @@ class CommentReactionSerializer(BaseSerializer):
|
||||
read_only_fields = ["workspace", "project", "comment", "actor"]
|
||||
|
||||
|
||||
|
||||
class IssueVoteSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = IssueVote
|
||||
fields = ["issue", "vote", "workspace_id", "project_id", "actor"]
|
||||
@ -564,12 +603,20 @@ class IssueVoteSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueCommentSerializer(BaseSerializer):
|
||||
actor_detail = UserLiteSerializer(read_only=True, source="actor")
|
||||
actor_detail = UserSerializer(
|
||||
source="actor",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
issue_detail = IssueFlatSerializer(read_only=True, source="issue")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
comment_reactions = CommentReactionLiteSerializer(read_only=True, many=True)
|
||||
|
||||
workspace_details = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
comment_reactions = CommentReactionLiteSerializer(read_only=True, many=True)
|
||||
|
||||
class Meta:
|
||||
model = IssueComment
|
||||
@ -606,7 +653,12 @@ class IssueStateSerializer(BaseSerializer):
|
||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||
assignee_details = UserSerializer(
|
||||
source="assignees",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||
bridge_id = serializers.UUIDField(read_only=True)
|
||||
attachment_count = serializers.IntegerField(read_only=True)
|
||||
@ -622,7 +674,12 @@ class IssueSerializer(BaseSerializer):
|
||||
state_detail = StateSerializer(read_only=True, source="state")
|
||||
parent_detail = IssueStateFlatSerializer(read_only=True, source="parent")
|
||||
label_details = LabelSerializer(read_only=True, source="labels", many=True)
|
||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||
assignee_details = UserSerializer(
|
||||
source="assignees",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
# List of issues blocked by this issue
|
||||
blocked_issues = BlockedIssueSerializer(read_only=True, many=True)
|
||||
# List of issues that block this issue
|
||||
@ -648,11 +705,20 @@ class IssueSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class IssueLiteSerializer(BaseSerializer):
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
state_detail = StateLiteSerializer(read_only=True, source="state")
|
||||
label_details = LabelLiteSerializer(read_only=True, source="labels", many=True)
|
||||
assignee_details = UserLiteSerializer(read_only=True, source="assignees", many=True)
|
||||
assignee_details = UserSerializer(
|
||||
source="assignees",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
sub_issues_count = serializers.IntegerField(read_only=True)
|
||||
cycle_id = serializers.UUIDField(read_only=True)
|
||||
module_id = serializers.UUIDField(read_only=True)
|
||||
|
@ -3,9 +3,9 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from .project import ProjectSerializer, ProjectLiteSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from .issue import IssueStateSerializer
|
||||
|
||||
from plane.db.models import (
|
||||
@ -26,7 +26,11 @@ class ModuleWriteSerializer(BaseSerializer):
|
||||
)
|
||||
|
||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Module
|
||||
@ -124,7 +128,11 @@ class ModuleIssueSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class ModuleLinkSerializer(BaseSerializer):
|
||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||
created_by_detail = UserSerializer(
|
||||
source="created_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ModuleLink
|
||||
@ -152,8 +160,17 @@ class ModuleLinkSerializer(BaseSerializer):
|
||||
|
||||
class ModuleSerializer(BaseSerializer):
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
lead_detail = UserLiteSerializer(read_only=True, source="lead")
|
||||
members_detail = UserLiteSerializer(read_only=True, many=True, source="members")
|
||||
lead_detail = UserSerializer(
|
||||
source="lead",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
members_detail = UserSerializer(
|
||||
source="members",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
link_module = ModuleLinkSerializer(read_only=True, many=True)
|
||||
is_favorite = serializers.BooleanField(read_only=True)
|
||||
total_issues = serializers.IntegerField(read_only=True)
|
||||
|
@ -1,12 +1,16 @@
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer
|
||||
from .user import UserSerializer
|
||||
from plane.db.models import Notification
|
||||
|
||||
|
||||
class NotificationSerializer(BaseSerializer):
|
||||
triggered_by_details = UserLiteSerializer(read_only=True, source="triggered_by")
|
||||
triggered_by_details = UserSerializer(
|
||||
source="triggered_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Notification
|
||||
fields = "__all__"
|
||||
|
||||
|
@ -4,7 +4,7 @@ from rest_framework import serializers
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .issue import IssueFlatSerializer, LabelLiteSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from plane.db.models import Page, PageBlock, PageFavorite, PageLabel, Label
|
||||
|
||||
@ -12,7 +12,11 @@ from plane.db.models import Page, PageBlock, PageFavorite, PageLabel, Label
|
||||
class PageBlockSerializer(BaseSerializer):
|
||||
issue_detail = IssueFlatSerializer(source="issue", read_only=True)
|
||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = PageBlock
|
||||
@ -40,7 +44,11 @@ class PageSerializer(BaseSerializer):
|
||||
)
|
||||
blocks = PageBlockLiteSerializer(read_only=True, many=True)
|
||||
project_detail = ProjectLiteSerializer(source="project", read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Page
|
||||
|
@ -6,8 +6,8 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from plane.api.serializers.workspace import WorkSpaceSerializer, WorkspaceLiteSerializer
|
||||
from plane.api.serializers.user import UserLiteSerializer, UserAdminLiteSerializer
|
||||
from plane.api.serializers.workspace import WorkSpaceSerializer
|
||||
from plane.api.serializers.user import UserSerializer
|
||||
from plane.db.models import (
|
||||
Project,
|
||||
ProjectMember,
|
||||
@ -19,7 +19,11 @@ from plane.db.models import (
|
||||
|
||||
|
||||
class ProjectSerializer(BaseSerializer):
|
||||
workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Project
|
||||
@ -94,8 +98,14 @@ class ProjectLiteSerializer(BaseSerializer):
|
||||
|
||||
class ProjectDetailSerializer(BaseSerializer):
|
||||
workspace = WorkSpaceSerializer(read_only=True)
|
||||
default_assignee = UserLiteSerializer(read_only=True)
|
||||
project_lead = UserLiteSerializer(read_only=True)
|
||||
default_assignee = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
project_lead = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
is_favorite = serializers.BooleanField(read_only=True)
|
||||
total_members = serializers.IntegerField(read_only=True)
|
||||
total_cycles = serializers.IntegerField(read_only=True)
|
||||
@ -112,7 +122,10 @@ class ProjectDetailSerializer(BaseSerializer):
|
||||
class ProjectMemberSerializer(BaseSerializer):
|
||||
workspace = WorkSpaceSerializer(read_only=True)
|
||||
project = ProjectLiteSerializer(read_only=True)
|
||||
member = UserLiteSerializer(read_only=True)
|
||||
member = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ProjectMember
|
||||
@ -120,9 +133,24 @@ class ProjectMemberSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class ProjectMemberAdminSerializer(BaseSerializer):
|
||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||
workspace = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project = ProjectLiteSerializer(read_only=True)
|
||||
member = UserAdminLiteSerializer(read_only=True)
|
||||
member = UserSerializer(
|
||||
fields=(
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"avatar",
|
||||
"is_bot",
|
||||
"display_name",
|
||||
"email",
|
||||
),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ProjectMember
|
||||
@ -131,7 +159,10 @@ class ProjectMemberAdminSerializer(BaseSerializer):
|
||||
|
||||
class ProjectMemberInviteSerializer(BaseSerializer):
|
||||
project = ProjectLiteSerializer(read_only=True)
|
||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||
workspace = WorkSpaceSerializer(
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ProjectMemberInvite
|
||||
@ -157,7 +188,10 @@ class ProjectFavoriteSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class ProjectMemberLiteSerializer(BaseSerializer):
|
||||
member = UserLiteSerializer(read_only=True)
|
||||
member = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
is_subscribed = serializers.BooleanField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
@ -168,7 +202,11 @@ class ProjectMemberLiteSerializer(BaseSerializer):
|
||||
|
||||
class ProjectDeployBoardSerializer(BaseSerializer):
|
||||
project_details = ProjectLiteSerializer(read_only=True, source="project")
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ProjectDeployBoard
|
||||
|
@ -1,13 +1,17 @@
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
|
||||
from plane.db.models import State
|
||||
|
||||
|
||||
class StateSerializer(BaseSerializer):
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
|
||||
class Meta:
|
||||
|
@ -33,42 +33,6 @@ class UserSerializer(BaseSerializer):
|
||||
return bool(obj.first_name) or bool(obj.last_name)
|
||||
|
||||
|
||||
class UserLiteSerializer(BaseSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"avatar",
|
||||
"is_bot",
|
||||
"display_name",
|
||||
]
|
||||
read_only_fields = [
|
||||
"id",
|
||||
"is_bot",
|
||||
]
|
||||
|
||||
|
||||
class UserAdminLiteSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"avatar",
|
||||
"is_bot",
|
||||
"display_name",
|
||||
"email",
|
||||
]
|
||||
read_only_fields = [
|
||||
"id",
|
||||
"is_bot",
|
||||
]
|
||||
|
||||
|
||||
class ChangePasswordSerializer(serializers.Serializer):
|
||||
model = User
|
||||
|
||||
|
@ -3,7 +3,7 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .workspace import WorkspaceLiteSerializer
|
||||
from .workspace import WorkSpaceSerializer
|
||||
from .project import ProjectLiteSerializer
|
||||
from plane.db.models import IssueView, IssueViewFavorite
|
||||
from plane.utils.issue_filters import issue_filters
|
||||
@ -12,7 +12,11 @@ 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)
|
||||
workspace_detail = WorkSpaceSerializer(
|
||||
source="workspace",
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IssueView
|
||||
|
@ -3,7 +3,7 @@ from rest_framework import serializers
|
||||
|
||||
# Module imports
|
||||
from .base import BaseSerializer
|
||||
from .user import UserLiteSerializer, UserAdminLiteSerializer
|
||||
from .user import UserSerializer
|
||||
|
||||
from plane.db.models import (
|
||||
User,
|
||||
@ -17,7 +17,10 @@ from plane.db.models import (
|
||||
|
||||
|
||||
class WorkSpaceSerializer(BaseSerializer):
|
||||
owner = UserLiteSerializer(read_only=True)
|
||||
owner = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
total_members = serializers.IntegerField(read_only=True)
|
||||
total_issues = serializers.IntegerField(read_only=True)
|
||||
|
||||
@ -33,40 +36,55 @@ class WorkSpaceSerializer(BaseSerializer):
|
||||
"owner",
|
||||
]
|
||||
|
||||
class WorkspaceLiteSerializer(BaseSerializer):
|
||||
class Meta:
|
||||
model = Workspace
|
||||
fields = [
|
||||
"name",
|
||||
"slug",
|
||||
"id",
|
||||
]
|
||||
read_only_fields = fields
|
||||
|
||||
|
||||
|
||||
class WorkSpaceMemberSerializer(BaseSerializer):
|
||||
member = UserLiteSerializer(read_only=True)
|
||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||
member = UserSerializer(
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name" ,"email"),
|
||||
read_only=True,
|
||||
)
|
||||
workspace = WorkSpaceSerializer(
|
||||
fields=("id", "name", "slug"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = WorkspaceMember
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class WorkspaceMemberAdminSerializer(BaseSerializer):
|
||||
member = UserAdminLiteSerializer(read_only=True)
|
||||
workspace = WorkspaceLiteSerializer(read_only=True)
|
||||
# class WorkspaceMemberAdminSerializer(BaseSerializer):
|
||||
# member = UserSerializer(
|
||||
# fields=(
|
||||
# "id",
|
||||
# "first_name",
|
||||
# "last_name",
|
||||
# "avatar",
|
||||
# "is_bot",
|
||||
# "display_name",
|
||||
# "email",
|
||||
# ),
|
||||
# read_only=True,
|
||||
# )
|
||||
|
||||
class Meta:
|
||||
model = WorkspaceMember
|
||||
fields = "__all__"
|
||||
# workspace = WorkSpaceSerializer(
|
||||
# fields=("id", "name", "slug"),
|
||||
# read_only=True,
|
||||
# )
|
||||
|
||||
# class Meta:
|
||||
# model = WorkspaceMember
|
||||
# fields = "__all__"
|
||||
|
||||
|
||||
class WorkSpaceMemberInviteSerializer(BaseSerializer):
|
||||
workspace = WorkSpaceSerializer(read_only=True)
|
||||
total_members = serializers.IntegerField(read_only=True)
|
||||
created_by_detail = UserLiteSerializer(read_only=True, source="created_by")
|
||||
created_by_detail = UserSerializer(
|
||||
source="created_by",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = WorkspaceMemberInvite
|
||||
@ -74,7 +92,12 @@ class WorkSpaceMemberInviteSerializer(BaseSerializer):
|
||||
|
||||
|
||||
class TeamSerializer(BaseSerializer):
|
||||
members_detail = UserLiteSerializer(read_only=True, source="members", many=True)
|
||||
members_detail = UserSerializer(
|
||||
source="members",
|
||||
fields=("id", "first_name", "last_name", "avatar", "is_bot", "display_name"),
|
||||
read_only=True,
|
||||
many=True,
|
||||
)
|
||||
members = serializers.ListField(
|
||||
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
||||
write_only=True,
|
||||
|
@ -14,7 +14,7 @@ from django.conf import settings
|
||||
from .base import BaseAPIView
|
||||
from plane.api.permissions import ProjectEntityPermission
|
||||
from plane.db.models import Workspace, Project
|
||||
from plane.api.serializers import ProjectLiteSerializer, WorkspaceLiteSerializer
|
||||
from plane.api.serializers import ProjectLiteSerializer, WorkSpaceSerializer
|
||||
|
||||
|
||||
class GPTIntegrationEndpoint(BaseAPIView):
|
||||
@ -58,7 +58,10 @@ class GPTIntegrationEndpoint(BaseAPIView):
|
||||
"response": text,
|
||||
"response_html": text_html,
|
||||
"project_detail": ProjectLiteSerializer(project).data,
|
||||
"workspace_detail": WorkspaceLiteSerializer(workspace).data,
|
||||
"workspace_detail": WorkSpaceSerializer(
|
||||
workspace,
|
||||
fields=("id", "name", "slug"),
|
||||
).data,
|
||||
},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
|
@ -42,12 +42,11 @@ from plane.api.serializers import (
|
||||
WorkSpaceMemberSerializer,
|
||||
TeamSerializer,
|
||||
WorkSpaceMemberInviteSerializer,
|
||||
UserLiteSerializer,
|
||||
UserSerializer,
|
||||
ProjectMemberSerializer,
|
||||
WorkspaceThemeSerializer,
|
||||
IssueActivitySerializer,
|
||||
IssueLiteSerializer,
|
||||
WorkspaceMemberAdminSerializer
|
||||
)
|
||||
from plane.api.views.base import BaseAPIView
|
||||
from . import BaseViewSet
|
||||
@ -538,7 +537,7 @@ class UserWorkspaceInvitationsEndpoint(BaseViewSet):
|
||||
|
||||
|
||||
class WorkSpaceMemberViewSet(BaseViewSet):
|
||||
serializer_class = WorkspaceMemberAdminSerializer
|
||||
# serializer_class = WorkSpaceMemberSerializer
|
||||
model = WorkspaceMember
|
||||
|
||||
permission_classes = [
|
||||
@ -719,7 +718,7 @@ class TeamMemberViewSet(BaseViewSet):
|
||||
users = list(set(request.data.get("members", [])).difference(members))
|
||||
users = User.objects.filter(pk__in=users)
|
||||
|
||||
serializer = UserLiteSerializer(users, many=True)
|
||||
serializer = UserSerializer(users, fields=('id', 'first_name',"last_name","avatar","is_bot","display_name"),many=True)
|
||||
return Response(
|
||||
{
|
||||
"error": f"{len(users)} of the member(s) are not a part of the workspace",
|
||||
@ -786,6 +785,7 @@ class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
|
||||
|
||||
workspace = Workspace.objects.get(pk=last_workspace_id)
|
||||
workspace_serializer = WorkSpaceSerializer(workspace)
|
||||
# workspace_serializer = WorkSpaceSerializer(workspace, fields=("member": (fields: "displayname")))
|
||||
|
||||
project_member = ProjectMember.objects.filter(
|
||||
workspace_id=last_workspace_id, member=request.user
|
||||
@ -819,7 +819,7 @@ class WorkspaceMemberUserEndpoint(BaseAPIView):
|
||||
workspace_member = WorkspaceMember.objects.get(
|
||||
member=request.user, workspace__slug=slug
|
||||
)
|
||||
serializer = WorkSpaceMemberSerializer(workspace_member)
|
||||
serializer = WorkSpaceMemberSerializer(workspace_member, fields=("member","workspace"), remove_nested_fields={"member": ("email",)})
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
except (Workspace.DoesNotExist, WorkspaceMember.DoesNotExist):
|
||||
return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
|
||||
|
Loading…
Reference in New Issue
Block a user