diff --git a/internal/route/api/v1/api.go b/internal/route/api/v1/api.go index 2bc0223b0..6f10bf9ce 100644 --- a/internal/route/api/v1/api.go +++ b/internal/route/api/v1/api.go @@ -144,7 +144,7 @@ func reqRepoWriter() macaron.Handler { } } -// reqRepoWriter makes sure the context user has at least admin access to the repository. +// reqRepoAdmin makes sure the context user has at least admin access to the repository. func reqRepoAdmin() macaron.Handler { return func(c *context.Context) { if !c.Repo.IsAdmin() { @@ -154,6 +154,16 @@ func reqRepoAdmin() macaron.Handler { } } +// reqRepoOwner makes sure the context user has owner access to the repository. +func reqRepoOwner() macaron.Handler { + return func(c *context.Context) { + if !c.Repo.IsOwner() { + c.Status(http.StatusForbidden) + return + } + } +} + func mustEnableIssues(c *context.APIContext) { if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker { c.NotFound() @@ -247,7 +257,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/repos", func() { m.Post("/migrate", bind(form.MigrateRepo{}), repo.Migrate) - m.Delete("/:username/:reponame", repoAssignment(), repo.Delete) + m.Delete("/:username/:reponame", repoAssignment(), reqRepoOwner(), repo.Delete) m.Group("/:username/:reponame", func() { m.Group("/hooks", func() {