Browse Source

add pagination for admin api get orgs and fix only list public orgs bug (#7742)

tags/v1.11.0-dev
Lunny Xiao techknowlogick 5 years ago
parent
commit
16e8a23648
3 changed files with 27 additions and 4 deletions
  1. +1
    -3
      models/user.go
  2. +12
    -1
      routers/api/v1/admin/org.go
  3. +14
    -0
      templates/swagger/v1_json.tmpl

+ 1
- 3
models/user.go View File

@@ -1409,9 +1409,7 @@ type SearchUserOptions struct {
} }


func (opts *SearchUserOptions) toConds() builder.Cond { 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 { if len(opts.Keyword) > 0 {
lowerKeyword := strings.ToLower(opts.Keyword) lowerKeyword := strings.ToLower(opts.Keyword)


+ 12
- 1
routers/api/v1/admin/org.go View File

@@ -82,6 +82,15 @@ func GetAllOrgs(ctx *context.APIContext) {
// summary: List all organizations // summary: List all organizations
// produces: // produces:
// - application/json // - 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: // responses:
// "200": // "200":
// "$ref": "#/responses/OrganizationList" // "$ref": "#/responses/OrganizationList"
@@ -90,7 +99,9 @@ func GetAllOrgs(ctx *context.APIContext) {
users, _, err := models.SearchUsers(&models.SearchUserOptions{ users, _, err := models.SearchUsers(&models.SearchUserOptions{
Type: models.UserTypeOrganization, Type: models.UserTypeOrganization,
OrderBy: models.SearchOrderByAlphabetically, OrderBy: models.SearchOrderByAlphabetically,
PageSize: -1,
Page: ctx.QueryInt("page"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
Private: true,
}) })
if err != nil { if err != nil {
ctx.Error(500, "SearchOrganizations", err) ctx.Error(500, "SearchOrganizations", err)


+ 14
- 0
templates/swagger/v1_json.tmpl View File

@@ -33,6 +33,20 @@
], ],
"summary": "List all organizations", "summary": "List all organizations",
"operationId": "adminGetAllOrgs", "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": { "responses": {
"200": { "200": {
"$ref": "#/responses/OrganizationList" "$ref": "#/responses/OrganizationList"


Loading…
Cancel
Save