Skip to content

Commit

Permalink
fix(issue_platform): Allow deleting in the group details endpoint (#7…
Browse files Browse the repository at this point in the history
…9016)

I missed this in #77794.
  • Loading branch information
armenzg authored Oct 11, 2024
1 parent 911c2a5 commit 47dbada
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/sentry/issues/endpoints/group_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
```````````````
Expand All @@ -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:
Expand Down
25 changes: 24 additions & 1 deletion tests/snuba/api/endpoints/test_group_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 47dbada

Please sign in to comment.