forked from github/plane
fix: project member delete when deleting user from workspace (#1123)
* fix: project member delete when deleting user from workspace * fix: workspace and project member delete
This commit is contained in:
parent
e608b58e70
commit
af2d7d6f75
@ -37,18 +37,19 @@ from plane.db.models import (
|
|||||||
State,
|
State,
|
||||||
TeamMember,
|
TeamMember,
|
||||||
ProjectFavorite,
|
ProjectFavorite,
|
||||||
|
ProjectIdentifier,
|
||||||
|
Module,
|
||||||
|
Cycle,
|
||||||
|
CycleFavorite,
|
||||||
|
ModuleFavorite,
|
||||||
|
PageFavorite,
|
||||||
|
IssueViewFavorite,
|
||||||
|
Page,
|
||||||
|
IssueAssignee,
|
||||||
|
ModuleMember
|
||||||
)
|
)
|
||||||
|
|
||||||
from plane.db.models import (
|
|
||||||
Project,
|
|
||||||
ProjectMember,
|
|
||||||
Workspace,
|
|
||||||
ProjectMemberInvite,
|
|
||||||
User,
|
|
||||||
ProjectIdentifier,
|
|
||||||
Cycle,
|
|
||||||
Module,
|
|
||||||
)
|
|
||||||
from plane.bgtasks.project_invitation_task import project_invitation
|
from plane.bgtasks.project_invitation_task import project_invitation
|
||||||
|
|
||||||
|
|
||||||
@ -443,6 +444,33 @@ class ProjectMemberViewSet(BaseViewSet):
|
|||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
def destroy(self, request, slug, project_id, pk):
|
||||||
|
try:
|
||||||
|
project_member = ProjectMember.objects.get(
|
||||||
|
workspace__slug=slug, project_id=project_id, pk=pk
|
||||||
|
)
|
||||||
|
# Remove all favorites
|
||||||
|
ProjectFavorite.objects.filter(workspace__slug=slug, project_id=project_id, user=project_member.member).delete()
|
||||||
|
CycleFavorite.objects.filter(workspace__slug=slug, project_id=project_id, user=project_member.member).delete()
|
||||||
|
ModuleFavorite.objects.filter(workspace__slug=slug, project_id=project_id, user=project_member.member).delete()
|
||||||
|
PageFavorite.objects.filter(workspace__slug=slug, project_id=project_id, user=project_member.member).delete()
|
||||||
|
IssueViewFavorite.objects.filter(workspace__slug=slug, project_id=project_id, user=project_member.member).delete()
|
||||||
|
# Also remove issue from issue assigned
|
||||||
|
IssueAssignee.objects.filter(
|
||||||
|
workspace__slug=slug, project_id=project_id, assignee=project_member.member
|
||||||
|
).delete()
|
||||||
|
|
||||||
|
# Remove if module member
|
||||||
|
ModuleMember.objects.filter(workspace__slug=slug, project_id=project_id, member=project_member.member).delete()
|
||||||
|
# Delete owned Pages
|
||||||
|
Page.objects.filter(workspace__slug=slug, project_id=project_id, owned_by=project_member.member).delete()
|
||||||
|
project_member.delete()
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
except ProjectMember.DoesNotExist:
|
||||||
|
return Response({"error": "Project Member does not exist"}, status=status.HTTP_400)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response({"error": "Something went wrong please try again later"})
|
||||||
|
|
||||||
|
|
||||||
class AddMemberToProjectEndpoint(BaseAPIView):
|
class AddMemberToProjectEndpoint(BaseAPIView):
|
||||||
|
@ -50,6 +50,14 @@ from plane.db.models import (
|
|||||||
IssueActivity,
|
IssueActivity,
|
||||||
Issue,
|
Issue,
|
||||||
WorkspaceTheme,
|
WorkspaceTheme,
|
||||||
|
IssueAssignee,
|
||||||
|
ProjectFavorite,
|
||||||
|
CycleFavorite,
|
||||||
|
ModuleMember,
|
||||||
|
ModuleFavorite,
|
||||||
|
PageFavorite,
|
||||||
|
Page,
|
||||||
|
IssueViewFavorite,
|
||||||
)
|
)
|
||||||
from plane.api.permissions import WorkSpaceBasePermission, WorkSpaceAdminPermission
|
from plane.api.permissions import WorkSpaceBasePermission, WorkSpaceAdminPermission
|
||||||
from plane.bgtasks.workspace_invitation_task import workspace_invitation
|
from plane.bgtasks.workspace_invitation_task import workspace_invitation
|
||||||
@ -460,6 +468,43 @@ class WorkSpaceMemberViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def destroy(self, request, slug, pk):
|
||||||
|
try:
|
||||||
|
workspace_member = WorkspaceMember.objects.get(workspace__slug=slug, pk=pk)
|
||||||
|
# Delete the user also from all the projects
|
||||||
|
ProjectMember.objects.filter(
|
||||||
|
workspace__slug=slug, member=workspace_member.member
|
||||||
|
).delete()
|
||||||
|
# Remove all favorites
|
||||||
|
ProjectFavorite.objects.filter(workspace__slug=slug, user=workspace_member.member).delete()
|
||||||
|
CycleFavorite.objects.filter(workspace__slug=slug, user=workspace_member.member).delete()
|
||||||
|
ModuleFavorite.objects.filter(workspace__slug=slug, user=workspace_member.member).delete()
|
||||||
|
PageFavorite.objects.filter(workspace__slug=slug, user=workspace_member.member).delete()
|
||||||
|
IssueViewFavorite.objects.filter(workspace__slug=slug, user=workspace_member.member).delete()
|
||||||
|
# Also remove issue from issue assigned
|
||||||
|
IssueAssignee.objects.filter(
|
||||||
|
workspace__slug=slug, assignee=workspace_member.member
|
||||||
|
).delete()
|
||||||
|
|
||||||
|
# Remove if module member
|
||||||
|
ModuleMember.objects.filter(workspace__slug=slug, member=workspace_member.member).delete()
|
||||||
|
# Delete owned Pages
|
||||||
|
Page.objects.filter(workspace__slug=slug, owned_by=workspace_member.member).delete()
|
||||||
|
|
||||||
|
workspace_member.delete()
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
except WorkspaceMember.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "Workspace Member does not exists"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TeamMemberViewSet(BaseViewSet):
|
class TeamMemberViewSet(BaseViewSet):
|
||||||
serializer_class = TeamSerializer
|
serializer_class = TeamSerializer
|
||||||
|
Loading…
Reference in New Issue
Block a user