Skip to content

Commit

Permalink
feat: user display name (#1179)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pablohashescobar authored Aug 8, 2023
1 parent 9df0ba6 commit cf306ee
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 157 deletions.
8 changes: 4 additions & 4 deletions apiserver/bin/user_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys
import os, sys, random, string
import uuid

sys.path.append("/code")
Expand All @@ -19,9 +19,9 @@ def populate():
user = User.objects.create(email=default_email, username=uuid.uuid4().hex)
user.set_password(default_password)
user.save()
print("User created")

print("Success")
print(f"User created with an email: {default_email}")
else:
print(f"User already exists with the default email: {default_email}")


if __name__ == "__main__":
Expand Down
8 changes: 2 additions & 6 deletions apiserver/plane/api/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from .base import BaseSerializer
from .people import (
ChangePasswordSerializer,
ResetPasswordSerializer,
TokenSerializer,
)
from .user import UserSerializer, UserLiteSerializer
from .user import UserSerializer, UserLiteSerializer, ChangePasswordSerializer, ResetPasswordSerializer, UserAdminLiteSerializer
from .workspace import (
WorkSpaceSerializer,
WorkSpaceMemberSerializer,
TeamSerializer,
WorkSpaceMemberInviteSerializer,
WorkspaceLiteSerializer,
WorkspaceThemeSerializer,
WorkspaceMemberAdminSerializer,
)
from .project import (
ProjectSerializer,
Expand Down
57 changes: 0 additions & 57 deletions apiserver/plane/api/serializers/people.py

This file was deleted.

13 changes: 12 additions & 1 deletion apiserver/plane/api/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Module imports
from .base import BaseSerializer
from plane.api.serializers.workspace import WorkSpaceSerializer, WorkspaceLiteSerializer
from plane.api.serializers.user import UserLiteSerializer
from plane.api.serializers.user import UserLiteSerializer, UserAdminLiteSerializer
from plane.db.models import (
Project,
ProjectMember,
Expand Down Expand Up @@ -110,6 +110,17 @@ class Meta:
fields = "__all__"


class ProjectMemberAdminSerializer(BaseSerializer):
workspace = WorkspaceLiteSerializer(read_only=True)
project = ProjectLiteSerializer(read_only=True)
member = UserAdminLiteSerializer(read_only=True)


class Meta:
model = ProjectMember
fields = "__all__"


class ProjectMemberInviteSerializer(BaseSerializer):
project = ProjectLiteSerializer(read_only=True)
workspace = WorkspaceLiteSerializer(read_only=True)
Expand Down
44 changes: 43 additions & 1 deletion apiserver/plane/api/serializers/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Third party imports
from rest_framework import serializers

# Module import
from .base import BaseSerializer
from plane.db.models import User
Expand Down Expand Up @@ -37,11 +40,50 @@ class Meta:
"id",
"first_name",
"last_name",
"email",
"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

"""
Serializer for password change endpoint.
"""
old_password = serializers.CharField(required=True)
new_password = serializers.CharField(required=True)


class ResetPasswordSerializer(serializers.Serializer):
model = User

"""
Serializer for password change endpoint.
"""
new_password = serializers.CharField(required=True)
confirm_password = serializers.CharField(required=True)
35 changes: 22 additions & 13 deletions apiserver/plane/api/serializers/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Module imports
from .base import BaseSerializer
from .user import UserLiteSerializer
from .user import UserLiteSerializer, UserAdminLiteSerializer

from plane.db.models import (
User,
Expand Down Expand Up @@ -33,10 +33,30 @@ class Meta:
"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 = WorkSpaceSerializer(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
Expand Down Expand Up @@ -101,17 +121,6 @@ def update(self, instance, validated_data):
return super().update(instance, validated_data)


class WorkspaceLiteSerializer(BaseSerializer):
class Meta:
model = Workspace
fields = [
"name",
"slug",
"id",
]
read_only_fields = fields


class WorkspaceThemeSerializer(BaseSerializer):
class Meta:
model = WorkspaceTheme
Expand Down
12 changes: 12 additions & 0 deletions apiserver/plane/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
InviteWorkspaceEndpoint,
JoinWorkspaceEndpoint,
WorkSpaceMemberViewSet,
WorkspaceMembersEndpoint,
WorkspaceInvitationsViewset,
UserWorkspaceInvitationsEndpoint,
WorkspaceMemberUserEndpoint,
Expand Down Expand Up @@ -59,6 +60,7 @@
ProjectViewSet,
InviteProjectEndpoint,
ProjectMemberViewSet,
ProjectMemberEndpoint,
ProjectMemberInvitationsViewset,
ProjectMemberUserEndpoint,
AddMemberToProjectEndpoint,
Expand Down Expand Up @@ -335,6 +337,11 @@
),
name="workspace",
),
path(
"workspaces/<str:slug>/workspace-members/",
WorkspaceMembersEndpoint.as_view(),
name="workspace-members",
),
path(
"workspaces/<str:slug>/teams/",
TeamMemberViewSet.as_view(
Expand Down Expand Up @@ -468,6 +475,11 @@
),
name="project",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/project-members/",
ProjectMemberEndpoint.as_view(),
name="project",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/members/add/",
AddMemberToProjectEndpoint.as_view(),
Expand Down
4 changes: 3 additions & 1 deletion apiserver/plane/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
ProjectUserViewsEndpoint,
ProjectMemberUserEndpoint,
ProjectFavoritesViewSet,
ProjectMemberEndpoint,
)
from .people import (
from .user import (
UserEndpoint,
UpdateUserOnBoardedEndpoint,
UpdateUserTourCompletedEndpoint,
Expand Down Expand Up @@ -47,6 +48,7 @@
WorkspaceUserProfileEndpoint,
WorkspaceUserProfileIssuesEndpoint,
WorkspaceLabelsEndpoint,
WorkspaceMembersEndpoint,
)
from .state import StateViewSet
from .view import IssueViewViewSet, ViewIssuesEndpoint, IssueViewFavoriteViewSet
Expand Down
10 changes: 5 additions & 5 deletions apiserver/plane/api/views/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def get(self, request, slug):
)

assignee_details = {}
if x_axis in ["assignees__email"] or segment in ["assignees__email"]:
if x_axis in ["assignees__id"] or segment in ["assignees__id"]:
assignee_details = (
Issue.issue_objects.filter(workspace__slug=slug, **filters, assignees__avatar__isnull=False)
.order_by("assignees__id")
.distinct("assignees__id")
.values("assignees__avatar", "assignees__email", "assignees__first_name", "assignees__last_name")
.values("assignees__avatar", "assignees__display_name", "assignees__first_name", "assignees__last_name", "assignees__id")
)


Expand Down Expand Up @@ -243,21 +243,21 @@ def get(self, request, slug):
)
most_issue_created_user = (
queryset.exclude(created_by=None)
.values("created_by__first_name", "created_by__last_name", "created_by__avatar", "created_by__email")
.values("created_by__first_name", "created_by__last_name", "created_by__avatar", "created_by__display_name")
.annotate(count=Count("id"))
.order_by("-count")
)[:5]

most_issue_closed_user = (
queryset.filter(completed_at__isnull=False, assignees__isnull=False)
.values("assignees__first_name", "assignees__last_name", "assignees__avatar", "assignees__email")
.values("assignees__first_name", "assignees__last_name", "assignees__avatar", "assignees__display_name")
.annotate(count=Count("id"))
.order_by("-count")
)[:5]

pending_issue_user = (
queryset.filter(completed_at__isnull=True)
.values("assignees__first_name", "assignees__last_name", "assignees__avatar", "assignees__email")
.values("assignees__first_name", "assignees__last_name", "assignees__avatar", "assignees__display_name")
.annotate(count=Count("id"))
.order_by("-count")
)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/api/views/auth_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

## Module imports
from . import BaseAPIView
from plane.api.serializers.people import (
from plane.api.serializers import (
ChangePasswordSerializer,
ResetPasswordSerializer,
)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/api/views/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def post(self, request, slug, project_id, service):
actor=request.user,
project_id=project_id,
workspace_id=project.workspace_id,
comment=f"{request.user.email} importer the issue from {service}",
comment=f"imported the issue from {service}",
verb="created",
created_by=request.user,
)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/api/views/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def post(self, request, slug, project_id, page_id, page_block_id):
issue=issue,
actor=request.user,
project_id=project_id,
comment=f"{request.user.email} created the issue from {page_block.name} block",
comment=f"created the issue from {page_block.name} block",
verb="created",
)

Expand Down
Loading

0 comments on commit cf306ee

Please sign in to comment.