summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorSteven Oud <soud@protonmail.com>2015-10-04 17:09:16 +0200
committerSteven Oud <soud@protonmail.com>2015-10-04 23:29:23 +0200
commit6fe868a4d512adf3d4cf652a777c0c16521fbe5c (patch)
treeadbcc68deb1056a23f40d049e4192c3248fbd579 /routers/api
parent02d3b662654d1627ad510b7b330c016e97a7d1af (diff)
downloadgitea-6fe868a4d512adf3d4cf652a777c0c16521fbe5c.tar.gz
gitea-6fe868a4d512adf3d4cf652a777c0c16521fbe5c.zip
added repository remove option to api
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo.go36
1 files changed, 36 insertions, 0 deletions
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)
+}