Profile: Fixes profile preferences being accessible when anonymous access was enabled (#31516)

* Profile: Fixes profile preferences page being available when anonymous access was enabled

* Minor change

* Renamed property
This commit is contained in:
Torkel Ödegaard
2021-02-27 18:04:28 +01:00
committed by GitHub
parent e9d2592481
commit 7428668835
5 changed files with 27 additions and 12 deletions

View File

@ -16,6 +16,7 @@ import (
type AuthOptions struct {
ReqGrafanaAdmin bool
ReqSignedIn bool
ReqNoAnonynmous bool
}
func accessForbidden(c *models.ReqContext) {
@ -75,6 +76,7 @@ func RoleAuth(roles ...models.RoleType) macaron.Handler {
func Auth(options *AuthOptions) macaron.Handler {
return func(c *models.ReqContext) {
forceLogin := false
if c.AllowAnonymous {
forceLoginParam, err := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin"))
if err == nil {
@ -89,7 +91,9 @@ func Auth(options *AuthOptions) macaron.Handler {
}
}
}
requireLogin := !c.AllowAnonymous || forceLogin
requireLogin := !c.AllowAnonymous || forceLogin || options.ReqNoAnonynmous
if !c.IsSignedIn && options.ReqSignedIn && requireLogin {
notAuthorized(c)
return