From 2e8b60009b25728436884a5a262d34c1b3bddce1 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Thu, 7 Dec 2023 17:28:31 +0530 Subject: [PATCH] chore: workspace project roles for the current user --- apiserver/plane/app/urls/project.py | 6 ++++++ apiserver/plane/app/views/__init__.py | 1 + apiserver/plane/app/views/project.py | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apiserver/plane/app/urls/project.py b/apiserver/plane/app/urls/project.py index f1b4200ed..39456a830 100644 --- a/apiserver/plane/app/urls/project.py +++ b/apiserver/plane/app/urls/project.py @@ -13,6 +13,7 @@ from plane.app.views import ( UserProjectInvitationsViewset, ProjectPublicCoverImagesEndpoint, ProjectDeployBoardViewSet, + UserProjectRolesEndpoint, ) @@ -74,6 +75,11 @@ urlpatterns = [ ), name="user-project-invitations", ), + path( + "users/me/workspaces//project-roles/", + UserProjectRolesEndpoint.as_view(), + name="user-project-roles", + ), path( "workspaces//projects//join//", ProjectJoinEndpoint.as_view(), diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index 0b5da33ea..c122dce9f 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -11,6 +11,7 @@ from .project import ( ProjectFavoritesViewSet, ProjectPublicCoverImagesEndpoint, ProjectDeployBoardViewSet, + UserProjectRolesEndpoint, ) from .user import ( UserEndpoint, diff --git a/apiserver/plane/app/views/project.py b/apiserver/plane/app/views/project.py index 5a6a9ddd3..2ed82e7e9 100644 --- a/apiserver/plane/app/views/project.py +++ b/apiserver/plane/app/views/project.py @@ -39,6 +39,7 @@ from plane.app.serializers import ( ) from plane.app.permissions import ( + WorkspaceUserPermission, ProjectBasePermission, ProjectMemberPermission, ) @@ -165,7 +166,7 @@ class ProjectViewSet(WebhookMixin, BaseViewSet): workspace__slug=slug, is_active=True, ).select_related("member"), - to_attr='members_list' + to_attr="members_list", ) ) .order_by("sort_order", "name") @@ -1049,3 +1050,20 @@ class ProjectDeployBoardViewSet(BaseViewSet): serializer = ProjectDeployBoardSerializer(project_deploy_board) return Response(serializer.data, status=status.HTTP_200_OK) + + +class UserProjectRolesEndpoint(BaseAPIView): + permission_classes = [ + WorkspaceUserPermission, + ] + + def get(self, request, slug): + project_members = ProjectMember.objects.filter( + workspace__slug=slug, + member_id=request.user.id, + ).values("project_id", "role") + + project_members = { + str(member["project_id"]): member["role"] for member in project_members + } + return Response(project_members, status=status.HTTP_200_OK)