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

Add pagination for admin api get orgs and fix only list public orgs bug #7742

Merged
merged 2 commits into from
Aug 4, 2019
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
4 changes: 1 addition & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,9 +1409,7 @@ type SearchUserOptions struct {
}

func (opts *SearchUserOptions) toConds() builder.Cond {

var cond = builder.NewCond()
cond = cond.And(builder.Eq{"type": opts.Type})
var cond builder.Cond = builder.Eq{"type": opts.Type}

if len(opts.Keyword) > 0 {
lowerKeyword := strings.ToLower(opts.Keyword)
Expand Down
13 changes: 12 additions & 1 deletion routers/api/v1/admin/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ func GetAllOrgs(ctx *context.APIContext) {
// summary: List all organizations
// produces:
// - application/json
// parameters:
// - name: page
// in: query
// description: page number of results to return (1-based)
// type: integer
// - name: limit
// in: query
// description: page size of results, maximum page size is 50
// type: integer
// responses:
// "200":
// "$ref": "#/responses/OrganizationList"
Expand All @@ -90,7 +99,9 @@ func GetAllOrgs(ctx *context.APIContext) {
users, _, err := models.SearchUsers(&models.SearchUserOptions{
Type: models.UserTypeOrganization,
OrderBy: models.SearchOrderByAlphabetically,
PageSize: -1,
Page: ctx.QueryInt("page"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
Private: true,
})
if err != nil {
ctx.Error(500, "SearchOrganizations", err)
Expand Down
14 changes: 14 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
],
"summary": "List all organizations",
"operationId": "adminGetAllOrgs",
"parameters": [
{
"type": "integer",
"description": "page number of results to return (1-based)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "page size of results, maximum page size is 50",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/OrganizationList"
Expand Down