forked from NYANDEV/forgejo
added repository remove option to api
This commit is contained in:
parent
02d3b66265
commit
6fe868a4d5
2 changed files with 37 additions and 0 deletions
|
@ -226,6 +226,7 @@ func runWeb(ctx *cli.Context) {
|
|||
|
||||
m.Group("", func() {
|
||||
m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
|
||||
m.Delete("/:owner/:reponame", v1.RemoveRepo)
|
||||
}, middleware.ApiReqToken())
|
||||
|
||||
m.Group("/:username/:reponame", func() {
|
||||
|
|
|
@ -253,3 +253,39 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
|||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||
ctx.JSON(201, ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
func RemoveRepo(ctx *middleware.Context) {
|
||||
user, err := models.GetUserByName(ctx.Params(":owner"))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.HandleAPI(404, err)
|
||||
} else {
|
||||
ctx.JSON(500, &base.ApiJsonErr{"GetUserByName: " + err.Error(), base.DOC_URL})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.HandleAPI(404, err)
|
||||
} else {
|
||||
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) {
|
||||
ctx.HandleAPI(403, "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(user.Id, repo.ID); err != nil {
|
||||
log.Error(4, "DeleteRespository: %v:", err)
|
||||
ctx.HandleAPI(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Repository deleted: %s/%s", user.Name, repo.Name)
|
||||
ctx.Status(204)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue