diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c09ba78..b098094f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fix receive channel filter in alert groups API [#2140](https://github.com/grafana/oncall/pull/2140) + ## v1.2.41 (2023-06-08) ### Added diff --git a/engine/apps/api/tests/test_alert_group.py b/engine/apps/api/tests/test_alert_group.py index ea815f28..736ff69c 100644 --- a/engine/apps/api/tests/test_alert_group.py +++ b/engine/apps/api/tests/test_alert_group.py @@ -43,6 +43,33 @@ def alert_group_internal_api_setup( return user, token, alert_groups +@pytest.mark.django_db +def test_get_filter_by_integration( + alert_group_internal_api_setup, make_alert_receive_channel, make_alert_group, make_user_auth_headers +): + user, token, alert_groups = alert_group_internal_api_setup + + ag = alert_groups[0] + # channel filter could be None, but the alert group still belongs to the original integration + ag.channel_filter = None + ag.save() + + # make an alert group in other integration + alert_receive_channel = make_alert_receive_channel(user.organization) + make_alert_group(alert_receive_channel) + + client = APIClient() + url = reverse("api-internal:alertgroup-list") + response = client.get( + url + f"?integration={ag.channel.public_primary_key}", + format="json", + **make_user_auth_headers(user, token), + ) + + assert response.status_code == status.HTTP_200_OK + 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 diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index bcae5306..1e9f4bef 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -104,7 +104,7 @@ class AlertGroupFilter(DateRangeFilterMixin, ByTeamModelFieldFilterMixin, ModelF method=ModelFieldFilterMixin.filter_model_field.__name__, ) integration = filters.ModelMultipleChoiceFilter( - field_name="channel_filter__alert_receive_channel", + field_name="channel", queryset=None, to_field_name="public_primary_key", method=ModelFieldFilterMixin.filter_model_field.__name__,