Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update exports to only contain personal manifest entries (#2159)
Leendert de Borsta6a1a6e1d058
diff --git a/apps/mobile-app/app/(tabs)/settings/import-export.tsx b/apps/mobile-app/app/(tabs)/settings/import-export.tsxindex eccd669c8..44cf93755 100644--- a/apps/mobile-app/app/(tabs)/settings/import-export.tsx+++ b/apps/mobile-app/app/(tabs)/settings/import-export.tsx@@ -308,8 +308,12 @@ export default function ImportExportScreen(): React.ReactNode {try {const dateStr = new Date().toISOString().split('T')[0];- // Export as CSV- const items = await dbContext.sqliteClient?.items.getAll() ?? [];+ // Export as CSV. Only personal manifest entries are exported.+ const personalManifestId = await dbContext.sqliteClient?.getPersonalManifestId();+ if (!personalManifestId) {+ throw new Error('No personal manifest id is recorded; the vault has not been loaded yet.');+ }+ const items = await dbContext.sqliteClient?.items.getAllInManifest(personalManifestId) ?? [];const csvContent = await itemsToCsv(items);const filename = `aliasvault-export-${dateStr}.csv`;diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razorindex 50a820d8b..0e8a459d3 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor@@ -298,7 +298,7 @@{try{- var items = await ItemService.LoadAllAsync();+ var items = await ItemService.LoadAllInManifestAsync(DbService.PersonalManifestId);var csvBytes = ItemCsvService.ExportItemsToCsv(items);@@ -365,16 +365,17 @@}/// <summary>- /// Generates .avux bytes from the current vault data.- /// This is used by both .avux export (unencrypted) and .avex export (encrypted).+ /// Generates .avux bytes from the personal manifest. Note: shared manifests are not included in the export+ /// on purpose, a separate export operation will be required for shared manifests./// </summary>private async Task<byte[]> GenerateAvuxBytesAsync(){var context = await DbService.GetDbContextAsync();+ var manifestId = DbService.PersonalManifestId;// Load all vault entities with their related datavar items = await context.Items- .Where(i => !i.IsDeleted && i.DeletedAt == null)+ .Where(i => i.ManifestId == manifestId && !i.IsDeleted && i.DeletedAt == null).Include(i => i.FieldValues).Include(i => i.Attachments).Include(i => i.TotpCodes)@@ -382,19 +383,19 @@.ToListAsync();var folders = await context.Folders- .Where(f => !f.IsDeleted)+ .Where(f => f.ManifestId == manifestId && !f.IsDeleted).ToListAsync();var tags = await context.Tags- .Where(t => !t.IsDeleted)+ .Where(t => t.ManifestId == manifestId && !t.IsDeleted).ToListAsync();var itemTags = await context.ItemTags- .Where(it => !it.IsDeleted)+ .Where(it => it.ManifestId == manifestId && !it.IsDeleted).ToListAsync();var fieldDefinitions = await context.FieldDefinitions- .Where(fd => !fd.IsDeleted)+ .Where(fd => fd.ManifestId == manifestId && !fd.IsDeleted).ToListAsync();// Get unique logo IDs from items@@ -404,9 +405,9 @@.Distinct().ToList();- // Load logos used by items+ // Load logos used by items; the manifest predicate keeps a same-id logo of another manifest outvar logos = await context.Logos- .Where(l => !l.IsDeleted && logoIds.Contains(l.Id))+ .Where(l => l.ManifestId == manifestId && !l.IsDeleted && logoIds.Contains(l.Id)).ToListAsync();var username = await GetUsernameAsync();diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.csindex 23b75828f..7ac691d51 100644--- a/apps/server/AliasVault.Client/Services/ItemService.cs+++ b/apps/server/AliasVault.Client/Services/ItemService.cs@@ -490,22 +490,17 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf/// <returns>List of all items.</returns>public async Task<List<Item>> LoadAllAsync(){- var context = await dbService.GetDbContextAsync();-- var items = await context.Items- .Include(x => x.FieldValues.Where(fv => !fv.IsDeleted))- .ThenInclude(fv => fv.FieldDefinition)- .Include(x => x.Logo)- .Include(x => x.Attachments.Where(a => !a.IsDeleted))- .Include(x => x.TotpCodes.Where(t => !t.IsDeleted))- .Include(x => x.Passkeys.Where(p => !p.IsDeleted))- .AsSplitQuery()- .Where(x => !x.IsDeleted)- .Where(x => x.DeletedAt == null) // Exclude items in trash- .Where(x => x.ArchivedAt == null) // Exclude archived items- .ToListAsync();+ return await LoadAllAsync(manifestId: null);+ }- return items;+ /// <summary>+ /// Load all active items of one manifest.+ /// </summary>+ /// <param name="manifestId">The manifest to read.</param>+ /// <returns>List of the manifest's active items.</returns>+ public async Task<List<Item>> LoadAllInManifestAsync(Guid manifestId)+ {+ return await LoadAllAsync(manifestId);}/// <summary>@@ -1865,4 +1860,33 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Confreturn await dbService.SaveDatabaseAsync();}++ /// <summary>+ /// Load all active items, optionally restricted to one manifest.+ /// </summary>+ /// <param name="manifestId">The manifest to read, or null for every manifest in the vault.</param>+ /// <returns>List of active items.</returns>+ private async Task<List<Item>> LoadAllAsync(Guid? manifestId)+ {+ var context = await dbService.GetDbContextAsync();++ var query = context.Items+ .Include(x => x.FieldValues.Where(fv => !fv.IsDeleted))+ .ThenInclude(fv => fv.FieldDefinition)+ .Include(x => x.Logo)+ .Include(x => x.Attachments.Where(a => !a.IsDeleted))+ .Include(x => x.TotpCodes.Where(t => !t.IsDeleted))+ .Include(x => x.Passkeys.Where(p => !p.IsDeleted))+ .AsSplitQuery()+ .Where(x => !x.IsDeleted)+ .Where(x => x.DeletedAt == null) // Exclude items in trash+ .Where(x => x.ArchivedAt == null); // Exclude archived items++ if (manifestId is not null)+ {+ query = query.Where(x => x.ManifestId == manifestId.Value);+ }++ return await query.ToListAsync();+ }}diff --git a/core/client/src/database/__tests__/SharedManifestRendering.test.ts b/core/client/src/database/__tests__/SharedManifestRendering.test.tsindex 2eb049431..33e132d6f 100644--- a/core/client/src/database/__tests__/SharedManifestRendering.test.ts+++ b/core/client/src/database/__tests__/SharedManifestRendering.test.ts@@ -88,4 +88,12 @@ describe('a shared manifest rendered as a folder', () => {it('refuses to delete the folder', async () => {await expect(client.folders.delete(SHARED_ROOT)).rejects.toThrow();});++ it('is left out of a personal export, which reads one manifest', async () => {+ await client.items.create(draftItem('Netflix', SHARED, SHARED));+ await client.items.create(draftItem('Mine', PERSONAL, null));++ expect(client.items.getAll().map(item => item.Name).sort()).toEqual(['Mine', 'Netflix']);+ expect(client.items.getAllInManifest(PERSONAL).map(item => item.Name)).toEqual(['Mine']);+ });});diff --git a/core/client/src/database/queries/ItemQueries.ts b/core/client/src/database/queries/ItemQueries.tsindex 51f5b2dcb..b9b758187 100644--- a/core/client/src/database/queries/ItemQueries.ts+++ b/core/client/src/database/queries/ItemQueries.ts@@ -41,6 +41,14 @@ export class ItemQueries {WHERE i.IsDeleted = 0 AND i.DeletedAt IS NULL AND i.ArchivedAt IS NULLORDER BY i.CreatedAt DESC`;+ /**+ * Get the active items of one manifest.+ */+ public static readonly GET_ALL_ACTIVE_IN_MANIFEST = `+ ${ItemQueries.BASE_SELECT}+ WHERE i.IsDeleted = 0 AND i.DeletedAt IS NULL AND i.ArchivedAt IS NULL AND i.ManifestId = ?+ ORDER BY i.CreatedAt DESC`;+/*** Get the active items of one folder, matched on the folder's whole key.*/diff --git a/core/client/src/database/repositories/ItemRepository.ts b/core/client/src/database/repositories/ItemRepository.tsindex cfbad9521..43119b168 100644--- a/core/client/src/database/repositories/ItemRepository.ts+++ b/core/client/src/database/repositories/ItemRepository.ts@@ -97,6 +97,16 @@ export class ItemRepository extends BaseRepository {return yield* this.hydrateItems(itemRows);}+ /**+ * Fetch the active items of one manifest with their dynamic fields and tags.+ * @param manifestId - The manifest to read+ * @returns Array of Item objects+ */+ public *getAllInManifest(manifestId: string): DbOp<Item[]> {+ const itemRows = yield* this.selectItemRows(ItemQueries.GET_ALL_ACTIVE_IN_MANIFEST, [manifestId]);+ return yield* this.hydrateItems(itemRows);+ }+/*** Fetch the active items of one folder with their dynamic fields and tags.* @param folder - The folder to read