Access Control: Move database-related models to enterprise (#32907)

* Move database-related models to enterprise

* Chore: use GetUserBuiltInRoles() method

* Rename permission to action
This commit is contained in:
Alexander Zobnin
2021-04-13 16:28:11 +03:00
committed by GitHub
parent bd74953f0d
commit 7ea58f9cf5
5 changed files with 29 additions and 48 deletions
@@ -9,19 +9,9 @@ import (
"github.com/grafana/grafana/pkg/services/accesscontrol"
)
const roleGrafanaAdmin = "Grafana Admin"
// Evaluate evaluates access to the given resource, using provided AccessControl instance
func Evaluate(ctx context.Context, ac accesscontrol.AccessControl, user *models.SignedInUser, permission string, scope ...string) (bool, error) {
roles := []string{string(user.OrgRole)}
for _, role := range user.OrgRole.Children() {
roles = append(roles, string(role))
}
if user.IsGrafanaAdmin {
roles = append(roles, roleGrafanaAdmin)
}
res, err := ac.GetUserPermissions(ctx, user, roles)
res, err := ac.GetUserPermissions(ctx, user)
if err != nil {
return false, err
}
@@ -61,7 +51,7 @@ func extractPermission(permissions []*accesscontrol.Permission, permission strin
if p == nil {
continue
}
if p.Permission == permission {
if p.Action == permission {
ok = true
scopes[p.Scope] = struct{}{}
}