2016-04-04 19:41:34 -04: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 (
|
2018-05-27 08:53:48 +08:00
|
|
|
"github.com/gogs/gogs/models"
|
|
|
|
|
"github.com/gogs/gogs/models/errors"
|
|
|
|
|
"github.com/gogs/gogs/pkg/context"
|
2016-04-04 19:41:34 -04:00
|
|
|
)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func GetRepositoryByParams(c *context.APIContext) *models.Repository {
|
|
|
|
|
repo, err := models.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
|
2016-04-04 19:41:34 -04:00
|
|
|
if err != nil {
|
2019-08-10 13:40:48 -07:00
|
|
|
c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
2016-04-04 19:41:34 -04:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return repo
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func AddTeamRepository(c *context.APIContext) {
|
|
|
|
|
repo := GetRepositoryByParams(c)
|
|
|
|
|
if c.Written() {
|
2016-04-04 19:41:34 -04:00
|
|
|
return
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
if err := c.Org.Team.AddRepository(repo); err != nil {
|
2019-08-10 13:40:48 -07:00
|
|
|
c.ServerError("AddRepository", err)
|
2016-04-04 19:41:34 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 13:40:48 -07:00
|
|
|
c.NoContent()
|
2016-04-04 19:41:34 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func RemoveTeamRepository(c *context.APIContext) {
|
|
|
|
|
repo := GetRepositoryByParams(c)
|
|
|
|
|
if c.Written() {
|
2016-04-04 19:41:34 -04:00
|
|
|
return
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
|
2019-08-10 13:40:48 -07:00
|
|
|
c.ServerError("RemoveRepository", err)
|
2016-04-04 19:41:34 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 13:40:48 -07:00
|
|
|
c.NoContent()
|
2016-04-04 19:41:34 -04:00
|
|
|
}
|