Auth: Fix grafana-auth-app menu not being displayed (#90882)

Auth: Fix grafana-auth-app menu not being displayed if user only has access to cloud access policies
This commit is contained in:
Jo
2024-07-24 15:10:19 +02:00
committed by GitHub
parent e5ff5e65df
commit 93a979d46d
3 changed files with 47 additions and 3 deletions
+40
View File
@@ -86,6 +86,7 @@ func (root *NavTreeRoot) AddSection(node *NavLink) {
root.Children = append(root.Children, node)
}
// RemoveSection removes a section from the root node. Does not recurse into children.
func (root *NavTreeRoot) RemoveSection(node *NavLink) {
var result []*NavLink
@@ -98,6 +99,26 @@ func (root *NavTreeRoot) RemoveSection(node *NavLink) {
root.Children = result
}
// RemoveSectionByID removes a section by ID from the root node and all its children
func (root *NavTreeRoot) RemoveSectionByID(id string) bool {
var result []*NavLink
for i, child := range root.Children {
if child.Id == id {
// Remove the node by slicing it out
result = append(root.Children[:i], root.Children[i+1:]...)
root.Children = result
return true
} else if len(child.Children) > 0 {
if removed := RemoveById(child, id); removed {
return true
}
}
}
return false
}
func (root *NavTreeRoot) FindById(id string) *NavLink {
return FindById(root.Children, id)
}
@@ -227,3 +248,22 @@ func FindByURL(nodes []*NavLink, url string) *NavLink {
return nil
}
func RemoveById(node *NavLink, id string) bool {
var result []*NavLink
for i, child := range node.Children {
if child.Id == id {
// Remove the node by slicing it out
result = append(node.Children[:i], node.Children[i+1:]...)
node.Children = result
return true
} else if len(child.Children) > 0 {
if removed := RemoveById(child, id); removed {
return true
}
}
}
return false
}