aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-21 12:53:04 -0400
committerUnknwon <u@gogs.io>2016-03-21 12:53:04 -0400
commit90e93b1f3a10f2810f7a34024288ae73e64e1098 (patch)
treece81e7abe40f35a175cc8fe5b866e89d2cf9d232 /routers
parente6f927f61af927156798390e64f17dd6755697e7 (diff)
downloadgitea-90e93b1f3a10f2810f7a34024288ae73e64e1098.tar.gz
gitea-90e93b1f3a10f2810f7a34024288ae73e64e1098.zip
Change list teams API to non-admin specific
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/admin/org.go2
-rw-r--r--routers/api/v1/admin/org_team.go20
-rw-r--r--routers/api/v1/api.go7
-rw-r--r--routers/api/v1/org/team.go31
4 files changed, 38 insertions, 22 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index fcce3b9314..e82fc3ed66 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -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)
}
diff --git a/routers/api/v1/admin/org_team.go b/routers/api/v1/admin/org_team.go
index 618dd9a948..e3f9a1f1f0 100644
--- a/routers/api/v1/admin/org_team.go
+++ b/routers/api/v1/admin/org_team.go
@@ -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)
}
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 744289ac0d..08e6a75153 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -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())
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
new file mode 100644
index 0000000000..fad0d2f703
--- /dev/null
+++ b/routers/api/v1/org/team.go
@@ -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)
+}