Add explicit vault view factories
This commit is contained in:
@@ -5,19 +5,27 @@ import "git.julianfamily.org/keepassgo/internal/vault"
|
||||
// HiddenRoot returns the single synthetic top-level vault group that should be
|
||||
// treated as an internal storage root rather than as a user-visible group.
|
||||
func HiddenRoot(model vault.Model) string {
|
||||
if len(model.EntriesInPath(nil)) != 0 {
|
||||
if !hasGroup(model.Groups, []string{KeepassRoot}) {
|
||||
return ""
|
||||
}
|
||||
groups := model.ChildGroups(nil)
|
||||
roots := make([]string, 0, len(groups))
|
||||
return KeepassRoot
|
||||
}
|
||||
|
||||
func hasGroup(groups [][]string, path []string) bool {
|
||||
for _, group := range groups {
|
||||
if group == "Recycle Bin" {
|
||||
if len(group) != len(path) {
|
||||
continue
|
||||
}
|
||||
roots = append(roots, group)
|
||||
match := true
|
||||
for i := range group {
|
||||
if group[i] != path[i] {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if len(roots) != 1 {
|
||||
return ""
|
||||
}
|
||||
return roots[0]
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user