User: Support sort query param for user and org user, search endpoints (#75229)

* User: Add sort option to user search

* Switch to an approach that uses the dashboard search options

* Cable user sort on the org endpoint

* Alias user table with u in org store

* Add test and cover orgs/:orgID/users/search endpoint

* Add test to userimpl store

* Simplify the store_test with sortopts.ParseSortQueryParam

* Account for PR feedback

* Positive check

* Update docs

* Update docs

* Switch to ErrOrFallback

Co-authored-by: Karl Persson <kalle.persson@grafana.com>

---------

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
This commit is contained in:
Gabriel MABILLE
2023-09-28 10:16:18 +02:00
committed by GitHub
parent 4563fc48af
commit 96cbe70b14
13 changed files with 279 additions and 78 deletions

View File

@ -28,7 +28,7 @@ API Tokens can be used with Organization HTTP API to get users of specific organ
## Search Users
`GET /api/users?perpage=10&page=1`
`GET /api/users?perpage=10&page=1&sort=login-asc,email-asc`
**Required permissions**
@ -49,6 +49,8 @@ Authorization: Basic YWRtaW46YWRtaW4=
Default value for the `perpage` parameter is `1000` and for the `page` parameter is `1`. Requires basic authentication and that the authenticated user is a Grafana Admin.
The `sort` param is an optional comma separated list of options to order the search result. Accepted values for the sort filter are: `login-asc`, `login-desc`, `email-asc`, `email-desc`, `name-asc`, `name-desc`, `lastSeenAtAge-asc`, `lastSeenAtAge-desc`. By default, if `sort` is not specified, the user list will be ordered by `login`, `email` in ascending order.
**Example Response**:
```http
@ -83,7 +85,7 @@ Content-Type: application/json
The `sort` param is an optional comma separated list of options to order the search result. Accepted values for the sort filter are: `login-asc`, `login-desc`, `email-asc`, `email-desc`, `name-asc`, `name-desc`, `lastSeenAtAge-asc`, `lastSeenAtAge-desc`. By default, if `sort` is not specified, the user list will be ordered by `login`, `email` in ascending order.
Requires basic authentication and that the authenticated user is a Grafana Admin.
**Example Response**:
```http
@ -104,6 +106,8 @@ Authorization: Basic YWRtaW46YWRtaW4=
| ---------- | --------------- |
| users:read | global.users:\* |
**Example Request**:
```http
GET /api/users/1 HTTP/1.1
Accept: application/json