forked from NYANDEV/forgejo
Change list teams API to non-admin specific
This commit is contained in:
parent
e6f927f61a
commit
90e93b1f3a
4 changed files with 38 additions and 22 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
31
routers/api/v1/org/team.go
Normal file
31
routers/api/v1/org/team.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue