Commit a81d5486 by Johannes Schill Committed by Torkel Ödegaard

Viewers with viewers_can_edit should be able to access /explore (#15787)

* fix: Viewers with viewers_can_edit should be able to access /explore #15773

* refactoring initial PR a bit to simplify function and reduce duplication
parent be8f60b0
...@@ -73,7 +73,7 @@ func (hs *HTTPServer) registerRoutes() { ...@@ -73,7 +73,7 @@ func (hs *HTTPServer) registerRoutes() {
r.Get("/dashboards/", reqSignedIn, hs.Index) r.Get("/dashboards/", reqSignedIn, hs.Index)
r.Get("/dashboards/*", reqSignedIn, hs.Index) r.Get("/dashboards/*", reqSignedIn, hs.Index)
r.Get("/explore", reqEditorRole, hs.Index) r.Get("/explore", reqSignedIn, middleware.EnsureEditorOrViewerCanEdit, hs.Index)
r.Get("/playlists/", reqSignedIn, hs.Index) r.Get("/playlists/", reqSignedIn, hs.Index)
r.Get("/playlists/*", reqSignedIn, hs.Index) r.Get("/playlists/*", reqSignedIn, hs.Index)
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"gopkg.in/macaron.v1" macaron "gopkg.in/macaron.v1"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
...@@ -52,6 +52,12 @@ func notAuthorized(c *m.ReqContext) { ...@@ -52,6 +52,12 @@ func notAuthorized(c *m.ReqContext) {
c.Redirect(setting.AppSubUrl + "/login") c.Redirect(setting.AppSubUrl + "/login")
} }
func EnsureEditorOrViewerCanEdit(c *m.ReqContext) {
if !c.SignedInUser.HasRole(m.ROLE_EDITOR) && !setting.ViewersCanEdit {
accessForbidden(c)
}
}
func RoleAuth(roles ...m.RoleType) macaron.Handler { func RoleAuth(roles ...m.RoleType) macaron.Handler {
return func(c *m.ReqContext) { return func(c *m.ReqContext) {
ok := false ok := false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment