diff --git a/backend/users/views.py b/backend/users/views.py index d3afbca24..d99e4ab15 100644 --- a/backend/users/views.py +++ b/backend/users/views.py @@ -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) @@ -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"