mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: members list filtering for workspace and projects (#1872)
This commit is contained in:
parent
08382f88b4
commit
55e2f00ffe
@ -122,7 +122,9 @@ class ProjectViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.annotate(
|
.annotate(
|
||||||
total_members=ProjectMember.objects.filter(project_id=OuterRef("id"))
|
total_members=ProjectMember.objects.filter(
|
||||||
|
project_id=OuterRef("id"), member__is_bot=False
|
||||||
|
)
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
.values("count")
|
.values("count")
|
||||||
@ -393,7 +395,9 @@ class InviteProjectEndpoint(BaseAPIView):
|
|||||||
validate_email(email)
|
validate_email(email)
|
||||||
# Check if user is already a member of workspace
|
# Check if user is already a member of workspace
|
||||||
if ProjectMember.objects.filter(
|
if ProjectMember.objects.filter(
|
||||||
project_id=project_id, member__email=email
|
project_id=project_id,
|
||||||
|
member__email=email,
|
||||||
|
member__is_bot=False,
|
||||||
).exists():
|
).exists():
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "User is already member of workspace"},
|
{"error": "User is already member of workspace"},
|
||||||
@ -1097,7 +1101,9 @@ class ProjectMemberEndpoint(BaseAPIView):
|
|||||||
def get(self, request, slug, project_id):
|
def get(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
project_members = ProjectMember.objects.filter(
|
project_members = ProjectMember.objects.filter(
|
||||||
project_id=project_id, workspace__slug=slug
|
project_id=project_id,
|
||||||
|
workspace__slug=slug,
|
||||||
|
member__is_bot=False,
|
||||||
).select_related("project", "member")
|
).select_related("project", "member")
|
||||||
serializer = ProjectMemberSerializer(project_members, many=True)
|
serializer = ProjectMemberSerializer(project_members, many=True)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
@ -47,7 +47,7 @@ from plane.api.serializers import (
|
|||||||
WorkspaceThemeSerializer,
|
WorkspaceThemeSerializer,
|
||||||
IssueActivitySerializer,
|
IssueActivitySerializer,
|
||||||
IssueLiteSerializer,
|
IssueLiteSerializer,
|
||||||
WorkspaceMemberAdminSerializer
|
WorkspaceMemberAdminSerializer,
|
||||||
)
|
)
|
||||||
from plane.api.views.base import BaseAPIView
|
from plane.api.views.base import BaseAPIView
|
||||||
from . import BaseViewSet
|
from . import BaseViewSet
|
||||||
@ -107,7 +107,9 @@ class WorkSpaceViewSet(BaseViewSet):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
member_count = (
|
member_count = (
|
||||||
WorkspaceMember.objects.filter(workspace=OuterRef("id"))
|
WorkspaceMember.objects.filter(
|
||||||
|
workspace=OuterRef("id"), member__is_bot=False
|
||||||
|
)
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
.values("count")
|
.values("count")
|
||||||
@ -192,7 +194,9 @@ class UserWorkSpacesEndpoint(BaseAPIView):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
try:
|
try:
|
||||||
member_count = (
|
member_count = (
|
||||||
WorkspaceMember.objects.filter(workspace=OuterRef("id"))
|
WorkspaceMember.objects.filter(
|
||||||
|
workspace=OuterRef("id"), member__is_bot=False
|
||||||
|
)
|
||||||
.order_by()
|
.order_by()
|
||||||
.annotate(count=Func(F("id"), function="Count"))
|
.annotate(count=Func(F("id"), function="Count"))
|
||||||
.values("count")
|
.values("count")
|
||||||
@ -625,7 +629,9 @@ class WorkSpaceMemberViewSet(BaseViewSet):
|
|||||||
if (
|
if (
|
||||||
workspace_member.role == 20
|
workspace_member.role == 20
|
||||||
and WorkspaceMember.objects.filter(
|
and WorkspaceMember.objects.filter(
|
||||||
workspace__slug=slug, role=20
|
workspace__slug=slug,
|
||||||
|
role=20,
|
||||||
|
member__is_bot=False,
|
||||||
).count()
|
).count()
|
||||||
== 1
|
== 1
|
||||||
):
|
):
|
||||||
@ -1455,7 +1461,8 @@ class WorkspaceMembersEndpoint(BaseAPIView):
|
|||||||
def get(self, request, slug):
|
def get(self, request, slug):
|
||||||
try:
|
try:
|
||||||
workspace_members = WorkspaceMember.objects.filter(
|
workspace_members = WorkspaceMember.objects.filter(
|
||||||
workspace__slug=slug
|
workspace__slug=slug,
|
||||||
|
member__is_bot=False,
|
||||||
).select_related("workspace", "member")
|
).select_related("workspace", "member")
|
||||||
serialzier = WorkSpaceMemberSerializer(workspace_members, many=True)
|
serialzier = WorkSpaceMemberSerializer(workspace_members, many=True)
|
||||||
return Response(serialzier.data, status=status.HTTP_200_OK)
|
return Response(serialzier.data, status=status.HTTP_200_OK)
|
||||||
|
Loading…
Reference in New Issue
Block a user