Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add folder hierarchy scaffolding to avux export/import (#1695)

Leendert de Borst164dac6ea6ff
diff --git a/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs b/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs
index c94a73a22..4f426c125 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs
@@ -34,7 +34,7 @@ public static class ItemCsvService
var record = new ItemCsvRecord
{
ServiceName = item.Name ?? string.Empty,
- FolderPath = item.Folder?.Name ?? string.Empty,
+ FolderPath = BuildFolderPath(item.Folder),
ServiceUrl = GetFieldValue(item, FieldKey.LoginUrl),
Username = GetFieldValue(item, FieldKey.LoginUsername),
CurrentPassword = GetFieldValue(item, FieldKey.LoginPassword),
@@ -123,6 +123,31 @@ public static class ItemCsvService
return credentials;
}
+ /// <summary>
+ /// Builds the full hierarchical path for a folder by traversing parent folders.
+ /// </summary>
+ /// <param name="folder">The folder to build the path for.</param>
+ /// <returns>The full hierarchical path (e.g., "Work/Projects/Active"), or empty string if null.</returns>
+ private static string BuildFolderPath(Folder? folder)
+ {
+ if (folder == null)
+ {
+ return string.Empty;
+ }
+
+ var pathParts = new List<string>();
+ var currentFolder = folder;
+
+ // Traverse up the folder hierarchy
+ while (currentFolder != null)
+ {
+ pathParts.Insert(0, currentFolder.Name);
+ currentFolder = currentFolder.ParentFolder;
+ }
+
+ return string.Join("/", pathParts);
+ }
+
/// <summary>
/// Gets a field value from an item by field key.
/// </summary>
diff --git a/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs b/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs
index 0a21baa82..ff807be08 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs
@@ -132,7 +132,7 @@ public static class VaultImportService
Dictionary<Guid, byte[]> logoDataById)
{
var credentials = new List<ImportedCredential>();
- var folderMap = manifest.Folders.ToDictionary(f => f.Id, f => f.Name);
+ var folderMap = BuildFolderPathMap(manifest.Folders);
foreach (var item in manifest.Items)
{
@@ -150,9 +150,9 @@ public static class VaultImportService
}
// Get folder path
- if (item.FolderId.HasValue && folderMap.TryGetValue(item.FolderId.Value, out var folderName))
+ if (item.FolderId.HasValue && folderMap.TryGetValue(item.FolderId.Value, out var folderPath))
{
- credential.FolderPath = folderName;
+ credential.FolderPath = folderPath;
}
// Extract field values
@@ -183,6 +183,54 @@ public static class VaultImportService
return credentials;
}
+ /// <summary>
+ /// Builds a map of folder IDs to their full hierarchical paths.
+ /// </summary>
+ /// <param name="folders">The list of folders from the manifest.</param>
+ /// <returns>A dictionary mapping folder IDs to full paths (e.g., "Work/Projects/Active").</returns>
+ private static Dictionary<Guid, string> BuildFolderPathMap(List<AvuxFolder> folders)
+ {
+ var folderMap = new Dictionary<Guid, string>();
+ var folderById = folders.ToDictionary(f => f.Id);
+
+ foreach (var folder in folders)
+ {
+ var path = BuildFolderPath(folder, folderById);
+ folderMap[folder.Id] = path;
+ }
+
+ return folderMap;
+ }
+
+ /// <summary>
+ /// Recursively builds the full path for a folder by traversing parent folders.
+ /// </summary>
+ /// <param name="folder">The folder to build the path for.</param>
+ /// <param name="folderById">Dictionary of all folders by ID.</param>
+ /// <returns>The full hierarchical path (e.g., "Work/Projects/Active").</returns>
+ private static string BuildFolderPath(AvuxFolder folder, Dictionary<Guid, AvuxFolder> folderById)
+ {
+ var pathParts = new List<string>();
+ var currentFolder = folder;
+
+ // Traverse up the folder hierarchy
+ while (currentFolder != null)
+ {
+ pathParts.Insert(0, currentFolder.Name);
+
+ if (currentFolder.ParentFolderId.HasValue && folderById.TryGetValue(currentFolder.ParentFolderId.Value, out var parentFolder))
+ {
+ currentFolder = parentFolder;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return string.Join("/", pathParts);
+ }
+
/// <summary>
/// Extracts field values from the AvuxItem and populates the ImportedCredential.
/// </summary>