API endpoints for organization teams (#370)
This commit is contained in:
parent
c463b1b8cb
commit
f686a32eac
3 changed files with 70 additions and 0 deletions
|
@ -33,6 +33,31 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
|
|||
ctx.JSON(201, convert.ToTeam(team))
|
||||
}
|
||||
|
||||
// EditTeam api for edit a team
|
||||
func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
|
||||
team := &models.Team{
|
||||
ID: ctx.Org.Team.ID,
|
||||
OrgID: ctx.Org.Team.OrgID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
}
|
||||
if err := models.UpdateTeam(team, true); err != nil {
|
||||
ctx.Error(500, "EditTeam", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToTeam(team))
|
||||
}
|
||||
|
||||
// DeleteTeam api for delete a team
|
||||
func DeleteTeam(ctx *context.APIContext) {
|
||||
if err := models.DeleteTeam(ctx.Org.Team); err != nil {
|
||||
ctx.Error(500, "DeleteTeam", err)
|
||||
return
|
||||
}
|
||||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// AddTeamMember api for add a member to a team
|
||||
func AddTeamMember(ctx *context.APIContext) {
|
||||
u := user.GetUserByParams(ctx)
|
||||
|
|
|
@ -357,6 +357,11 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
Delete(org.DeleteHook)
|
||||
})
|
||||
}, orgAssignment(true))
|
||||
m.Group("/teams/:teamid", func() {
|
||||
m.Get("", org.GetTeam)
|
||||
m.Get("/members", org.GetTeamMembers)
|
||||
m.Get("/repos", org.GetTeamRepos)
|
||||
}, orgAssignment(false, true))
|
||||
|
||||
m.Any("/*", func(ctx *context.Context) {
|
||||
ctx.Error(404)
|
||||
|
@ -382,6 +387,8 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
})
|
||||
m.Group("/teams", func() {
|
||||
m.Group("/:teamid", func() {
|
||||
m.Combo("").Patch(bind(api.EditTeamOption{}), admin.EditTeam).
|
||||
Delete(admin.DeleteTeam)
|
||||
m.Combo("/members/:username").Put(admin.AddTeamMember).Delete(admin.RemoveTeamMember)
|
||||
m.Combo("/repos/:reponame").Put(admin.AddTeamRepository).Delete(admin.RemoveTeamRepository)
|
||||
}, orgAssignment(false, true))
|
||||
|
|
|
@ -7,6 +7,7 @@ package org
|
|||
import (
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
@ -25,3 +26,40 @@ func ListTeams(ctx *context.APIContext) {
|
|||
}
|
||||
ctx.JSON(200, apiTeams)
|
||||
}
|
||||
|
||||
// GetTeam api for get a team
|
||||
func GetTeam(ctx *context.APIContext) {
|
||||
ctx.JSON(200, convert.ToTeam(ctx.Org.Team))
|
||||
}
|
||||
|
||||
// GetTeamMembers api for get a team's members
|
||||
func GetTeamMembers(ctx *context.APIContext) {
|
||||
team := ctx.Org.Team
|
||||
if err := team.GetMembers(); err != nil {
|
||||
ctx.Error(500, "GetTeamMembers", err)
|
||||
return
|
||||
}
|
||||
members := make([]*api.User, len(team.Members))
|
||||
for i, member := range team.Members {
|
||||
members[i] = member.APIFormat()
|
||||
}
|
||||
ctx.JSON(200, members)
|
||||
}
|
||||
|
||||
// GetTeamRepos api for get a team's repos
|
||||
func GetTeamRepos(ctx *context.APIContext) {
|
||||
team := ctx.Org.Team
|
||||
if err := team.GetRepositories(); err != nil {
|
||||
ctx.Error(500, "GetTeamRepos", err)
|
||||
}
|
||||
repos := make([]*api.Repository, len(team.Repos))
|
||||
for i, repo := range team.Repos {
|
||||
access, err := models.AccessLevel(ctx.User, repo)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetTeamRepos", err)
|
||||
return
|
||||
}
|
||||
repos[i] = repo.APIFormat(access)
|
||||
}
|
||||
ctx.JSON(200, repos)
|
||||
}
|
||||
|
|
Reference in a new issue