mirror of
https://github.com/go-gitea/gitea
synced 2024-11-16 15:01:07 +01:00
api/admin: add/remove organization team repository
This commit is contained in:
parent
d9900e4dbc
commit
d27ca649c7
2 changed files with 74 additions and 18 deletions
49
routers/api/v1/admin/org_repo.go
Normal file
49
routers/api/v1/admin/org_repo.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// 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 admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
|
||||||
|
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
|
||||||
|
if err != nil {
|
||||||
|
if models.IsErrRepoNotExist(err) {
|
||||||
|
ctx.Status(404)
|
||||||
|
} else {
|
||||||
|
ctx.Error(500, "GetRepositoryByName", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddTeamRepository(ctx *context.APIContext) {
|
||||||
|
repo := GetRepositoryByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := ctx.Org.Team.AddRepository(repo); err != nil {
|
||||||
|
ctx.Error(500, "AddRepository", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Status(204)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveTeamRepository(ctx *context.APIContext) {
|
||||||
|
repo := GetRepositoryByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
|
||||||
|
ctx.Error(500, "RemoveRepository", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Status(204)
|
||||||
|
}
|
|
@ -112,24 +112,29 @@ func ReqAdmin() macaron.Handler {
|
||||||
|
|
||||||
func OrgAssignment(args ...bool) macaron.Handler {
|
func OrgAssignment(args ...bool) macaron.Handler {
|
||||||
var (
|
var (
|
||||||
|
assignOrg bool
|
||||||
assignTeam bool
|
assignTeam bool
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
assignTeam = args[0]
|
assignOrg = args[0]
|
||||||
|
}
|
||||||
|
if len(args) > 1 {
|
||||||
|
assignTeam = args[1]
|
||||||
}
|
}
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
org, err := models.GetUserByName(ctx.Params(":orgname"))
|
ctx.Org = new(context.APIOrganization)
|
||||||
if err != nil {
|
|
||||||
if models.IsErrUserNotExist(err) {
|
var err error
|
||||||
ctx.Status(404)
|
if assignOrg {
|
||||||
} else {
|
ctx.Org.Organization, err = models.GetUserByName(ctx.Params(":orgname"))
|
||||||
ctx.Error(500, "GetUserByName", err)
|
if err != nil {
|
||||||
|
if models.IsErrUserNotExist(err) {
|
||||||
|
ctx.Status(404)
|
||||||
|
} else {
|
||||||
|
ctx.Error(500, "GetUserByName", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.Org = &context.APIOrganization{
|
|
||||||
Organization: org,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if assignTeam {
|
if assignTeam {
|
||||||
|
@ -244,7 +249,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Group("/orgs/:orgname", func() {
|
m.Group("/orgs/:orgname", func() {
|
||||||
m.Combo("").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
|
m.Combo("").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit)
|
||||||
m.Combo("/teams").Get(org.ListTeams)
|
m.Combo("/teams").Get(org.ListTeams)
|
||||||
}, OrgAssignment())
|
}, OrgAssignment(true))
|
||||||
|
|
||||||
m.Any("/*", func(ctx *context.Context) {
|
m.Any("/*", func(ctx *context.Context) {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
|
@ -265,13 +270,15 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
|
|
||||||
m.Group("/orgs/:orgname", func() {
|
m.Group("/orgs/:orgname", func() {
|
||||||
m.Group("/teams", func() {
|
m.Group("/teams", func() {
|
||||||
m.Post("", OrgAssignment(), bind(api.CreateTeamOption{}), admin.CreateTeam)
|
m.Post("", OrgAssignment(true), bind(api.CreateTeamOption{}), admin.CreateTeam)
|
||||||
|
|
||||||
m.Group("/:teamid", func() {
|
|
||||||
m.Combo("/memberships/:username").Put(admin.AddTeamMember).Delete(admin.RemoveTeamMember)
|
|
||||||
}, OrgAssignment(true))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
m.Group("/teams", func() {
|
||||||
|
m.Group("/:teamid", func() {
|
||||||
|
m.Combo("/members/:username").Put(admin.AddTeamMember).Delete(admin.RemoveTeamMember)
|
||||||
|
m.Combo("/repos/:reponame").Put(admin.AddTeamRepository).Delete(admin.RemoveTeamRepository)
|
||||||
|
}, OrgAssignment(false, true))
|
||||||
|
})
|
||||||
}, ReqAdmin())
|
}, ReqAdmin())
|
||||||
}, context.APIContexter())
|
}, context.APIContexter())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue