mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
cf306ee605
* feat: user display name for the entire system * feat: update issue activity to remove emails * dev: update to display name wherever assignees__email and member__email * dev: update display names on issue activity and the user script * dev: update display_name function to generate display_name from email * dev: add email for test purpose * dev: set default display name for the user * dev: add migration script and default value * dev: annotate with assignees_id * dev: return assignees id * dev: display name for the profile * dev: project members endpoint * dev: url update * dev: trailing / * dev: update workspace member serializer * fix: activity for assignees
132 lines
3.6 KiB
Python
132 lines
3.6 KiB
Python
# Third party imports
|
|
from rest_framework import serializers
|
|
|
|
# Module imports
|
|
from .base import BaseSerializer
|
|
from .user import UserLiteSerializer, UserAdminLiteSerializer
|
|
|
|
from plane.db.models import (
|
|
User,
|
|
Workspace,
|
|
WorkspaceMember,
|
|
Team,
|
|
TeamMember,
|
|
WorkspaceMemberInvite,
|
|
WorkspaceTheme,
|
|
)
|
|
|
|
|
|
class WorkSpaceSerializer(BaseSerializer):
|
|
owner = UserLiteSerializer(read_only=True)
|
|
total_members = serializers.IntegerField(read_only=True)
|
|
total_issues = serializers.IntegerField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Workspace
|
|
fields = "__all__"
|
|
read_only_fields = [
|
|
"id",
|
|
"created_by",
|
|
"updated_by",
|
|
"created_at",
|
|
"updated_at",
|
|
"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)
|
|
|
|
class Meta:
|
|
model = WorkspaceMember
|
|
fields = "__all__"
|
|
|
|
|
|
class WorkspaceMemberAdminSerializer(BaseSerializer):
|
|
member = UserAdminLiteSerializer(read_only=True)
|
|
workspace = WorkspaceLiteSerializer(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")
|
|
|
|
class Meta:
|
|
model = WorkspaceMemberInvite
|
|
fields = "__all__"
|
|
|
|
|
|
class TeamSerializer(BaseSerializer):
|
|
members_detail = UserLiteSerializer(read_only=True, source="members", many=True)
|
|
members = serializers.ListField(
|
|
child=serializers.PrimaryKeyRelatedField(queryset=User.objects.all()),
|
|
write_only=True,
|
|
required=False,
|
|
)
|
|
|
|
class Meta:
|
|
model = Team
|
|
fields = "__all__"
|
|
read_only_fields = [
|
|
"workspace",
|
|
"created_by",
|
|
"updated_by",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
|
|
def create(self, validated_data, **kwargs):
|
|
if "members" in validated_data:
|
|
members = validated_data.pop("members")
|
|
workspace = self.context["workspace"]
|
|
team = Team.objects.create(**validated_data, workspace=workspace)
|
|
team_members = [
|
|
TeamMember(member=member, team=team, workspace=workspace)
|
|
for member in members
|
|
]
|
|
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
|
return team
|
|
else:
|
|
team = Team.objects.create(**validated_data)
|
|
return team
|
|
|
|
def update(self, instance, validated_data):
|
|
if "members" in validated_data:
|
|
members = validated_data.pop("members")
|
|
TeamMember.objects.filter(team=instance).delete()
|
|
team_members = [
|
|
TeamMember(member=member, team=instance, workspace=instance.workspace)
|
|
for member in members
|
|
]
|
|
TeamMember.objects.bulk_create(team_members, batch_size=10)
|
|
return super().update(instance, validated_data)
|
|
else:
|
|
return super().update(instance, validated_data)
|
|
|
|
|
|
class WorkspaceThemeSerializer(BaseSerializer):
|
|
class Meta:
|
|
model = WorkspaceTheme
|
|
fields = "__all__"
|
|
read_only_fields = [
|
|
"workspace",
|
|
"actor",
|
|
]
|