Skip to content

Commit c6f1825

Browse files
lunnytechknowlogick
authored andcommitted
add pagination for admin api get orgs and fix only list public orgs bug (#7742) (#7752)
1 parent 4f5dbc4 commit c6f1825

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
@@ -1376,9 +1376,7 @@ type SearchUserOptions struct {
13761376
}
13771377

13781378
func (opts *SearchUserOptions) toConds() builder.Cond {
1379-
1380-
var cond = builder.NewCond()
1381-
cond = cond.And(builder.Eq{"type": opts.Type})
1379+
var cond builder.Cond = builder.Eq{"type": opts.Type}
13821380

13831381
if len(opts.Keyword) > 0 {
13841382
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)