Access control: Fix searching permissions from cache (#87489)

* Fix searching permissions from cache

* Write permissions to cache
This commit is contained in:
Alexander Zobnin
2024-05-08 16:08:21 +02:00
committed by GitHub
parent 41b29ff93c
commit d1c582815a
3 changed files with 37 additions and 21 deletions
+26
View File
@@ -0,0 +1,26 @@
package accesscontrol
import (
"fmt"
"strings"
"github.com/grafana/grafana/pkg/services/auth/identity"
)
func GetPermissionCacheKey(user identity.Requester) string {
return fmt.Sprintf("rbac-permissions-%s", user.GetCacheKey())
}
func GetUserDirectPermissionCacheKey(user identity.Requester) string {
return fmt.Sprintf("rbac-permissions-direct-%s", user.GetCacheKey())
}
func GetBasicRolePermissionCacheKey(role string, orgID int64) string {
roleKey := strings.Replace(role, " ", "_", -1)
roleKey = strings.ToLower(roleKey)
return fmt.Sprintf("rbac-permissions-basic-role-%d-%s", orgID, roleKey)
}
func GetTeamPermissionCacheKey(teamID int64, orgID int64) string {
return fmt.Sprintf("rbac-permissions-team-%d-%d", orgID, teamID)
}