Add id_ne filter for integrations (internal API) (#4032)
# What this PR does Adds a new multiple choice `id_ne` (ID not equal) filter to internal API integrations endpoint. ## Which issue(s) this PR closes Related to https://github.com/grafana/oncall-private/issues/2540 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
This commit is contained in:
parent
cf1fac8997
commit
6d9d58d0db
2 changed files with 37 additions and 0 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue