summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/web.go1
-rw-r--r--routers/api/v1/repo.go36
2 files changed, 37 insertions, 0 deletions
diff --git a/cmd/web.go b/cmd/web.go
index ec0e4cd74f..0c0eea3f81 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -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() {
diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go
index d38a0b0ff2..9fd2f92a1a 100644
--- a/routers/api/v1/repo.go
+++ b/routers/api/v1/repo.go
@@ -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)
+}