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:
@@ -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{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user