Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable filtering users by public primary key #3339

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions engine/apps/api/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions engine/apps/api/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading