@@ -18,18 +18,27 @@ import (
18
18
)
19
19
20
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 )
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
0 commit comments