Skip to content

Commit

Permalink
Merge pull request #1052 from AI4Bharat/revert-1047-remove_user
Browse files Browse the repository at this point in the history
Revert "added a feature to remove user as workspace member and manager when h…"
  • Loading branch information
aparna-aa authored Apr 15, 2024
2 parents 6c2a68c + b064b78 commit 7b2a8f7
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions backend/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from rest_framework_simplejwt.tokens import RefreshToken
from dotenv import load_dotenv
import logging
from workspaces.views import WorkspaceusersViewSet
from workspaces.views import WorkspaceViewSet

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -686,38 +686,14 @@ def user_details_update(self, request, pk=None):
workspaces = Workspace.objects.filter(
Q(members=user) | Q(managers=user)
)
workspacecustomviewset_obj = WorkspaceCustomViewSet()
request.data["ids"] = [user.id]

workspaceusersviewset_obj = WorkspaceusersViewSet()
request.data["user_id"] = user.id

failed_workspace_unassign = []
failed_workspace_remove = []

workspace_view = WorkspaceViewSet()
for workspace in workspaces:
response_unassign = workspacecustomviewset_obj.unassign_manager(
request=request, pk=workspace.pk
workspace_view.unassign_manager(
request, pk=workspace.pk, ids=[user.id]
)

if response_unassign.status_code != 200:
failed_workspace_unassign.append(workspace.pk)

response_remove = workspaceusersviewset_obj.remove_members(
request=request, pk=workspace.pk
workspace_view.remove_members(
request, pk=workspace.pk, user_id=user.id
)

if response_remove.status_code != 200:
failed_workspace_remove.append(workspace.pk)

message = "User removed from some workspaces both as workspace member and workspace manager."
if failed_workspace_unassign:
message += f" {failed_workspace_unassign} failed to unassign user as workspace manager."
if failed_workspace_remove:
message += f" {failed_workspace_remove} failed to remove user as workspace member."
if message:
return Response({"message": message}, status=status.HTTP_200_OK)

return Response(
{
"message": "User removed from all workspaces both as workspace member and workspace manager"
Expand Down

0 comments on commit 7b2a8f7

Please sign in to comment.