diff --git a/router/middleware/session/user.go b/router/middleware/session/user.go index 78f0a16bf..c1c0e09b4 100644 --- a/router/middleware/session/user.go +++ b/router/middleware/session/user.go @@ -85,6 +85,23 @@ func MustAdmin() gin.HandlerFunc { } } +func MustRepoAdmin() gin.HandlerFunc { + return func(c *gin.Context) { + user := User(c) + perm := Perm(c) + switch { + case user == nil: + c.String(401, "User not authorized") + c.Abort() + case perm.Admin == false: + c.String(403, "User not authorized") + c.Abort() + default: + c.Next() + } + } +} + func MustUser() gin.HandlerFunc { return func(c *gin.Context) { user := User(c) diff --git a/router/router.go b/router/router.go index 8dd1a3609..446b4d641 100644 --- a/router/router.go +++ b/router/router.go @@ -84,8 +84,8 @@ func Load(middleware ...gin.HandlerFunc) http.Handler { // requires push permissions repo.PATCH("", session.MustPush, server.PatchRepo) - repo.DELETE("", session.MustPush, server.DeleteRepo) - repo.POST("/chown", session.MustPush, server.ChownRepo) + repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo) + repo.POST("/chown", session.MustRepoAdmin(), server.ChownRepo) repo.POST("/builds/:number", session.MustPush, server.PostBuild) repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)