Repository: getsentry/sentry

Issue:
[BE] Update the alerts response to include whether the alert was disabled due to being “noisy”
Similar to https://github.com/getsentry/sentry/issues/55098 - update the response to include something like `disableReason: noisy` if a `NoisyIssueAlert` entry exists for that rule id. Also need to add a `noisyDisableDate` so the front end can know whether or not to display the banner. 


Discussion:

Resolving patch:
diff --git a/src/sentry/api/serializers/models/rule.py b/src/sentry/api/serializers/models/rule.py
--- a/src/sentry/api/serializers/models/rule.py
+++ b/src/sentry/api/serializers/models/rule.py
@@ -15,6 +15,7 @@
     actor_type_to_string,
 )
 from sentry.models.actor import Actor
+from sentry.models.rule import NeglectedRule
 from sentry.models.rulefirehistory import RuleFireHistory
 from sentry.models.rulesnooze import RuleSnooze
 from sentry.services.hybrid_cloud.user.service import user_service
@@ -195,4 +196,13 @@ def serialize(self, obj, attrs, user, **kwargs):
         else:
             d["snooze"] = False
 
+        try:
+            neglected_rule = NeglectedRule.objects.get(
+                rule=obj, organization=obj.project.organization_id, opted_out=False
+            )
+            d["disableReason"] = "noisy"
+            d["disableDate"] = neglected_rule.disable_date
+        except (NeglectedRule.DoesNotExist, NeglectedRule.MultipleObjectsReturned):
+            pass
+
         return d


Test patch:
diff --git a/tests/sentry/api/endpoints/test_project_rule_details.py b/tests/sentry/api/endpoints/test_project_rule_details.py
--- a/tests/sentry/api/endpoints/test_project_rule_details.py
+++ b/tests/sentry/api/endpoints/test_project_rule_details.py
@@ -1,6 +1,6 @@
 from __future__ import annotations
 
-from datetime import datetime, timezone
+from datetime import datetime, timedelta, timezone
 from typing import Any, Mapping
 from unittest.mock import patch
 
@@ -10,7 +10,14 @@
 
 from sentry.constants import ObjectStatus
 from sentry.integrations.slack.utils.channel import strip_channel_name
-from sentry.models import Environment, Integration, Rule, RuleActivity, RuleActivityType
+from sentry.models import (
+    Environment,
+    Integration,
+    NeglectedRule,
+    Rule,
+    RuleActivity,
+    RuleActivityType,
+)
 from sentry.models.actor import Actor, get_actor_for_user
 from sentry.models.rulefirehistory import RuleFireHistory
 from sentry.silo import SiloMode
@@ -160,6 +167,28 @@ def test_with_filters(self):
         assert len(response.data["filters"]) == 1
         assert response.data["filters"][0]["id"] == conditions[1]["id"]
 
+    @responses.activate
+    def test_neglected_rule(self):
+        now = datetime.now().replace(tzinfo=timezone.utc)
+        NeglectedRule.objects.create(
+            rule=self.rule,
+            organization=self.organization,
+            opted_out=False,
+            disable_date=now + timedelta(days=14),
+        )
+        response = self.get_success_response(
+            self.organization.slug, self.project.slug, self.rule.id, status_code=200
+        )
+        assert response.data["disableReason"] == "noisy"
+        assert response.data["disableDate"] == now + timedelta(days=14)
+
+        another_rule = self.create_project_rule(project=self.project)
+        response = self.get_success_response(
+            self.organization.slug, self.project.slug, another_rule.id, status_code=200
+        )
+        assert not response.data.get("disableReason")
+        assert not response.data.get("disableDate")
+
     @responses.activate
     def test_with_snooze_rule(self):
         self.snooze_rule(user_id=self.user.id, owner_id=self.user.id, rule=self.rule)