@@ -17,19 +17,28 @@ import (
17
17
"code.gitea.io/gitea/routers/api/v1/utils"
18
18
)
19
19
20
- func listUserOrgs (ctx * context.APIContext , u * models.User , all bool ) {
21
- if err := u .GetOrganizations (& models.SearchOrganizationsOptions {
22
- ListOptions : utils .GetListOptions (ctx ),
23
- All : all ,
24
- }); err != nil {
25
- ctx .Error (http .StatusInternalServerError , "GetOrganizations" , err )
20
+ func listUserOrgs (ctx * context.APIContext , u * models.User ) {
21
+
22
+ listOptions := utils .GetListOptions (ctx )
23
+ showPrivate := ctx .IsSigned && (ctx .User .IsAdmin || ctx .User .ID == u .ID )
24
+
25
+ orgs , err := models .GetOrgsByUserID (u .ID , showPrivate )
26
+ if err != nil {
27
+ ctx .Error (http .StatusInternalServerError , "GetOrgsByUserID" , err )
26
28
return
27
29
}
30
+ maxResults := len (orgs )
31
+
32
+ orgs = utils .PaginateUserSlice (orgs , listOptions .Page , listOptions .PageSize )
28
33
29
- apiOrgs := make ([]* api.Organization , len (u . Orgs ))
30
- for i := range u . Orgs {
31
- apiOrgs [i ] = convert .ToOrganization (u . Orgs [i ])
34
+ apiOrgs := make ([]* api.Organization , len (orgs ))
35
+ for i := range orgs {
36
+ apiOrgs [i ] = convert .ToOrganization (orgs [i ])
32
37
}
38
+
39
+ ctx .SetLinkHeader (int (maxResults ), listOptions .PageSize )
40
+ ctx .Header ().Set ("X-Total-Count" , fmt .Sprintf ("%d" , maxResults ))
41
+ ctx .Header ().Set ("Access-Control-Expose-Headers" , "X-Total-Count, Link" )
33
42
ctx .JSON (http .StatusOK , & apiOrgs )
34
43
}
35
44
@@ -53,7 +62,7 @@ func ListMyOrgs(ctx *context.APIContext) {
53
62
// "200":
54
63
// "$ref": "#/responses/OrganizationList"
55
64
56
- listUserOrgs (ctx , ctx .User , true )
65
+ listUserOrgs (ctx , ctx .User )
57
66
}
58
67
59
68
// ListUserOrgs list user's orgs
@@ -85,7 +94,7 @@ func ListUserOrgs(ctx *context.APIContext) {
85
94
if ctx .Written () {
86
95
return
87
96
}
88
- listUserOrgs (ctx , u , ctx . User != nil && ( ctx . User . IsAdmin || ctx . User . ID == u . ID ) )
97
+ listUserOrgs (ctx , u )
89
98
}
90
99
91
100
// GetAll return list of all public organizations
0 commit comments