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