AccessControl: Make the built-in role definitions public (#47525)

* AccessControl: Make the built-in role definitions public

* Add context to RegisterFixedRoles

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

* Making BuiltInRolesWithParents public to the AccessControl package

Co-authored-by: Jguer <joao.guerreiro@grafana.com>

Co-authored-by: Jguer <joao.guerreiro@grafana.com>
This commit is contained in:
Gabriel MABILLE
2022-04-12 09:53:43 +02:00
committed by GitHub
parent 0bf889e058
commit 8bd825e16c
7 changed files with 79 additions and 76 deletions

View File

@@ -5,6 +5,7 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/annotations"
)
@@ -82,6 +83,7 @@ func (r RoleDTO) Role() Role {
ID: r.ID,
OrgID: r.OrgID,
UID: r.UID,
Version: r.Version,
Name: r.Name,
DisplayName: r.DisplayName,
Group: r.Group,
@@ -244,6 +246,9 @@ type SetResourcePermissionCommand struct {
const (
GlobalOrgID = 0
FixedRolePrefix = "fixed:"
RoleGrafanaAdmin = "Grafana Admin"
GeneralFolderUID = "general"
// Permission actions
@@ -385,6 +390,17 @@ var (
ScopeAnnotationsTypeOrganization = ScopeAnnotationsProvider.GetResourceScopeType(annotations.Organization.String())
)
const RoleGrafanaAdmin = "Grafana Admin"
func BuiltInRolesWithParents(builtInRoles []string) map[string]struct{} {
res := map[string]struct{}{}
const FixedRolePrefix = "fixed:"
for _, br := range builtInRoles {
res[br] = struct{}{}
if br != RoleGrafanaAdmin {
for _, parent := range models.RoleType(br).Parents() {
res[string(parent)] = struct{}{}
}
}
}
return res
}