2018-06-05 05:10:41 +02:00
|
|
|
import {
|
2018-08-21 04:21:13 +02:00
|
|
|
ChangeDetectorRef,
|
2018-06-05 05:10:41 +02:00
|
|
|
Component,
|
2018-08-21 04:21:13 +02:00
|
|
|
NgZone,
|
|
|
|
OnDestroy,
|
2018-06-06 23:25:57 +02:00
|
|
|
OnInit,
|
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
2018-06-05 05:10:41 +02:00
|
|
|
} from "@angular/core";
|
2022-06-13 16:14:09 +02:00
|
|
|
import { ActivatedRoute, Params, Router } from "@angular/router";
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from "rxjs/operators";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
2022-08-08 21:08:35 +02:00
|
|
|
import { VaultFilter } from "@bitwarden/angular/vault/vault-filter/models/vault-filter.model";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
2022-09-27 22:25:19 +02:00
|
|
|
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-08-29 20:14:59 +02:00
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { TokenService } from "@bitwarden/common/abstractions/token.service";
|
2022-10-14 18:25:50 +02:00
|
|
|
import { CipherView } from "@bitwarden/common/models/view/cipher.view";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-08-08 21:08:35 +02:00
|
|
|
import { UpdateKeyComponent } from "../settings/update-key.component";
|
|
|
|
|
|
|
|
import { AddEditComponent } from "./add-edit.component";
|
|
|
|
import { AttachmentsComponent } from "./attachments.component";
|
|
|
|
import { CiphersComponent } from "./ciphers.component";
|
|
|
|
import { CollectionsComponent } from "./collections.component";
|
|
|
|
import { FolderAddEditComponent } from "./folder-add-edit.component";
|
|
|
|
import { ShareComponent } from "./share.component";
|
|
|
|
import { VaultService } from "./shared/vault.service";
|
|
|
|
import { VaultFilterService } from "./vault-filter/shared/vault-filter.service";
|
|
|
|
import { VaultFilterComponent } from "./vault-filter/vault-filter.component";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-08-21 04:21:13 +02:00
|
|
|
const BroadcasterSubscriptionId = "VaultComponent";
|
|
|
|
|
2018-06-05 05:10:41 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-vault",
|
2022-08-08 21:08:35 +02:00
|
|
|
templateUrl: "vault.component.html",
|
2018-06-05 05:10:41 +02:00
|
|
|
})
|
2022-08-08 21:08:35 +02:00
|
|
|
export class VaultComponent implements OnInit, OnDestroy {
|
2022-05-09 14:21:52 +02:00
|
|
|
@ViewChild("vaultFilter", { static: true }) filterComponent: VaultFilterComponent;
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild(CiphersComponent, { static: true }) ciphersComponent: CiphersComponent;
|
|
|
|
@ViewChild("attachments", { read: ViewContainerRef, static: true })
|
|
|
|
attachmentsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("folderAddEdit", { read: ViewContainerRef, static: true })
|
|
|
|
folderAddEditModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("cipherAddEdit", { read: ViewContainerRef, static: true })
|
|
|
|
cipherAddEditModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("share", { read: ViewContainerRef, static: true }) shareModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("collections", { read: ViewContainerRef, static: true })
|
|
|
|
collectionsModalRef: ViewContainerRef;
|
2018-06-06 23:25:57 +02:00
|
|
|
@ViewChild("updateKeyTemplate", { read: ViewContainerRef, static: true })
|
2018-07-12 17:34:51 +02:00
|
|
|
updateKeyModalRef: ViewContainerRef;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-04-27 18:49:02 +02:00
|
|
|
folderId: string = null;
|
2022-05-09 14:21:52 +02:00
|
|
|
myVaultOnly = false;
|
2018-07-12 17:34:51 +02:00
|
|
|
showVerifyEmail = false;
|
|
|
|
showBrowserOutdated = false;
|
|
|
|
showUpdateKey = false;
|
2018-07-20 16:44:17 +02:00
|
|
|
showPremiumCallout = false;
|
2021-04-27 18:49:02 +02:00
|
|
|
trashCleanupWarning: string = null;
|
2022-05-09 14:21:52 +02:00
|
|
|
activeFilter: VaultFilter = new VaultFilter();
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-04-27 18:49:02 +02:00
|
|
|
constructor(
|
2018-06-26 18:03:11 +02:00
|
|
|
private syncService: SyncService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
|
|
private i18nService: I18nService,
|
2018-08-31 23:23:36 +02:00
|
|
|
private modalService: ModalService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private tokenService: TokenService,
|
|
|
|
private cryptoService: CryptoService,
|
2018-06-06 23:25:57 +02:00
|
|
|
private messagingService: MessagingService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
2019-03-19 17:44:22 +01:00
|
|
|
private broadcasterService: BroadcasterService,
|
2020-04-08 22:48:30 +02:00
|
|
|
private ngZone: NgZone,
|
2021-12-14 17:10:26 +01:00
|
|
|
private stateService: StateService,
|
|
|
|
private organizationService: OrganizationService,
|
2022-05-09 14:21:52 +02:00
|
|
|
private vaultService: VaultService,
|
2022-05-06 11:29:45 +02:00
|
|
|
private cipherService: CipherService,
|
2022-06-10 03:51:46 +02:00
|
|
|
private passwordRepromptService: PasswordRepromptService,
|
|
|
|
private vaultFilterService: VaultFilterService
|
2021-12-17 15:57:11 +01:00
|
|
|
) {}
|
|
|
|
|
2020-04-08 22:48:30 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.showVerifyEmail = !(await this.tokenService.getEmailVerified());
|
2018-12-20 16:06:40 +01:00
|
|
|
this.showBrowserOutdated = window.navigator.userAgent.indexOf("MSIE") !== -1;
|
|
|
|
this.trashCleanupWarning = this.i18nService.t(
|
|
|
|
this.platformUtilsService.isSelfHost()
|
|
|
|
? "trashCleanupWarningSelfHosted"
|
2018-08-31 23:23:36 +02:00
|
|
|
: "trashCleanupWarning"
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2018-08-31 23:23:36 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (params) => {
|
|
|
|
await this.syncService.fullSync(false);
|
|
|
|
const canAccessPremium = await this.stateService.getCanAccessPremium();
|
|
|
|
this.showPremiumCallout =
|
|
|
|
!this.showVerifyEmail && !canAccessPremium && !this.platformUtilsService.isSelfHost();
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
this.filterComponent.reloadCollectionsAndFolders(this.activeFilter);
|
|
|
|
this.filterComponent.reloadOrganizations();
|
2018-06-07 15:05:25 +02:00
|
|
|
this.showUpdateKey = !(await this.cryptoService.hasEncKey());
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-06-13 16:14:09 +02:00
|
|
|
const cipherId = getCipherIdFromParams(params);
|
|
|
|
|
|
|
|
if (cipherId) {
|
2022-05-09 14:21:52 +02:00
|
|
|
const cipherView = new CipherView();
|
2022-06-13 16:14:09 +02:00
|
|
|
cipherView.id = cipherId;
|
2022-05-09 14:21:52 +02:00
|
|
|
if (params.action === "clone") {
|
|
|
|
await this.cloneCipher(cipherView);
|
|
|
|
} else if (params.action === "edit") {
|
|
|
|
await this.editCipher(cipherView);
|
2018-07-18 15:21:23 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2022-05-09 14:21:52 +02:00
|
|
|
await this.ciphersComponent.reload();
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
/* eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe, rxjs/no-nested-subscribe */
|
2022-04-25 15:41:44 +02:00
|
|
|
this.route.queryParams.subscribe(async (params) => {
|
2022-06-13 16:14:09 +02:00
|
|
|
const cipherId = getCipherIdFromParams(params);
|
|
|
|
if (cipherId) {
|
|
|
|
if ((await this.cipherService.get(cipherId)) != null) {
|
|
|
|
this.editCipherId(cipherId);
|
2022-04-25 15:41:44 +02:00
|
|
|
} else {
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("errorOccurred"),
|
|
|
|
this.i18nService.t("unknownCipher")
|
|
|
|
);
|
|
|
|
this.router.navigate([], {
|
2022-06-13 16:14:09 +02:00
|
|
|
queryParams: { itemId: null, cipherId: null },
|
2022-04-25 15:41:44 +02:00
|
|
|
queryParamsHandling: "merge",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "syncCompleted":
|
2018-08-31 23:23:36 +02:00
|
|
|
if (message.successfully) {
|
2021-08-27 14:50:58 +02:00
|
|
|
await Promise.all([
|
2022-05-09 14:21:52 +02:00
|
|
|
this.filterComponent.reloadCollectionsAndFolders(this.activeFilter),
|
|
|
|
this.filterComponent.reloadOrganizations(),
|
2021-08-27 14:50:58 +02:00
|
|
|
this.ciphersComponent.load(this.ciphersComponent.filter),
|
|
|
|
]);
|
|
|
|
this.changeDetectorRef.detectChanges();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
break;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
get isShowingCards() {
|
|
|
|
return (
|
|
|
|
this.showBrowserOutdated ||
|
|
|
|
this.showPremiumCallout ||
|
|
|
|
this.showUpdateKey ||
|
|
|
|
this.showVerifyEmail
|
|
|
|
);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
async applyVaultFilter(vaultFilter: VaultFilter) {
|
|
|
|
this.ciphersComponent.showAddNew = vaultFilter.status !== "trash";
|
|
|
|
this.activeFilter = vaultFilter;
|
2022-07-08 10:18:07 +02:00
|
|
|
await this.ciphersComponent.reload(
|
|
|
|
this.activeFilter.buildFilter(),
|
|
|
|
vaultFilter.status === "trash"
|
|
|
|
);
|
2022-05-09 14:21:52 +02:00
|
|
|
this.filterComponent.searchPlaceholder = this.vaultService.calculateSearchBarLocalizationString(
|
|
|
|
this.activeFilter
|
|
|
|
);
|
2018-06-06 23:25:57 +02:00
|
|
|
this.go();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
async applyOrganizationFilter(orgId: string) {
|
|
|
|
if (orgId == null) {
|
|
|
|
this.activeFilter.resetOrganization();
|
|
|
|
this.activeFilter.myVaultOnly = true;
|
|
|
|
} else {
|
|
|
|
this.activeFilter.selectedOrganizationId = orgId;
|
|
|
|
}
|
2022-06-13 20:56:01 +02:00
|
|
|
await this.vaultFilterService.ensureVaultFiltersAreExpanded();
|
2022-05-09 14:21:52 +02:00
|
|
|
await this.applyVaultFilter(this.activeFilter);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 05:00:57 +02:00
|
|
|
filterSearchText(searchText: string) {
|
2018-06-07 15:05:25 +02:00
|
|
|
this.ciphersComponent.searchText = searchText;
|
2018-08-13 22:27:17 +02:00
|
|
|
this.ciphersComponent.search(200);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-09 19:29:30 +02:00
|
|
|
async editCipherAttachments(cipher: CipherView) {
|
|
|
|
const canAccessPremium = await this.stateService.getCanAccessPremium();
|
2018-08-29 15:22:28 +02:00
|
|
|
if (cipher.organizationId == null && !canAccessPremium) {
|
2018-07-18 15:21:23 +02:00
|
|
|
this.messagingService.send("premiumRequired");
|
2021-12-17 15:57:11 +01:00
|
|
|
return;
|
2018-07-18 15:21:23 +02:00
|
|
|
} else if (cipher.organizationId != null) {
|
2021-12-14 17:10:26 +01:00
|
|
|
const org = await this.organizationService.get(cipher.organizationId);
|
2018-06-09 19:29:30 +02:00
|
|
|
if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) {
|
2018-07-18 15:21:23 +02:00
|
|
|
this.messagingService.send("upgradeOrganization", {
|
|
|
|
organizationId: cipher.organizationId,
|
2018-06-06 23:25:57 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-06-06 23:25:57 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
let madeAttachmentChanges = false;
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
AttachmentsComponent,
|
|
|
|
this.attachmentsModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.cipherId = cipher.id;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onUploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onDeletedAttachment.subscribe(() => (madeAttachmentChanges = true));
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onReuploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.onClosed.subscribe(async () => {
|
2018-06-09 19:29:30 +02:00
|
|
|
if (madeAttachmentChanges) {
|
2021-08-27 14:50:58 +02:00
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-09 19:29:30 +02:00
|
|
|
madeAttachmentChanges = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async shareCipher(cipher: CipherView) {
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
ShareComponent,
|
|
|
|
this.shareModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.cipherId = cipher.id;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSharedCipher.subscribe(async () => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2018-06-12 17:46:11 +02:00
|
|
|
});
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async editCipherCollections(cipher: CipherView) {
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
CollectionsComponent,
|
|
|
|
this.collectionsModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.cipherId = cipher.id;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSavedCollections.subscribe(async () => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2018-06-12 19:08:47 +02:00
|
|
|
});
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
async addFolder() {
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
FolderAddEditComponent,
|
|
|
|
this.folderAddEditModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.folderId = null;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSavedFolder.subscribe(async () => {
|
|
|
|
modal.close();
|
2022-05-09 14:21:52 +02:00
|
|
|
await this.filterComponent.reloadCollectionsAndFolders(this.activeFilter);
|
2018-06-06 23:25:57 +02:00
|
|
|
});
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
async editFolder(folderId: string) {
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
FolderAddEditComponent,
|
|
|
|
this.folderAddEditModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.folderId = folderId;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onSavedFolder.subscribe(async () => {
|
|
|
|
modal.close();
|
2022-05-09 14:21:52 +02:00
|
|
|
await this.filterComponent.reloadCollectionsAndFolders(this.activeFilter);
|
2018-06-06 23:25:57 +02:00
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2018-06-07 05:23:14 +02:00
|
|
|
comp.onDeletedFolder.subscribe(async () => {
|
2021-02-03 18:41:33 +01:00
|
|
|
modal.close();
|
2022-05-09 14:21:52 +02:00
|
|
|
await this.filterComponent.reloadCollectionsAndFolders(this.activeFilter);
|
2018-06-07 05:23:14 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-07 05:23:14 +02:00
|
|
|
);
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async addCipher() {
|
|
|
|
const component = await this.editCipher(null);
|
2022-05-23 22:09:52 +02:00
|
|
|
component.type = this.activeFilter.cipherType;
|
2018-06-06 23:25:57 +02:00
|
|
|
component.folderId = this.folderId === "none" ? null : this.folderId;
|
2022-05-09 14:21:52 +02:00
|
|
|
if (this.activeFilter.selectedCollectionId != null) {
|
|
|
|
const collection = this.filterComponent.collections.fullList.filter(
|
|
|
|
(c) => c.id === this.activeFilter.selectedCollectionId
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2018-10-22 22:46:48 +02:00
|
|
|
if (collection.length > 0) {
|
|
|
|
component.organizationId = collection[0].organizationId;
|
2022-05-09 14:21:52 +02:00
|
|
|
component.collectionIds = [this.activeFilter.selectedCollectionId];
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-06 23:25:57 +02:00
|
|
|
}
|
2022-05-09 14:21:52 +02:00
|
|
|
if (this.activeFilter.selectedFolderId && this.activeFilter.selectedFolder) {
|
|
|
|
component.folderId = this.activeFilter.selectedFolderId;
|
|
|
|
}
|
|
|
|
if (this.activeFilter.selectedOrganizationId) {
|
|
|
|
component.organizationId = this.activeFilter.selectedOrganizationId;
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
async editCipher(cipher: CipherView) {
|
2022-04-25 15:41:44 +02:00
|
|
|
return this.editCipherId(cipher?.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async editCipherId(id: string) {
|
2022-05-06 11:29:45 +02:00
|
|
|
const cipher = await this.cipherService.get(id);
|
2022-05-10 19:33:16 +02:00
|
|
|
if (cipher != null && cipher.reprompt != 0) {
|
2022-05-06 11:29:45 +02:00
|
|
|
if (!(await this.passwordRepromptService.showPasswordPrompt())) {
|
2022-06-13 16:14:09 +02:00
|
|
|
this.go({ cipherId: null, itemId: null });
|
2022-05-06 11:29:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
2020-04-08 22:48:30 +02:00
|
|
|
AddEditComponent,
|
|
|
|
this.cipherAddEditModalRef,
|
2021-08-27 14:50:58 +02:00
|
|
|
(comp) => {
|
2022-04-25 15:41:44 +02:00
|
|
|
comp.cipherId = id;
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onSavedCipher.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
2018-11-30 16:28:46 +01:00
|
|
|
await this.ciphersComponent.refresh();
|
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onDeletedCipher.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2022-02-24 12:10:07 +01:00
|
|
|
comp.onRestoredCipher.subscribe(async () => {
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-04-25 15:41:44 +02:00
|
|
|
modal.onClosedPromise().then(() => {
|
2022-06-13 16:14:09 +02:00
|
|
|
this.go({ cipherId: null, itemId: null });
|
2022-04-25 15:41:44 +02:00
|
|
|
});
|
|
|
|
|
2018-06-07 05:23:14 +02:00
|
|
|
return childComponent;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async cloneCipher(cipher: CipherView) {
|
|
|
|
const component = await this.editCipher(cipher);
|
2018-10-22 22:46:48 +02:00
|
|
|
component.cloneMode = true;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async updateKey() {
|
|
|
|
await this.modalService.openViewRef(UpdateKeyComponent, this.updateKeyModalRef);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 23:25:57 +02:00
|
|
|
private go(queryParams: any = null) {
|
|
|
|
if (queryParams == null) {
|
|
|
|
queryParams = {
|
2022-06-29 22:12:08 +02:00
|
|
|
favorites: this.activeFilter.status === "favorites" ? true : null,
|
2022-05-23 22:09:52 +02:00
|
|
|
type: this.activeFilter.cipherType,
|
2022-06-29 22:12:08 +02:00
|
|
|
folderId: this.activeFilter.selectedFolderId,
|
|
|
|
collectionId: this.activeFilter.selectedCollectionId,
|
|
|
|
deleted: this.activeFilter.status === "trash" ? true : null,
|
2021-12-17 15:57:11 +01:00
|
|
|
};
|
2018-06-06 23:25:57 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-11-30 16:28:46 +01:00
|
|
|
this.router.navigate([], {
|
|
|
|
relativeTo: this.route,
|
|
|
|
queryParams: queryParams,
|
2022-04-25 15:41:44 +02:00
|
|
|
queryParamsHandling: "merge",
|
2018-11-30 16:28:46 +01:00
|
|
|
replaceUrl: true,
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
2018-06-05 05:10:41 +02:00
|
|
|
}
|
2022-06-13 16:14:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows backwards compatibility with
|
|
|
|
* old links that used the original `cipherId` param
|
|
|
|
*/
|
|
|
|
const getCipherIdFromParams = (params: Params): string => {
|
|
|
|
return params["itemId"] || params["cipherId"];
|
|
|
|
};
|