diff --git a/routers/api/v1/admin/org_team.go b/routers/api/v1/admin/org_team.go index 93af1ec42772e..716bd675fa414 100644 --- a/routers/api/v1/admin/org_team.go +++ b/routers/api/v1/admin/org_team.go @@ -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) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 11adfa5c5f77b..e63a644d014a7 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -344,6 +344,11 @@ func RegisterRoutes(m *macaron.Macaron) { m.Combo("").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit) m.Combo("/teams").Get(org.ListTeams) }, 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) @@ -369,6 +374,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)) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index f5b2e9dc55d67..2f51518875d84 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -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) +}