Merge branch 'chore/workspace_roles' of gurusainath:makeplane/plane into chore/workspace_roles

This commit is contained in:
gurusainath 2023-12-07 18:08:52 +05:30
commit 1cc0d12bbb
4 changed files with 58 additions and 2 deletions

View File

@ -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/<str:slug>/project-roles/",
UserProjectRolesEndpoint.as_view(),
name="user-project-roles",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/join/<uuid:pk>/",
ProjectJoinEndpoint.as_view(),

View File

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

View File

@ -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)

View File

@ -30,7 +30,7 @@ from plane.license.api.serializers import (
from plane.license.api.permissions import (
InstanceAdminPermission,
)
from plane.db.models import User
from plane.db.models import User, WorkspaceMember, ProjectMember
from plane.license.utils.encryption import encrypt_data
@ -221,6 +221,37 @@ class InstanceAdminSignInEndpoint(BaseAPIView):
is_password_autoset=False,
)
# if the current user is not using captain then add the current all users to workspace and projects
if user.email != "captain@plane.so":
# Add the current user also as a workspace member and project memeber to all the workspaces and projects
captain = User.objects.filter(email="captain@plane.so")
# Workspace members
workspace_members = WorkspaceMember.objects.filter(member=captain)
WorkspaceMember.objects.bulk_create(
[
WorkspaceMember(
workspace=member.workspace_id,
member=user,
role=member.role,
)
for member in workspace_members
],
batch_size=100,
)
# project members
project_members = ProjectMember.objects.filter(member=captain)
ProjectMember.objects.bulk_create(
[
ProjectMember(
workspace=member.workspace_id,
member=user,
role=member.role,
)
for member in project_members
],
batch_size=100,
)
# settings last active for the user
user.is_active = True
user.last_active = timezone.now()