chore: workspace project roles for the current user

This commit is contained in:
pablohashescobar 2023-12-07 17:28:31 +05:30
parent 0e055666e7
commit 2e8b60009b
3 changed files with 26 additions and 1 deletions

View File

@ -13,6 +13,7 @@ from plane.app.views import (
UserProjectInvitationsViewset, UserProjectInvitationsViewset,
ProjectPublicCoverImagesEndpoint, ProjectPublicCoverImagesEndpoint,
ProjectDeployBoardViewSet, ProjectDeployBoardViewSet,
UserProjectRolesEndpoint,
) )
@ -74,6 +75,11 @@ urlpatterns = [
), ),
name="user-project-invitations", name="user-project-invitations",
), ),
path(
"users/me/workspaces/<str:slug>/project-roles/",
UserProjectRolesEndpoint.as_view(),
name="user-project-roles",
),
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/join/<uuid:pk>/", "workspaces/<str:slug>/projects/<uuid:project_id>/join/<uuid:pk>/",
ProjectJoinEndpoint.as_view(), ProjectJoinEndpoint.as_view(),

View File

@ -11,6 +11,7 @@ from .project import (
ProjectFavoritesViewSet, ProjectFavoritesViewSet,
ProjectPublicCoverImagesEndpoint, ProjectPublicCoverImagesEndpoint,
ProjectDeployBoardViewSet, ProjectDeployBoardViewSet,
UserProjectRolesEndpoint,
) )
from .user import ( from .user import (
UserEndpoint, UserEndpoint,

View File

@ -39,6 +39,7 @@ from plane.app.serializers import (
) )
from plane.app.permissions import ( from plane.app.permissions import (
WorkspaceUserPermission,
ProjectBasePermission, ProjectBasePermission,
ProjectMemberPermission, ProjectMemberPermission,
) )
@ -165,7 +166,7 @@ class ProjectViewSet(WebhookMixin, BaseViewSet):
workspace__slug=slug, workspace__slug=slug,
is_active=True, is_active=True,
).select_related("member"), ).select_related("member"),
to_attr='members_list' to_attr="members_list",
) )
) )
.order_by("sort_order", "name") .order_by("sort_order", "name")
@ -1049,3 +1050,20 @@ class ProjectDeployBoardViewSet(BaseViewSet):
serializer = ProjectDeployBoardSerializer(project_deploy_board) serializer = ProjectDeployBoardSerializer(project_deploy_board)
return Response(serializer.data, status=status.HTTP_200_OK) 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)