diff --git a/engine/apps/api/tests/test_alert_receive_channel.py b/engine/apps/api/tests/test_alert_receive_channel.py index 3ad4a8e9..2b3dba1d 100644 --- a/engine/apps/api/tests/test_alert_receive_channel.py +++ b/engine/apps/api/tests/test_alert_receive_channel.py @@ -57,6 +57,37 @@ def test_get_alert_receive_channel_by_integration_ne( assert result["integration"] != AlertReceiveChannel.INTEGRATION_DIRECT_PAGING +@pytest.mark.django_db +def test_get_alert_receive_channel_by_id_ne( + make_organization_and_user_with_plugin_token, make_organization, make_user_auth_headers, make_alert_receive_channel +): + organization, user, token = make_organization_and_user_with_plugin_token() + + alert_receive_channel_1 = make_alert_receive_channel(organization) + alert_receive_channel_2 = make_alert_receive_channel(organization) + alert_receive_channel_3 = make_alert_receive_channel(organization) + + # integration in a different org + organization = make_organization() + alert_receive_channel_4 = make_alert_receive_channel(organization) + + client = APIClient() + url = ( + reverse("api-internal:alert_receive_channel-list") + + f"?id_ne={alert_receive_channel_1.public_primary_key}&id_ne={alert_receive_channel_2.public_primary_key}" + ) + response = client.get(url, **make_user_auth_headers(user, token)) + + assert response.status_code == status.HTTP_200_OK + assert len(response.json()["results"]) == 1 + assert response.json()["results"][0]["id"] == alert_receive_channel_3.public_primary_key + + # integration in a different org shouldn't work + url = reverse("api-internal:alert_receive_channel-list") + f"?id_ne={alert_receive_channel_4.public_primary_key}" + response = client.get(url, **make_user_auth_headers(user, token)) + assert response.status_code == status.HTTP_400_BAD_REQUEST + + @pytest.mark.django_db @pytest.mark.parametrize( "query_param,should_be_unpaginated", diff --git a/engine/apps/api/views/alert_receive_channel.py b/engine/apps/api/views/alert_receive_channel.py index 80b67025..50e48b29 100644 --- a/engine/apps/api/views/alert_receive_channel.py +++ b/engine/apps/api/views/alert_receive_channel.py @@ -68,6 +68,12 @@ class AlertReceiveChannelFilter(ByTeamModelFieldFilterMixin, filters.FilterSet): choices=AlertReceiveChannel.INTEGRATION_CHOICES, field_name="integration", exclude=True ) team = TeamModelMultipleChoiceFilter() + id_ne = filters.ModelMultipleChoiceFilter( + queryset=lambda request: request.auth.organization.alert_receive_channels.all(), + field_name="public_primary_key", + to_field_name="public_primary_key", + exclude=True, + ) class Meta: model = AlertReceiveChannel