Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-2092] chore: soft delete migration #5286

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apiserver/plane/app/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ class Meta:
"project",
"issue",
"actor",
"deleted_at"
]


Expand All @@ -551,7 +552,7 @@ class CommentReactionSerializer(BaseSerializer):
class Meta:
model = CommentReaction
fields = "__all__"
read_only_fields = ["workspace", "project", "comment", "actor"]
read_only_fields = ["workspace", "project", "comment", "actor", "deleted_at"]


class IssueVoteSerializer(BaseSerializer):
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/app/views/cycle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ def destroy(self, request, slug, project_id, cycle_id):
workspace__slug=slug,
entity_identifier=cycle_id,
)
cycle_favorite.delete(soft=False)
cycle_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/app/views/module/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def destroy(self, request, slug, project_id, module_id):
entity_type="module",
entity_identifier=module_id,
)
module_favorite.delete(soft=False)
module_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


Expand Down
17 changes: 1 addition & 16 deletions apiserver/plane/app/views/page/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,6 @@ def destroy(self, request, slug, project_id, pk):
status=status.HTTP_403_FORBIDDEN,
)

# only the owner and admin can delete the page
if (
ProjectMember.objects.filter(
project_id=project_id,
member=request.user,
is_active=True,
role__gt=20,
).exists()
or request.user.id != page.owned_by_id
):
return Response(
{"error": "Only the owner and admin can delete the page"},
status=status.HTTP_400_BAD_REQUEST,
)

if page.archived_at is None:
return Response(
{"error": "The page should be archived before deleting"},
Expand Down Expand Up @@ -401,7 +386,7 @@ def destroy(self, request, slug, project_id, pk):
entity_identifier=pk,
entity_type="page",
)
page_favorite.delete(soft=False)
page_favorite.delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-add access control check for page deletion.

The removal of the conditional check that restricted the deletion of a page to only its owner or an admin significantly alters the access control logic. This change potentially allows unauthorized deletions. Re-add the access control check to ensure only authorized users can delete a page.

-  if not page.owned_by_id != request.user.id and not (
-      ProjectMember.objects.filter(
-          workspace__slug=slug,
-          member=request.user,
-          role=20,
-          project_id=project_id,
-          is_active=True,
-      ).exists()
-  ):
-      return Response(
-          {"error": "Only admin or owner can delete the page"},
-          status=status.HTTP_403_FORBIDDEN,
-      )

Committable suggestion was skipped due to low confidence.

return Response(status=status.HTTP_204_NO_CONTENT)


Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/app/views/project/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def destroy(self, request, slug, project_id):
user=request.user,
workspace__slug=slug,
)
project_favorite.delete(soft=False)
project_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


Expand Down
10 changes: 8 additions & 2 deletions apiserver/plane/app/views/search/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ def get(self, request, slug, project_id):
issue = Issue.issue_objects.get(pk=issue_id)
issues = issues.filter(
~Q(pk=issue_id),
~Q(issue_related__issue=issue),
~Q(issue_relation__related_issue=issue),
~Q(
issue_related__issue=issue,
issue_related__deleted_at__isnull=True,
),
~Q(
issue_relation__related_issue=issue,
issue_related__deleted_at__isnull=True,
),
)
if sub_issue == "true" and issue_id:
issue = Issue.issue_objects.get(pk=issue_id)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/app/views/view/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,5 @@ def destroy(self, request, slug, project_id, view_id):
entity_type="view",
entity_identifier=view_id,
)
view_favorite.delete(soft=False)
view_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
Loading
Loading