|
|
|
@ -17,19 +17,28 @@ import (
|
|
|
|
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
|
|
|
|
|
if err := u.GetOrganizations(&models.SearchOrganizationsOptions{
|
|
|
|
|
ListOptions: utils.GetListOptions(ctx),
|
|
|
|
|
All: all,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetOrganizations", err)
|
|
|
|
|
func listUserOrgs(ctx *context.APIContext, u *models.User) {
|
|
|
|
|
|
|
|
|
|
listOptions := utils.GetListOptions(ctx)
|
|
|
|
|
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
|
|
|
|
|
|
|
|
|
|
orgs, err := models.GetOrgsByUserID(u.ID, showPrivate)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, "GetOrgsByUserID", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
maxResults := len(orgs)
|
|
|
|
|
|
|
|
|
|
orgs = utils.PaginateUserSlice(orgs, listOptions.Page, listOptions.PageSize)
|
|
|
|
|
|
|
|
|
|
apiOrgs := make([]*api.Organization, len(u.Orgs))
|
|
|
|
|
for i := range u.Orgs {
|
|
|
|
|
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
|
|
|
|
|
apiOrgs := make([]*api.Organization, len(orgs))
|
|
|
|
|
for i := range orgs {
|
|
|
|
|
apiOrgs[i] = convert.ToOrganization(orgs[i])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
|
|
|
|
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
|
|
|
|
|
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
|
|
|
|
|
ctx.JSON(http.StatusOK, &apiOrgs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,7 +62,7 @@ func ListMyOrgs(ctx *context.APIContext) {
|
|
|
|
|
// "200":
|
|
|
|
|
// "$ref": "#/responses/OrganizationList"
|
|
|
|
|
|
|
|
|
|
listUserOrgs(ctx, ctx.User, true)
|
|
|
|
|
listUserOrgs(ctx, ctx.User)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListUserOrgs list user's orgs
|
|
|
|
@ -85,7 +94,7 @@ func ListUserOrgs(ctx *context.APIContext) {
|
|
|
|
|
if ctx.Written() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
listUserOrgs(ctx, u, ctx.User != nil && (ctx.User.IsAdmin || ctx.User.ID == u.ID))
|
|
|
|
|
listUserOrgs(ctx, u)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetAll return list of all public organizations
|
|
|
|
|