Add explicit vault view factories

This commit is contained in:
Joe Julian
2026-04-13 07:02:44 -07:00
parent 0ce25a9712
commit ea30775eb7
3 changed files with 288 additions and 13 deletions
+17 -9
View File
@@ -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
}