mirror of
https://github.com/bitwarden/clients.git
synced 2026-02-11 03:15:16 +08:00
* Migrated folder service from using active user state to single user state Added extra test cases for encrypted folder and decrypted folders Updated derived state to use decrypt with key * Update callers in the web * Update callers in the browser * Update callers in libs * Update callers in cli * Fixed test * Fixed folder state test * Fixed test * removed duplicate activeUserId * Added takewhile operator to only make calls when userId is present * Simplified to accept a single user id instead of an observable * Required userid to be passed from notification service * [PM-15635] Folders not working on desktop (#12333) * Added folders memory state definition * added decrypted folders state * Refactored service to remove derived state * removed combinedstate and added clear decrypted folders to methods * Fixed test * Fixed issue with editing folder on the desktop app * Fixed test * Changed state name * fixed ts strict issue * fixed ts strict issue * fixed ts strict issue * removed unnecessasry null encrypteed folder check * Handle null folderdata * [PM-16197] "Items with No Folder" shows as a folder to edit name and delete (#12470) * Force redcryption anytime encryption state changes * Fixed text file * revert changes * create new object with nofolder instead of modifying exisiting object * Fixed failing test * switched to use memory-large-object * Fixed ts sctrict issue --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com> Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
|
import { Validators, FormBuilder } from "@angular/forms";
|
|
import { firstValueFrom, map } from "rxjs";
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
|
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
|
import { DialogService } from "@bitwarden/components";
|
|
import { KeyService } from "@bitwarden/key-management";
|
|
|
|
@Directive()
|
|
export class FolderAddEditComponent implements OnInit {
|
|
@Input() folderId: string;
|
|
@Output() onSavedFolder = new EventEmitter<FolderView>();
|
|
@Output() onDeletedFolder = new EventEmitter<FolderView>();
|
|
|
|
editMode = false;
|
|
folder: FolderView = new FolderView();
|
|
title: string;
|
|
formPromise: Promise<any>;
|
|
deletePromise: Promise<any>;
|
|
protected componentName = "";
|
|
|
|
protected activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
|
|
|
|
formGroup = this.formBuilder.group({
|
|
name: ["", [Validators.required]],
|
|
});
|
|
|
|
constructor(
|
|
protected folderService: FolderService,
|
|
protected folderApiService: FolderApiServiceAbstraction,
|
|
protected accountService: AccountService,
|
|
protected keyService: KeyService,
|
|
protected i18nService: I18nService,
|
|
protected platformUtilsService: PlatformUtilsService,
|
|
protected logService: LogService,
|
|
protected dialogService: DialogService,
|
|
protected formBuilder: FormBuilder,
|
|
) {}
|
|
|
|
async ngOnInit() {
|
|
await this.init();
|
|
}
|
|
|
|
async submit(): Promise<boolean> {
|
|
this.folder.name = this.formGroup.controls.name.value;
|
|
if (this.folder.name == null || this.folder.name === "") {
|
|
this.platformUtilsService.showToast(
|
|
"error",
|
|
this.i18nService.t("errorOccurred"),
|
|
this.i18nService.t("nameRequired"),
|
|
);
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const activeUserId = await firstValueFrom(this.activeUserId$);
|
|
const userKey = await this.keyService.getUserKeyWithLegacySupport(activeUserId);
|
|
const folder = await this.folderService.encrypt(this.folder, userKey);
|
|
this.formPromise = this.folderApiService.save(folder, activeUserId);
|
|
await this.formPromise;
|
|
this.platformUtilsService.showToast(
|
|
"success",
|
|
null,
|
|
this.i18nService.t(this.editMode ? "editedFolder" : "addedFolder"),
|
|
);
|
|
this.onSavedFolder.emit(this.folder);
|
|
return true;
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
async delete(): Promise<boolean> {
|
|
const confirmed = await this.dialogService.openSimpleDialog({
|
|
title: { key: "deleteFolder" },
|
|
content: { key: "deleteFolderConfirmation" },
|
|
type: "warning",
|
|
});
|
|
|
|
if (!confirmed) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const activeUserId = await firstValueFrom(this.activeUserId$);
|
|
this.deletePromise = this.folderApiService.delete(this.folder.id, activeUserId);
|
|
await this.deletePromise;
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("deletedFolder"));
|
|
this.onDeletedFolder.emit(this.folder);
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected async init() {
|
|
this.editMode = this.folderId != null;
|
|
|
|
if (this.editMode) {
|
|
this.editMode = true;
|
|
this.title = this.i18nService.t("editFolder");
|
|
const activeUserId = await firstValueFrom(this.activeUserId$);
|
|
this.folder = await firstValueFrom(
|
|
this.folderService.getDecrypted$(this.folderId, activeUserId),
|
|
);
|
|
} else {
|
|
this.title = this.i18nService.t("addFolder");
|
|
}
|
|
this.formGroup.controls.name.setValue(this.folder.name);
|
|
}
|
|
}
|