Change list teams API to non-admin specific

This commit is contained in:
Unknwon 2016-03-21 12:53:04 -04:00
parent e6f927f61a
commit 90e93b1f3a
4 changed files with 38 additions and 22 deletions

View file

@ -33,7 +33,7 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
if models.IsErrUserAlreadyExist(err) ||
models.IsErrNameReserved(err) ||
models.IsErrNamePatternNotAllowed(err) {
ctx.Error(422, "CreateOrganization", err)
ctx.Error(422, "", err)
} else {
ctx.Error(500, "CreateOrganization", err)
}

View file

@ -13,24 +13,6 @@ import (
"github.com/gogits/gogs/routers/api/v1/user"
)
func ListTeams(ctx *context.APIContext) {
org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() {
return
}
if err := org.GetTeams(); err != nil {
ctx.Error(500, "GetTeams", err)
return
}
apiTeams := make([]*api.Team, len(org.Teams))
for i := range org.Teams {
apiTeams[i] = convert.ToTeam(org.Teams[i])
}
ctx.JSON(200, apiTeams)
}
func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() {
@ -45,7 +27,7 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
}
if err := models.NewTeam(team); err != nil {
if models.IsErrTeamAlreadyExist(err) {
ctx.Error(422, "NewTeam", err)
ctx.Error(422, "", err)
} else {
ctx.Error(500, "NewTeam", err)
}

View file

@ -205,7 +205,10 @@ func RegisterRoutes(m *macaron.Macaron) {
// Organizations
m.Get("/user/orgs", ReqToken(), org.ListMyOrgs)
m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
m.Group("/orgs/:orgname", func() {
m.Combo("").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
m.Combo("/teams").Get(org.ListTeams)
})
m.Any("/*", func(ctx *context.Context) {
ctx.Error(404)
@ -225,7 +228,7 @@ func RegisterRoutes(m *macaron.Macaron) {
})
m.Group("/orgs/:orgname", func() {
m.Combo("/teams").Get(admin.ListTeams).Post(bind(api.CreateTeamOption{}), admin.CreateTeam)
m.Combo("/teams").Post(bind(api.CreateTeamOption{}), admin.CreateTeam)
})
}, ReqAdmin())
}, context.APIContexter())

View file

@ -0,0 +1,31 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package org
import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user"
)
func ListTeams(ctx *context.APIContext) {
org := user.GetUserByParamsName(ctx, ":orgname")
if ctx.Written() {
return
}
if err := org.GetTeams(); err != nil {
ctx.Error(500, "GetTeams", err)
return
}
apiTeams := make([]*api.Team, len(org.Teams))
for i := range org.Teams {
apiTeams[i] = convert.ToTeam(org.Teams[i])
}
ctx.JSON(200, apiTeams)
}