mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Access control: Build navigation links with access control (#33024)
* Build nav links with access control * Break up getNavTree (reduce cyclomatic complexity) * Fix tests * Use only ActionUsersRead permissions * Remove unused permissions definitions * Chore: remove unused fallbacks * Fix linter error
This commit is contained in:
@@ -17,6 +17,26 @@ type AccessControl interface {
|
||||
IsDisabled() bool
|
||||
}
|
||||
|
||||
func HasAccess(ac AccessControl, c *models.ReqContext) func(fallback func(*models.ReqContext) bool, permission string, scopes ...string) bool {
|
||||
return func(fallback func(*models.ReqContext) bool, permission string, scopes ...string) bool {
|
||||
if ac.IsDisabled() {
|
||||
return fallback(c)
|
||||
}
|
||||
|
||||
hasAccess, err := ac.Evaluate(c.Req.Context(), c.SignedInUser, permission, scopes...)
|
||||
if err != nil {
|
||||
c.Logger.Error("Error from access control system", "error", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return hasAccess
|
||||
}
|
||||
}
|
||||
|
||||
var ReqGrafanaAdmin = func(c *models.ReqContext) bool {
|
||||
return c.IsGrafanaAdmin
|
||||
}
|
||||
|
||||
func BuildPermissionsMap(permissions []*Permission) map[string]map[string]string {
|
||||
permissionsMap := make(map[string]map[string]string)
|
||||
for _, p := range permissions {
|
||||
|
||||
Reference in New Issue
Block a user