Skip to content

Commit 5b902e2

Browse files
lunnytechknowlogick
authored andcommitted
add pagination for admin api get orgs and fix only list public orgs bug (#7742)
1 parent 7b2a39c commit 5b902e2

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

models/user.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,7 @@ type SearchUserOptions struct {
14091409
}
14101410

14111411
func (opts *SearchUserOptions) toConds() builder.Cond {
1412-
1413-
var cond = builder.NewCond()
1414-
cond = cond.And(builder.Eq{"type": opts.Type})
1412+
var cond builder.Cond = builder.Eq{"type": opts.Type}
14151413

14161414
if len(opts.Keyword) > 0 {
14171415
lowerKeyword := strings.ToLower(opts.Keyword)

routers/api/v1/admin/org.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ func GetAllOrgs(ctx *context.APIContext) {
8282
// summary: List all organizations
8383
// produces:
8484
// - application/json
85+
// parameters:
86+
// - name: page
87+
// in: query
88+
// description: page number of results to return (1-based)
89+
// type: integer
90+
// - name: limit
91+
// in: query
92+
// description: page size of results, maximum page size is 50
93+
// type: integer
8594
// responses:
8695
// "200":
8796
// "$ref": "#/responses/OrganizationList"
@@ -90,7 +99,9 @@ func GetAllOrgs(ctx *context.APIContext) {
9099
users, _, err := models.SearchUsers(&models.SearchUserOptions{
91100
Type: models.UserTypeOrganization,
92101
OrderBy: models.SearchOrderByAlphabetically,
93-
PageSize: -1,
102+
Page: ctx.QueryInt("page"),
103+
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
104+
Private: true,
94105
})
95106
if err != nil {
96107
ctx.Error(500, "SearchOrganizations", err)

templates/swagger/v1_json.tmpl

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
],
3434
"summary": "List all organizations",
3535
"operationId": "adminGetAllOrgs",
36+
"parameters": [
37+
{
38+
"type": "integer",
39+
"description": "page number of results to return (1-based)",
40+
"name": "page",
41+
"in": "query"
42+
},
43+
{
44+
"type": "integer",
45+
"description": "page size of results, maximum page size is 50",
46+
"name": "limit",
47+
"in": "query"
48+
}
49+
],
3650
"responses": {
3751
"200": {
3852
"$ref": "#/responses/OrganizationList"

0 commit comments

Comments
 (0)