Skip to content

Commit

Permalink
Return alert groups for deleted integrations on private api (#3223)
Browse files Browse the repository at this point in the history
# What this PR does

This PR adds alert groups from deleted integrations to the api response.
More details in this [slack
thread](https://raintank-corp.slack.com/archives/C0229FD3CE9/p1698742008962209)

## Which issue(s) this PR fixes

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Matvey Kukuy <[email protected]>
  • Loading branch information
iskhakov and Matvey-Kuk authored Nov 2, 2023
1 parent e89018f commit a936430
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions engine/apps/api/tests/test_alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ def test_get_filter_by_integration(
assert len(response.data["results"]) == 4


@pytest.mark.django_db
def test_get_alert_groups_from_deleted_integration(alert_group_internal_api_setup, make_user_auth_headers):
user, token, alert_groups = alert_group_internal_api_setup

alert_receive_channel = alert_groups[0].channel
alert_receive_channel.delete()

client = APIClient()

url = reverse("api-internal:alertgroup-list")
response = client.get(
url,
format="json",
**make_user_auth_headers(user, token),
)

assert response.status_code == status.HTTP_200_OK
# Alert groups from deleted integrations should be returned
assert len(response.data["results"]) == 4


@pytest.mark.django_db
def test_get_filter_started_at(alert_group_internal_api_setup, make_user_auth_headers):
user, token, _ = alert_group_internal_api_setup
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/api/views/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_serializer_class(self):
def get_queryset(self, ignore_filtering_by_available_teams=False):
# no select_related or prefetch_related is used at this point, it will be done on paginate_queryset.

alert_receive_channels_qs = AlertReceiveChannel.objects.filter(
alert_receive_channels_qs = AlertReceiveChannel.objects_with_deleted.filter(
organization_id=self.request.auth.organization.id
)
if not ignore_filtering_by_available_teams:
Expand Down

0 comments on commit a936430

Please sign in to comment.