forked from github/plane
fix: workspace member listing endpoint (#348)
This commit is contained in:
parent
f5e96b8078
commit
cee8a6a8cd
@ -43,7 +43,6 @@ from plane.bgtasks.workspace_invitation_task import workspace_invitation
|
|||||||
|
|
||||||
|
|
||||||
class WorkSpaceViewSet(BaseViewSet):
|
class WorkSpaceViewSet(BaseViewSet):
|
||||||
|
|
||||||
model = Workspace
|
model = Workspace
|
||||||
serializer_class = WorkSpaceSerializer
|
serializer_class = WorkSpaceSerializer
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
@ -101,7 +100,6 @@ class WorkSpaceViewSet(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class UserWorkSpacesEndpoint(BaseAPIView):
|
class UserWorkSpacesEndpoint(BaseAPIView):
|
||||||
|
|
||||||
search_fields = [
|
search_fields = [
|
||||||
"name",
|
"name",
|
||||||
]
|
]
|
||||||
@ -111,7 +109,6 @@ 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"))
|
||||||
.order_by()
|
.order_by()
|
||||||
@ -163,14 +160,12 @@ class WorkSpaceAvailabilityCheckEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
|
|
||||||
class InviteWorkspaceEndpoint(BaseAPIView):
|
class InviteWorkspaceEndpoint(BaseAPIView):
|
||||||
|
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
WorkSpaceAdminPermission,
|
WorkSpaceAdminPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
def post(self, request, slug):
|
def post(self, request, slug):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
emails = request.data.get("emails", False)
|
emails = request.data.get("emails", False)
|
||||||
# Check if email is provided
|
# Check if email is provided
|
||||||
if not emails or not len(emails):
|
if not emails or not len(emails):
|
||||||
@ -267,7 +262,6 @@ class JoinWorkspaceEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
def post(self, request, slug, pk):
|
def post(self, request, slug, pk):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
workspace_invite = WorkspaceMemberInvite.objects.get(
|
workspace_invite = WorkspaceMemberInvite.objects.get(
|
||||||
pk=pk, workspace__slug=slug
|
pk=pk, workspace__slug=slug
|
||||||
)
|
)
|
||||||
@ -286,7 +280,6 @@ class JoinWorkspaceEndpoint(BaseAPIView):
|
|||||||
workspace_invite.save()
|
workspace_invite.save()
|
||||||
|
|
||||||
if workspace_invite.accepted:
|
if workspace_invite.accepted:
|
||||||
|
|
||||||
# Check if the user created account after invitation
|
# Check if the user created account after invitation
|
||||||
user = User.objects.filter(email=email).first()
|
user = User.objects.filter(email=email).first()
|
||||||
|
|
||||||
@ -334,7 +327,6 @@ class JoinWorkspaceEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
|
|
||||||
class WorkspaceInvitationsViewset(BaseViewSet):
|
class WorkspaceInvitationsViewset(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = WorkSpaceMemberInviteSerializer
|
serializer_class = WorkSpaceMemberInviteSerializer
|
||||||
model = WorkspaceMemberInvite
|
model = WorkspaceMemberInvite
|
||||||
|
|
||||||
@ -352,7 +344,6 @@ class WorkspaceInvitationsViewset(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class UserWorkspaceInvitationsEndpoint(BaseViewSet):
|
class UserWorkspaceInvitationsEndpoint(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = WorkSpaceMemberInviteSerializer
|
serializer_class = WorkSpaceMemberInviteSerializer
|
||||||
model = WorkspaceMemberInvite
|
model = WorkspaceMemberInvite
|
||||||
|
|
||||||
@ -366,7 +357,6 @@ class UserWorkspaceInvitationsEndpoint(BaseViewSet):
|
|||||||
|
|
||||||
def create(self, request):
|
def create(self, request):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
invitations = request.data.get("invitations")
|
invitations = request.data.get("invitations")
|
||||||
workspace_invitations = WorkspaceMemberInvite.objects.filter(
|
workspace_invitations = WorkspaceMemberInvite.objects.filter(
|
||||||
pk__in=invitations
|
pk__in=invitations
|
||||||
@ -397,7 +387,6 @@ class UserWorkspaceInvitationsEndpoint(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class WorkSpaceMemberViewSet(BaseViewSet):
|
class WorkSpaceMemberViewSet(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = WorkSpaceMemberSerializer
|
serializer_class = WorkSpaceMemberSerializer
|
||||||
model = WorkspaceMember
|
model = WorkspaceMember
|
||||||
|
|
||||||
@ -414,14 +403,13 @@ class WorkSpaceMemberViewSet(BaseViewSet):
|
|||||||
return self.filter_queryset(
|
return self.filter_queryset(
|
||||||
super()
|
super()
|
||||||
.get_queryset()
|
.get_queryset()
|
||||||
.filter(workspace__slug=self.kwargs.get("slug"), is_bot=False)
|
.filter(workspace__slug=self.kwargs.get("slug"), member__is_bot=False)
|
||||||
.select_related("workspace", "workspace__owner")
|
.select_related("workspace", "workspace__owner")
|
||||||
.select_related("member")
|
.select_related("member")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TeamMemberViewSet(BaseViewSet):
|
class TeamMemberViewSet(BaseViewSet):
|
||||||
|
|
||||||
serializer_class = TeamSerializer
|
serializer_class = TeamSerializer
|
||||||
model = Team
|
model = Team
|
||||||
permission_classes = [
|
permission_classes = [
|
||||||
@ -443,9 +431,7 @@ class TeamMemberViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def create(self, request, slug):
|
def create(self, request, slug):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
members = list(
|
members = list(
|
||||||
WorkspaceMember.objects.filter(
|
WorkspaceMember.objects.filter(
|
||||||
workspace__slug=slug, member__id__in=request.data.get("members", [])
|
workspace__slug=slug, member__id__in=request.data.get("members", [])
|
||||||
@ -456,7 +442,6 @@ class TeamMemberViewSet(BaseViewSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if len(members) != len(request.data.get("members", [])):
|
if len(members) != len(request.data.get("members", [])):
|
||||||
|
|
||||||
users = list(set(request.data.get("members", [])).difference(members))
|
users = list(set(request.data.get("members", [])).difference(members))
|
||||||
users = User.objects.filter(pk__in=users)
|
users = User.objects.filter(pk__in=users)
|
||||||
|
|
||||||
@ -493,7 +478,6 @@ class TeamMemberViewSet(BaseViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class UserWorkspaceInvitationEndpoint(BaseViewSet):
|
class UserWorkspaceInvitationEndpoint(BaseViewSet):
|
||||||
|
|
||||||
model = WorkspaceMemberInvite
|
model = WorkspaceMemberInvite
|
||||||
serializer_class = WorkSpaceMemberInviteSerializer
|
serializer_class = WorkSpaceMemberInviteSerializer
|
||||||
|
|
||||||
@ -513,7 +497,6 @@ class UserWorkspaceInvitationEndpoint(BaseViewSet):
|
|||||||
class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
|
class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
user = User.objects.get(pk=request.user.id)
|
user = User.objects.get(pk=request.user.id)
|
||||||
|
|
||||||
last_workspace_id = user.last_workspace_id
|
last_workspace_id = user.last_workspace_id
|
||||||
@ -577,7 +560,6 @@ class WorkspaceMemberUserEndpoint(BaseAPIView):
|
|||||||
class WorkspaceMemberUserViewsEndpoint(BaseAPIView):
|
class WorkspaceMemberUserViewsEndpoint(BaseAPIView):
|
||||||
def post(self, request, slug):
|
def post(self, request, slug):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
workspace_member = WorkspaceMember.objects.get(
|
workspace_member = WorkspaceMember.objects.get(
|
||||||
workspace__slug=slug, member=request.user
|
workspace__slug=slug, member=request.user
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user