Browse Source

feat(alerts): Allow delete metric alerts without incidents flag (#37553)

Scott Cooper 2 years ago
parent
commit
b3b634dcb0

+ 4 - 1
src/sentry/incidents/endpoints/bases.py

@@ -38,7 +38,10 @@ class OrganizationAlertRuleEndpoint(OrganizationEndpoint):
         args, kwargs = super().convert_args(request, *args, **kwargs)
         organization = kwargs["organization"]
 
-        if not features.has("organizations:incidents", organization, actor=request.user):
+        # Allow orgs that have downgraded plans to delete metric alerts
+        if request.method != "DELETE" and not features.has(
+            "organizations:incidents", organization, actor=request.user
+        ):
             raise ResourceDoesNotExist
 
         try:

+ 7 - 0
tests/sentry/incidents/endpoints/test_organization_alert_rule_details.py

@@ -520,6 +520,13 @@ class AlertRuleDetailsDeleteEndpointTest(AlertRuleDetailsBase, APITestCase):
         assert not AlertRule.objects_with_snapshots.filter(name=self.alert_rule.name).exists()
         assert not AlertRule.objects_with_snapshots.filter(id=self.alert_rule.id).exists()
 
+    def test_no_feature(self):
+        self.create_member(
+            user=self.user, organization=self.organization, role="owner", teams=[self.team]
+        )
+        self.login_as(self.user)
+        self.get_success_response(self.organization.slug, self.alert_rule.id, status_code=204)
+
     def test_snapshot_and_create_new_with_same_name(self):
         with self.tasks():
             self.create_member(