diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 2544d4f1c4..e1d6152bf3 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -26,15 +26,10 @@ import { CipherResponse } from '../models/response/cipherResponse'; import { ErrorResponse } from '../models/response/errorResponse'; import { AttachmentView } from '../models/view/attachmentView'; -import { CardView } from '../models/view/cardView'; import { CipherView } from '../models/view/cipherView'; import { FieldView } from '../models/view/fieldView'; -import { IdentityView } from '../models/view/identityView'; -import { LoginView } from '../models/view/loginView'; import { View } from '../models/view/view'; -import { ConstantsService } from './constants.service'; - import { ApiService } from '../abstractions/api.service'; import { CipherService as CipherServiceAbstraction } from '../abstractions/cipher.service'; import { CryptoService } from '../abstractions/crypto.service'; diff --git a/src/services/folder.service.ts b/src/services/folder.service.ts index d4806e0c0f..51ec8e4bb8 100644 --- a/src/services/folder.service.ts +++ b/src/services/folder.service.ts @@ -9,23 +9,25 @@ import { FolderResponse } from '../models/response/folderResponse'; import { FolderView } from '../models/view/folderView'; import { ApiService } from '../abstractions/api.service'; +import { CipherService } from '../abstractions/cipher.service'; import { CryptoService } from '../abstractions/crypto.service'; import { FolderService as FolderServiceAbstraction } from '../abstractions/folder.service'; import { I18nService } from '../abstractions/i18n.service'; import { StorageService } from '../abstractions/storage.service'; import { UserService } from '../abstractions/user.service'; +import { CipherData } from '../models/data/cipherData'; const Keys = { foldersPrefix: 'folders_', + ciphersPrefix: 'ciphers_', }; export class FolderService implements FolderServiceAbstraction { decryptedFolderCache: FolderView[]; constructor(private cryptoService: CryptoService, private userService: UserService, - private noneFolder: () => string, private apiService: ApiService, - private storageService: StorageService, private i18nService: I18nService) { - } + private apiService: ApiService, private storageService: StorageService, + private i18nService: I18nService, private cipherService: CipherService) { } clearCache(): void { this.decryptedFolderCache = null; @@ -83,7 +85,7 @@ export class FolderService implements FolderServiceAbstraction { decFolders.sort(this.getLocaleSortingFunction()); const noneFolder = new FolderView(); - noneFolder.name = this.noneFolder(); + noneFolder.name = this.i18nService.t('noneFolder'); decFolders.push(noneFolder); this.decryptedFolderCache = decFolders; @@ -157,6 +159,21 @@ export class FolderService implements FolderServiceAbstraction { await this.storageService.save(Keys.foldersPrefix + userId, folders); this.decryptedFolderCache = null; + + // Items in a deleted folder are re-assigned to "No Folder" + const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(Keys.ciphersPrefix + userId); + if (ciphers != null) { + const updates: CipherData[] = []; + for (const cId in ciphers) { + if (ciphers[cId].folderId === id) { + ciphers[cId].folderId = null; + updates.push(ciphers[cId]); + } + } + if (updates.length > 0) { + this.cipherService.upsert(updates); + } + } } async deleteWithServer(id: string): Promise {