Enable filtering users by public primary key (#3339)

Related to https://github.com/grafana/oncall/issues/3164

This will allow the following request to check if a user is currently
on-call:
`GET
/api/internal/v1/users/?search=UCGEIXI1MR1NZ&is_currently_oncall=true`
This commit is contained in:
Matias Bordese 2023-11-14 09:56:58 -03:00 committed by GitHub
parent 4cff51e43c
commit e8bd71bbab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added user timezone field to the users public API response ([#3311](https://github.com/grafana/oncall/pull/3311))
- Allow filtering users by public primary key in internal API ([#3339](https://github.com/grafana/oncall/pull/3339))
### Changed

View file

@ -262,6 +262,31 @@ def test_list_users_filtered_by_granted_permission(
assert user3.public_primary_key not in returned_user_pks
@pytest.mark.django_db
def test_list_users_filtered_by_public_primary_key(
make_organization,
make_user_for_organization,
make_token_for_organization,
make_user_auth_headers,
):
organization = make_organization()
admin_user = make_user_for_organization(organization)
user1 = make_user_for_organization(organization)
make_user_for_organization(organization)
_, token = make_token_for_organization(organization)
client = APIClient()
url = reverse("api-internal:user-list")
response = client.get(
f"{url}?search={user1.public_primary_key}", format="json", **make_user_auth_headers(admin_user, token)
)
assert response.status_code == status.HTTP_200_OK
returned_user_pks = [u["pk"] for u in response.json()["results"]]
assert returned_user_pks == [user1.public_primary_key]
@pytest.mark.django_db
def test_notification_chain_verbal(
make_organization,

View file

@ -222,6 +222,7 @@ class UserView(
"^slack_user_identity__cached_slack_login",
"^slack_user_identity__cached_name",
"^teams__name",
"=public_primary_key",
)
filterset_class = UserFilter