Share hidden vault root logic across UI and API
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package vaultview
|
||||
|
||||
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 {
|
||||
return ""
|
||||
}
|
||||
groups := model.ChildGroups(nil)
|
||||
roots := make([]string, 0, len(groups))
|
||||
for _, group := range groups {
|
||||
if group == "Recycle Bin" {
|
||||
continue
|
||||
}
|
||||
roots = append(roots, group)
|
||||
}
|
||||
if len(roots) != 1 {
|
||||
return ""
|
||||
}
|
||||
return roots[0]
|
||||
}
|
||||
Reference in New Issue
Block a user