mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
API: Support paging in the admin orgs list API (#26932)
* Add page/limit to org search * Update docs * Fix test per PR feedback
This commit is contained in:
parent
214c1078aa
commit
3403db190d
@ -325,7 +325,7 @@ Content-Type: application/json
|
|||||||
|
|
||||||
### Search all Organizations
|
### Search all Organizations
|
||||||
|
|
||||||
`GET /api/orgs`
|
`GET /api/orgs?perpage=10&page=1`
|
||||||
|
|
||||||
Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api).
|
Only works with Basic Authentication (username and password), see [introduction](#admin-organizations-api).
|
||||||
|
|
||||||
@ -339,6 +339,8 @@ Content-Type: application/json
|
|||||||
Note: The api will only work when you pass the admin name and password
|
Note: The api will only work when you pass the admin name and password
|
||||||
to the request HTTP URL, like http://admin:admin@localhost:3000/api/orgs
|
to the request HTTP URL, like http://admin:admin@localhost:3000/api/orgs
|
||||||
|
|
||||||
|
Default value for the `perpage` parameter is `1000` and for the `page` parameter is `0`.
|
||||||
|
|
||||||
**Example Response**:
|
**Example Response**:
|
||||||
|
|
||||||
```http
|
```http
|
||||||
|
@ -160,11 +160,18 @@ func DeleteOrgByID(c *models.ReqContext) Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SearchOrgs(c *models.ReqContext) Response {
|
func SearchOrgs(c *models.ReqContext) Response {
|
||||||
|
perPage := c.QueryInt("perpage")
|
||||||
|
if perPage <= 0 {
|
||||||
|
perPage = 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
page := c.QueryInt("page")
|
||||||
|
|
||||||
query := models.SearchOrgsQuery{
|
query := models.SearchOrgsQuery{
|
||||||
Query: c.Query("query"),
|
Query: c.Query("query"),
|
||||||
Name: c.Query("name"),
|
Name: c.Query("name"),
|
||||||
Page: 0,
|
Page: page,
|
||||||
Limit: 1000,
|
Limit: perPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bus.Dispatch(&query); err != nil {
|
if err := bus.Dispatch(&query); err != nil {
|
||||||
|
@ -35,6 +35,38 @@ func TestAccountDataAccess(t *testing.T) {
|
|||||||
So(len(query.Result), ShouldEqual, 3)
|
So(len(query.Result), ShouldEqual, 3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Given we have organizations, we can limit and paginate search", func() {
|
||||||
|
for i := 1; i < 4; i++ {
|
||||||
|
cmd := &models.CreateOrgCommand{Name: fmt.Sprint("Org #", i)}
|
||||||
|
err := CreateOrg(cmd)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
Convey("Should be able to search with defaults", func() {
|
||||||
|
query := &models.SearchOrgsQuery{}
|
||||||
|
err := SearchOrgs(query)
|
||||||
|
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(len(query.Result), ShouldEqual, 3)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Should be able to limit search", func() {
|
||||||
|
query := &models.SearchOrgsQuery{Limit: 1}
|
||||||
|
err := SearchOrgs(query)
|
||||||
|
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Should be able to limit and paginate search", func() {
|
||||||
|
query := &models.SearchOrgsQuery{Limit: 2, Page: 1}
|
||||||
|
err := SearchOrgs(query)
|
||||||
|
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Convey("Given single org mode", func() {
|
Convey("Given single org mode", func() {
|
||||||
setting.AutoAssignOrg = true
|
setting.AutoAssignOrg = true
|
||||||
setting.AutoAssignOrgId = 1
|
setting.AutoAssignOrgId = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user