fix: user deactivation if instance admin and remove auto assigning of workspace and projects

This commit is contained in:
pablohashescobar 2023-12-08 13:52:01 +05:30 committed by sriram veeraghanta
parent d4a4046cd3
commit aebf8daf08
2 changed files with 4 additions and 31 deletions

View File

@ -49,6 +49,10 @@ class UserEndpoint(BaseViewSet):
# Check all workspace user is active
user = self.get_object()
# Instance admin check
if InstanceAdmin.objects.filter(user=user).exists():
return Response({"error": "You cannot deactivate your account since you are an instance admin"}, status=status.HTTP_400_BAD_REQUEST)
projects_to_deactivate = []
workspaces_to_deactivate = []

View File

@ -221,37 +221,6 @@ 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()