mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
RBAC: remove redundant role name field from plugin role registrations (#58166)
* RBAC: Remove name from role registration * Inline accesscontrol service * test fix * use fmt Co-Authored-By: marefr <marcus.efraimsson@gmail.com> Co-authored-by: marefr <marcus.efraimsson@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pluginutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -34,14 +35,14 @@ func ValidatePluginRole(pluginID string, role ac.RoleDTO) error {
|
||||
return ValidatePluginPermissions(pluginID, role.Permissions)
|
||||
}
|
||||
|
||||
func ToRegistrations(pluginName string, regs []plugins.RoleRegistration) []ac.RoleRegistration {
|
||||
func ToRegistrations(pluginID, pluginName string, regs []plugins.RoleRegistration) []ac.RoleRegistration {
|
||||
res := make([]ac.RoleRegistration, 0, len(regs))
|
||||
for i := range regs {
|
||||
res = append(res, ac.RoleRegistration{
|
||||
Role: ac.RoleDTO{
|
||||
Version: 1,
|
||||
Name: regs[i].Role.Name,
|
||||
DisplayName: regs[i].Role.DisplayName,
|
||||
Name: roleName(pluginID, regs[i].Role.Name),
|
||||
DisplayName: regs[i].Role.Name,
|
||||
Description: regs[i].Role.Description,
|
||||
Group: pluginName,
|
||||
Permissions: toPermissions(regs[i].Role.Permissions),
|
||||
@@ -53,6 +54,10 @@ func ToRegistrations(pluginName string, regs []plugins.RoleRegistration) []ac.Ro
|
||||
return res
|
||||
}
|
||||
|
||||
func roleName(pluginID, roleName string) string {
|
||||
return fmt.Sprintf("%v%v:%v", ac.PluginRolePrefix, pluginID, strings.Replace(strings.ToLower(roleName), " ", "-", -1))
|
||||
}
|
||||
|
||||
func toPermissions(perms []plugins.Permission) []ac.Permission {
|
||||
res := make([]ac.Permission, 0, len(perms))
|
||||
for i := range perms {
|
||||
|
||||
Reference in New Issue
Block a user