Role checking when saving dashboard, making sure that the user has owner or editor role

This commit is contained in:
Torkel Ödegaard
2015-01-16 15:28:44 +01:00
parent 22156fe309
commit 3912ed5023
317 changed files with 8218 additions and 206556 deletions
+2 -1
View File
@@ -13,6 +13,7 @@ import (
func Register(r *macaron.Macaron) {
reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true})
reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_OWNER)
bind := binding.Bind
// not logged in views
@@ -63,7 +64,7 @@ func Register(r *macaron.Macaron) {
// Dashboard
r.Group("/dashboard", func() {
r.Combo("/:slug").Get(GetDashboard).Delete(DeleteDashboard)
r.Post("/", bind(m.SaveDashboardCommand{}), PostDashboard)
r.Post("/", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
})
// Search
r.Get("/search/", Search)
+15
View File
@@ -60,6 +60,21 @@ func authDenied(c *Context) {
c.Redirect(setting.AppSubUrl + "/login")
}
func RoleAuth(roles ...m.RoleType) macaron.Handler {
return func(c *Context) {
ok := false
for _, role := range roles {
if role == c.UserRole {
ok = true
break
}
}
if !ok {
authDenied(c)
}
}
}
func Auth(options *AuthOptions) macaron.Handler {
return func(c *Context) {
+1
View File
@@ -14,6 +14,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
)