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 (
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
|
|
|
|
"gogs.io/gogs/internal/db"
|
2016-04-04 19:41:34 -04:00
|
|
|
)
|
|
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
func GetRepositoryByParams(c *context.APIContext) *db.Repository {
|
|
|
|
|
repo, err := db.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
|
2016-04-04 19:41:34 -04:00
|
|
|
if err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.NotFoundOrError(err, "get repository by name")
|
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 {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "add repository")
|
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 {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "remove repository")
|
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
|
|
|
}
|