diff --git a/apiserver/plane/license/api/views/instance.py b/apiserver/plane/license/api/views/instance.py index 1e2d34bd0..0e40b897f 100644 --- a/apiserver/plane/license/api/views/instance.py +++ b/apiserver/plane/license/api/views/instance.py @@ -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()