From 47dbada5f58ce27b3f55f669f11d64e3b27813b0 Mon Sep 17 00:00:00 2001 From: "Armen Zambrano G." <44410+armenzg@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:21:12 -0400 Subject: [PATCH] fix(issue_platform): Allow deleting in the group details endpoint (#79016) I missed this in #77794. --- src/sentry/issues/endpoints/group_details.py | 8 ++++-- .../snuba/api/endpoints/test_group_details.py | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/sentry/issues/endpoints/group_details.py b/src/sentry/issues/endpoints/group_details.py index a4ca1e2f19ab83..40117285948b6c 100644 --- a/src/sentry/issues/endpoints/group_details.py +++ b/src/sentry/issues/endpoints/group_details.py @@ -384,7 +384,7 @@ def put(self, request: Request, group) -> Response: ) return Response(e.body, status=e.status_code) - def delete(self, request: Request, group) -> Response: + def delete(self, request: Request, group: Group) -> Response: """ Remove an Issue ``````````````` @@ -396,7 +396,11 @@ def delete(self, request: Request, group) -> Response: """ from sentry.utils import snuba - if group.issue_category != GroupCategory.ERROR: + issue_platform_deletion_allowed = features.has( + "organizations:issue-platform-deletion", group.project.organization, actor=request.user + ) + + if group.issue_category != GroupCategory.ERROR and not issue_platform_deletion_allowed: raise ValidationError(detail="Only error issues can be deleted.") try: diff --git a/tests/snuba/api/endpoints/test_group_details.py b/tests/snuba/api/endpoints/test_group_details.py index b0f6c81b4192d6..0fbbf32aa1d01d 100644 --- a/tests/snuba/api/endpoints/test_group_details.py +++ b/tests/snuba/api/endpoints/test_group_details.py @@ -4,13 +4,15 @@ from sentry import tsdb from sentry.issues.forecasts import generate_and_save_forecasts +from sentry.issues.grouptype import PerformanceSlowDBQueryGroupType from sentry.models.activity import Activity from sentry.models.environment import Environment -from sentry.models.group import GroupStatus +from sentry.models.group import Group, GroupStatus from sentry.models.groupinbox import GroupInboxReason, add_group_to_inbox, remove_group_from_inbox from sentry.models.groupowner import GROUP_OWNER_TYPE, GroupOwner, GroupOwnerType from sentry.models.release import Release from sentry.testutils.cases import APITestCase, SnubaTestCase +from sentry.testutils.helpers import Feature from sentry.testutils.helpers.datetime import before_now, iso_format from sentry.types.activity import ActivityType from sentry.types.group import PriorityLevel @@ -315,3 +317,24 @@ def test_issue_type_category(self): assert int(response.data["id"]) == event.group.id assert response.data["issueType"] == "error" assert response.data["issueCategory"] == "error" + + def test_delete_issue_platform_deletion(self): + """Test that a user cannot delete an issue if issue platform deletion is not allowed""" + self.login_as(user=self.user) + + group = self.create_group( + status=GroupStatus.RESOLVED, + project=self.project, + type=PerformanceSlowDBQueryGroupType.type_id, + ) + + url = f"/api/0/issues/{group.id}/" + response = self.client.delete(url, format="json") + assert response.status_code == 400 + assert response.json() == ["Only error issues can be deleted."] + + # We are allowed to delete the groups with the feature flag enabled + with Feature({"organizations:issue-platform-deletion": True}), self.tasks(): + response = self.client.delete(url, format="json") + assert response.status_code == 202 + assert not Group.objects.filter(id=group.id).exists()