fix: fixes issue where files imported from another account could not be deleted (#2082)
This commit is contained in:
@@ -145,6 +145,23 @@ describe('fileService', () => {
|
|||||||
expect(fileService['encryptedCache'].get(file.uuid)).toBeFalsy()
|
expect(fileService['encryptedCache'].get(file.uuid)).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('if file fails to delete, should present alert asking if they want to remove item', async () => {
|
||||||
|
const file = {
|
||||||
|
uuid: '1',
|
||||||
|
decryptedSize: 100_000,
|
||||||
|
} as jest.Mocked<FileItem>
|
||||||
|
|
||||||
|
const alertMock = (alertService.confirm = jest.fn().mockReturnValue(true))
|
||||||
|
const deleteItemMock = (itemManager.setItemToBeDeleted = jest.fn())
|
||||||
|
|
||||||
|
apiService.deleteFile = jest.fn().mockReturnValue({ error: true })
|
||||||
|
|
||||||
|
await fileService.deleteFile(file)
|
||||||
|
|
||||||
|
expect(alertMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(deleteItemMock).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
it('should download file from network if no backup', async () => {
|
it('should download file from network if no backup', async () => {
|
||||||
const file = {
|
const file = {
|
||||||
uuid: '1',
|
uuid: '1',
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
isEncryptedPayload,
|
isEncryptedPayload,
|
||||||
} from '@standardnotes/models'
|
} from '@standardnotes/models'
|
||||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||||
import { UuidGenerator } from '@standardnotes/utils'
|
import { spaceSeparatedStrings, UuidGenerator } from '@standardnotes/utils'
|
||||||
import { EncryptionProviderInterface, SNItemsKey } from '@standardnotes/encryption'
|
import { EncryptionProviderInterface, SNItemsKey } from '@standardnotes/encryption'
|
||||||
import {
|
import {
|
||||||
DownloadAndDecryptFileOperation,
|
DownloadAndDecryptFileOperation,
|
||||||
@@ -33,7 +33,7 @@ import {
|
|||||||
readAndDecryptBackupFileUsingBackupService,
|
readAndDecryptBackupFileUsingBackupService,
|
||||||
BackupServiceInterface,
|
BackupServiceInterface,
|
||||||
} from '@standardnotes/files'
|
} from '@standardnotes/files'
|
||||||
import { AlertService } from '../Alert/AlertService'
|
import { AlertService, ButtonType } from '../Alert/AlertService'
|
||||||
import { ChallengeServiceInterface } from '../Challenge'
|
import { ChallengeServiceInterface } from '../Challenge'
|
||||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||||
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
||||||
@@ -244,7 +244,21 @@ export class FileService extends AbstractService implements FilesClientInterface
|
|||||||
const result = await this.api.deleteFile(tokenResult)
|
const result = await this.api.deleteFile(tokenResult)
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
return ClientDisplayableError.FromError(result.error)
|
const deleteAnyway = await this.alertService.confirm(
|
||||||
|
spaceSeparatedStrings(
|
||||||
|
'This file could not be deleted from the server, possibly because you are attempting to delete a file item',
|
||||||
|
'that was imported from another account. Would you like to remove this file item from your account anyway?',
|
||||||
|
"If you're sure the file is yours and still exists on the server, do not choose this option,",
|
||||||
|
'and instead try to delete it again.',
|
||||||
|
),
|
||||||
|
'Unable to Delete',
|
||||||
|
'Delete Anyway',
|
||||||
|
ButtonType.Danger,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!deleteAnyway) {
|
||||||
|
return ClientDisplayableError.FromError(result.error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.itemManager.setItemToBeDeleted(file)
|
await this.itemManager.setItemToBeDeleted(file)
|
||||||
|
|||||||
@@ -683,3 +683,7 @@ export function assert(value: unknown): asserts value {
|
|||||||
export function useBoolean(value: boolean | undefined, defaultValue: boolean): boolean {
|
export function useBoolean(value: boolean | undefined, defaultValue: boolean): boolean {
|
||||||
return value != undefined ? value : defaultValue
|
return value != undefined ? value : defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function spaceSeparatedStrings(...strings: string[]): string {
|
||||||
|
return strings.join(' ')
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import ModalDialogLabel from '@/Components/Shared/ModalDialogLabel'
|
|||||||
import Button from '@/Components/Button/Button'
|
import Button from '@/Components/Button/Button'
|
||||||
import ImportPlugin from './Plugins/ImportPlugin/ImportPlugin'
|
import ImportPlugin from './Plugins/ImportPlugin/ImportPlugin'
|
||||||
import { NoteViewController } from '../Controller/NoteViewController'
|
import { NoteViewController } from '../Controller/NoteViewController'
|
||||||
import { spaceSeparatedStrings } from '../../../Utils/spaceSeparatedStrings'
|
import { spaceSeparatedStrings } from '@standardnotes/utils'
|
||||||
|
|
||||||
const NotePreviewCharLimit = 160
|
const NotePreviewCharLimit = 160
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
export function spaceSeparatedStrings(...strings: string[]): string {
|
|
||||||
return strings.join(' ')
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user