Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak attachment delete and is deleted checks (#1473)
Leendert de Borst198b3893456e
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/AttachmentUploader.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/AttachmentUploader.tsxindex b0ab5ca71..a61155fb8 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/AttachmentUploader.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/AttachmentUploader.tsx@@ -108,7 +108,6 @@ const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({{activeAttachments.length > 0 && (<div>- <h4 className="mb-2 text-md font-medium text-gray-900 dark:text-white">{t('attachmentUploader.currentAttachments')}</h4><div className="space-y-2">{activeAttachments.map(attachment => (<divdiff --git a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts b/apps/browser-extension/src/utils/db/repositories/ItemRepository.tsindex 664a06b2e..4afdfe9fc 100644--- a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts+++ b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts@@ -848,6 +848,20 @@ export class ItemRepository extends BaseRepository {originalIds: string[],currentDateTime: string): void {+ // Track which original attachments are still present+ const currentAttachmentIds = new Set(attachments.map(a => a.Id));++ // Soft-delete any original attachments that are no longer in the list+ for (const originalId of originalIds) {+ if (!currentAttachmentIds.has(originalId)) {+ this.client.executeUpdate(+ `UPDATE Attachments SET IsDeleted = 1, UpdatedAt = ? WHERE Id = ?`,+ [currentDateTime, originalId]+ );+ }+ }++ // Process current attachmentsfor (const attachment of attachments) {const wasOriginal = originalIds.includes(attachment.Id);diff --git a/apps/mobile-app/components/items/details/AttachmentUploader.tsx b/apps/mobile-app/components/items/details/AttachmentUploader.tsxindex 1fe740872..3ee13381e 100644--- a/apps/mobile-app/components/items/details/AttachmentUploader.tsx+++ b/apps/mobile-app/components/items/details/AttachmentUploader.tsx@@ -5,7 +5,6 @@ import React, { useState } from 'react';import { useTranslation } from 'react-i18next';import { View, StyleSheet, TouchableOpacity } from 'react-native';-import { ConfirmDialog } from '@/components/common/ConfirmDialog';import { ThemedText } from '@/components/themed/ThemedText';import { ThemedView } from '@/components/themed/ThemedView';import { useColors } from '@/hooks/useColorScheme';@@ -18,6 +17,8 @@ type AttachmentUploaderProps = {/*** This component allows uploading and managing attachments for a credential.+ * Deletion is pending until the item is saved - attachments are removed from the list+ * immediately but only persisted when the parent form saves.*/export const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({attachments,@@ -26,7 +27,6 @@ export const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({const { t } = useTranslation();const colors = useColors();const [statusMessage, setStatusMessage] = useState<string>('');- const [attachmentToDelete, setAttachmentToDelete] = useState<Attachment | null>(null);/*** Handles file selection and upload.@@ -112,36 +112,12 @@ export const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({};/**- * Initiates the delete process for an attachment.+ * Deletes an attachment immediately from the list (pending save).+ * The actual database deletion happens when the parent item is saved.*/- const initiateDeleteAttachment = (attachment: Attachment): void => {- setAttachmentToDelete(attachment);- };-- /**- * Confirms and deletes an attachment.- */- const confirmDeleteAttachment = (): void => {- if (!attachmentToDelete) return;-- try {- const updatedAttachments = [...attachments];-- // Remove the attachment from the list- const index = updatedAttachments.findIndex(a => a.Id === attachmentToDelete.Id);- if (index !== -1) {- updatedAttachments.splice(index, 1);- }-- onAttachmentsChange(updatedAttachments);- setStatusMessage('');- } catch (error) {- console.error('Error deleting attachment:', error);- setStatusMessage(t('items.attachments.errorDeleting'));- setTimeout(() => setStatusMessage(''), 3000);- }-- setAttachmentToDelete(null);+ const deleteAttachment = (attachmentToDelete: Attachment): void => {+ const updatedAttachments = attachments.filter(a => a.Id !== attachmentToDelete.Id);+ onAttachmentsChange(updatedAttachments);};const activeAttachments = attachments.filter(a => !a.IsDeleted);@@ -218,7 +194,7 @@ export const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({</View><TouchableOpacitystyle={styles.deleteButton}- onPress={() => initiateDeleteAttachment(attachment)}+ onPress={() => deleteAttachment(attachment)}><ThemedText style={styles.deleteButtonText}>{t('items.deleteAttachment')}@@ -235,25 +211,6 @@ export const AttachmentUploader: React.FC<AttachmentUploaderProps> = ({><Ionicons name="add" size={24} color={colors.background} /></TouchableOpacity>-- <ConfirmDialog- isVisible={attachmentToDelete !== null}- title={t('items.attachments.deleteTitle')}- message={t('items.attachments.deleteConfirm', { filename: attachmentToDelete?.Filename })}- buttons={[- {- text: t('common.cancel'),- style: 'cancel',- onPress: (): void => setAttachmentToDelete(null),- },- {- text: t('common.delete'),- style: 'destructive',- onPress: confirmDeleteAttachment,- },- ]}- onClose={(): void => setAttachmentToDelete(null)}- /></ThemedView>);-};\ No newline at end of file+};diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor b/apps/server/AliasVault.Client/Main/Pages/Items/View.razorindex 82d1e3e08..8262909a8 100644--- a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Items/View.razor@@ -104,7 +104,7 @@ else}@* Attachments *@- @if (Item.Attachments.Count > 0)+ @if (Item.Attachments.Any(a => !a.IsDeleted)){<AttachmentViewer Attachments="@Item.Attachments" />}diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.csindex ff72d6305..95533609d 100644--- a/apps/server/AliasVault.Client/Services/ItemService.cs+++ b/apps/server/AliasVault.Client/Services/ItemService.cs@@ -397,15 +397,15 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, ConfEmail = GetFieldValue(x, FieldKey.LoginEmail),CardNumber = GetFieldValue(x, FieldKey.CardNumber),CreatedAt = x.CreatedAt,- HasPasskey = x.Passkeys != null && x.Passkeys.Any(),+ HasPasskey = x.Passkeys != null && x.Passkeys.Any(p => !p.IsDeleted),HasAlias = !string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.AliasFirstName)) ||!string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.AliasLastName)) ||!string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.AliasGender)) ||!string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.AliasBirthdate)),HasUsernameOrPassword = !string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.LoginUsername)) ||!string.IsNullOrWhiteSpace(GetFieldValue(x, FieldKey.LoginPassword)),- HasAttachment = x.Attachments != null && x.Attachments.Any(),- HasTotp = x.TotpCodes != null && x.TotpCodes.Any(),+ HasAttachment = x.Attachments != null && x.Attachments.Any(a => !a.IsDeleted),+ HasTotp = x.TotpCodes != null && x.TotpCodes.Any(t => !t.IsDeleted),FolderId = x.FolderId,FolderName = x.Folder?.Name,}).ToList();