diff options
author | Unknwon <u@gogs.io> | 2016-03-25 18:04:02 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-03-25 18:04:02 -0400 |
commit | b1d41cfa603aee63711fbc23bb02fced5a4c54e3 (patch) | |
tree | dc79e8f9c8dec5ab324b27d10108667e7b4d9090 /routers/api/v1/api.go | |
parent | 9dda9ef07c03000cb961a80e3c75459c58602009 (diff) | |
download | gitea-b1d41cfa603aee63711fbc23bb02fced5a4c54e3.tar.gz gitea-b1d41cfa603aee63711fbc23bb02fced5a4c54e3.zip |
#1692 add admin APIs to add/remove a user from teams
Diffstat (limited to 'routers/api/v1/api.go')
-rw-r--r-- | routers/api/v1/api.go | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 08e6a75153..34a441f417 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -110,6 +110,42 @@ func ReqAdmin() macaron.Handler { } } +func OrgAssignment(args ...bool) macaron.Handler { + var ( + assignTeam bool + ) + + if len(args) > 0 { + assignTeam = args[0] + } + return func(ctx *context.APIContext) { + org, err := models.GetUserByName(ctx.Params(":orgname")) + if err != nil { + if models.IsErrUserNotExist(err) { + ctx.Status(404) + } else { + ctx.Error(500, "GetUserByName", err) + } + return + } + ctx.Org = &context.APIOrganization{ + Organization: org, + } + + if assignTeam { + ctx.Org.Team, err = models.GetTeamByID(ctx.ParamsInt64(":teamid")) + if err != nil { + if models.IsErrUserNotExist(err) { + ctx.Status(404) + } else { + ctx.Error(500, "GetTeamById", err) + } + return + } + } + } +} + // RegisterRoutes registers all v1 APIs routes to web application. // FIXME: custom form error response func RegisterRoutes(m *macaron.Macaron) { @@ -208,7 +244,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/orgs/:orgname", func() { m.Combo("").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit) m.Combo("/teams").Get(org.ListTeams) - }) + }, OrgAssignment()) m.Any("/*", func(ctx *context.Context) { ctx.Error(404) @@ -228,7 +264,13 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Group("/orgs/:orgname", func() { - m.Combo("/teams").Post(bind(api.CreateTeamOption{}), admin.CreateTeam) + m.Group("/teams", func() { + m.Post("", OrgAssignment(), bind(api.CreateTeamOption{}), admin.CreateTeam) + + m.Group("/:teamid", func() { + m.Combo("/memberships/:username").Put(admin.AddTeamMember).Delete(admin.RemoveTeamMember) + }, OrgAssignment(true)) + }) }) }, ReqAdmin()) }, context.APIContexter()) |