Fontend handling of account role to hide user actions and links that the user does not have access to
This commit is contained in:
+3
-1
@@ -46,6 +46,8 @@ secret_key = SW2YcwTIb9zpOOhoPsMm
|
|||||||
login_remember_days = 7
|
login_remember_days = 7
|
||||||
cookie_username = grafana_user
|
cookie_username = grafana_user
|
||||||
cookie_remember_name = grafana_remember
|
cookie_remember_name = grafana_remember
|
||||||
|
; disable user signup / registration
|
||||||
|
disable_user_signup = false
|
||||||
|
|
||||||
[account.single]
|
[account.single]
|
||||||
; Enable this feature to auto assign new users to a single account, suitable for NON multi tenant setups
|
; Enable this feature to auto assign new users to a single account, suitable for NON multi tenant setups
|
||||||
@@ -57,7 +59,7 @@ default_role = Editor
|
|||||||
|
|
||||||
[auth.anonymous]
|
[auth.anonymous]
|
||||||
; enable anonymous access
|
; enable anonymous access
|
||||||
enabled = false
|
enabled = true
|
||||||
; specify account name that should be used for unauthenticated users
|
; specify account name that should be used for unauthenticated users
|
||||||
account_name = main
|
account_name = main
|
||||||
; specify role for unauthenticated users
|
; specify role for unauthenticated users
|
||||||
|
|||||||
+1
-1
Submodule grafana updated: 017eab8dcd...c75e669204
+10
-13
@@ -31,7 +31,7 @@ func Register(r *macaron.Macaron) {
|
|||||||
r.Get("/account/users/", reqSignedIn, Index)
|
r.Get("/account/users/", reqSignedIn, Index)
|
||||||
r.Get("/account/apikeys/", reqSignedIn, Index)
|
r.Get("/account/apikeys/", reqSignedIn, Index)
|
||||||
r.Get("/account/import/", reqSignedIn, Index)
|
r.Get("/account/import/", reqSignedIn, Index)
|
||||||
r.Get("/admin/users", reqSignedIn, Index)
|
r.Get("/admin/users", reqGrafanaAdmin, Index)
|
||||||
r.Get("/dashboard/*", reqSignedIn, Index)
|
r.Get("/dashboard/*", reqSignedIn, Index)
|
||||||
|
|
||||||
// sign up
|
// sign up
|
||||||
@@ -104,18 +104,15 @@ func setIndexViewData(c *middleware.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUser := &dtos.CurrentUser{}
|
currentUser := &dtos.CurrentUser{
|
||||||
|
IsSignedIn: c.IsSignedIn,
|
||||||
if c.IsSignedIn {
|
Login: c.Login,
|
||||||
currentUser = &dtos.CurrentUser{
|
Email: c.Email,
|
||||||
Login: c.Login,
|
Name: c.Name,
|
||||||
Email: c.Email,
|
AccountName: c.AccountName,
|
||||||
Name: c.Name,
|
AccountRole: c.AccountRole,
|
||||||
UsingAccountName: c.AccountName,
|
GravatarUrl: dtos.GetGravatarUrl(c.Email),
|
||||||
GravatarUrl: dtos.GetGravatarUrl(c.Email),
|
IsGrafanaAdmin: c.IsGrafanaAdmin,
|
||||||
IsGrafanaAdmin: c.IsGrafanaAdmin,
|
|
||||||
Role: c.AccountRole,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["User"] = currentUser
|
c.Data["User"] = currentUser
|
||||||
|
|||||||
@@ -15,13 +15,14 @@ type LoginCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CurrentUser struct {
|
type CurrentUser struct {
|
||||||
Login string `json:"login"`
|
IsSignedIn bool `json:"isSignedIn"`
|
||||||
Email string `json:"email"`
|
Login string `json:"login"`
|
||||||
Role m.RoleType `json:"role"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
UsingAccountName string `json:"usingAccountName"`
|
AccountRole m.RoleType `json:"accountRole"`
|
||||||
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
AccountName string `json:"acountName"`
|
||||||
GravatarUrl string `json:"gravatarUrl"`
|
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
||||||
|
GravatarUrl string `json:"gravatarUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataSource struct {
|
type DataSource struct {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ func RoleAuth(roles ...m.RoleType) macaron.Handler {
|
|||||||
func Auth(options *AuthOptions) macaron.Handler {
|
func Auth(options *AuthOptions) macaron.Handler {
|
||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
if !c.IsGrafanaAdmin && options.ReqGrafanaAdmin {
|
if !c.IsGrafanaAdmin && options.ReqGrafanaAdmin {
|
||||||
|
c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+c.Req.RequestURI), 0, setting.AppSubUrl+"/")
|
||||||
authDenied(c)
|
authDenied(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user