@@ -17,19 +17,28 @@ import (
1717 "code.gitea.io/gitea/routers/api/v1/utils"
1818)
1919
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 )
2628 return
2729 }
30+ maxResults := len (orgs )
31+
32+ orgs = utils .PaginateUserSlice (orgs , listOptions .Page , listOptions .PageSize )
2833
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 ])
3237 }
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" )
3342 ctx .JSON (http .StatusOK , & apiOrgs )
3443}
3544
@@ -53,7 +62,7 @@ func ListMyOrgs(ctx *context.APIContext) {
5362 // "200":
5463 // "$ref": "#/responses/OrganizationList"
5564
56- listUserOrgs (ctx , ctx .User , true )
65+ listUserOrgs (ctx , ctx .User )
5766}
5867
5968// ListUserOrgs list user's orgs
@@ -85,7 +94,7 @@ func ListUserOrgs(ctx *context.APIContext) {
8594 if ctx .Written () {
8695 return
8796 }
88- listUserOrgs (ctx , u , ctx . User != nil && ( ctx . User . IsAdmin || ctx . User . ID == u . ID ) )
97+ listUserOrgs (ctx , u )
8998}
9099
91100// GetAll return list of all public organizations
0 commit comments