2016-04-04 17:41:34 -06:00
|
|
|
// 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 (
|
2016-11-10 09:24:48 -07:00
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2016-04-04 17:41:34 -06:00
|
|
|
)
|
|
|
|
|
2016-11-24 00:04:31 -07:00
|
|
|
// GetRepositoryByParams api for getting repository by orgnizition ID and repo name
|
2016-04-04 17:41:34 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-11-24 00:04:31 -07:00
|
|
|
// AddTeamRepository api for adding a repository to a team
|
2016-04-04 17:41:34 -06:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-11-24 00:04:31 -07:00
|
|
|
// RemoveTeamRepository api for removing a repository from a team
|
2016-04-04 17:41:34 -06:00
|
|
|
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)
|
|
|
|
}
|