bitwarden-estensione-browser/apps/desktop/src/app/vault/vault.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

785 lines
25 KiB
TypeScript
Raw Normal View History

2018-01-16 22:12:26 +01:00
import {
2018-02-08 21:58:47 +01:00
ChangeDetectorRef,
2018-01-16 22:12:26 +01:00
Component,
2018-02-08 21:58:47 +01:00
NgZone,
2018-02-10 05:25:18 +01:00
OnDestroy,
2018-01-16 22:12:26 +01:00
OnInit,
2018-01-26 21:44:02 +01:00
ViewChild,
2018-01-29 15:33:43 +01:00
ViewContainerRef,
2018-01-16 22:12:26 +01:00
} from "@angular/core";
2018-01-25 17:21:08 +01:00
import { ActivatedRoute, Router } from "@angular/router";
import { first } from "rxjs/operators";
2021-12-20 15:47:17 +01:00
import { ModalRef } from "jslib-angular/components/modal/modal.ref";
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
import { VaultFilter } from "jslib-angular/modules/vault-filter/models/vault-filter.model";
import { ModalService } from "jslib-angular/services/modal.service";
2021-12-06 12:03:02 +01:00
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
import { EventService } from "jslib-common/abstractions/event.service";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { MessagingService } from "jslib-common/abstractions/messaging.service";
import { PasswordRepromptService } from "jslib-common/abstractions/passwordReprompt.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
import { StateService } from "jslib-common/abstractions/state.service";
import { SyncService } from "jslib-common/abstractions/sync.service";
import { TotpService } from "jslib-common/abstractions/totp.service";
2022-02-24 20:50:19 +01:00
import { CipherRepromptType } from "jslib-common/enums/cipherRepromptType";
import { CipherType } from "jslib-common/enums/cipherType";
import { EventType } from "jslib-common/enums/eventType";
import { CipherView } from "jslib-common/models/view/cipherView";
import { FolderView } from "jslib-common/models/view/folderView";
import { invokeMenu, RendererMenuItem } from "jslib-electron/utils";
2021-12-20 15:47:17 +01:00
2022-02-24 20:50:19 +01:00
import { SearchBarService } from "../layout/search/search-bar.service";
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
import { VaultFilterComponent } from "../modules/vault-filter/vault-filter.component";
2022-02-24 20:50:19 +01:00
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 { GeneratorComponent } from "./generator.component";
2022-02-24 20:50:19 +01:00
import { PasswordHistoryComponent } from "./password-history.component";
import { ShareComponent } from "./share.component";
import { ViewComponent } from "./view.component";
2018-02-10 21:22:07 +01:00
const BroadcasterSubscriptionId = "VaultComponent";
2018-02-09 21:49:00 +01:00
2018-01-16 22:12:26 +01:00
@Component({
selector: "app-vault",
templateUrl: "vault.component.html",
2018-01-16 22:12:26 +01:00
})
2018-02-10 05:25:18 +01:00
export class VaultComponent implements OnInit, OnDestroy {
@ViewChild(ViewComponent) viewComponent: ViewComponent;
2018-01-29 22:33:38 +01:00
@ViewChild(AddEditComponent) addEditComponent: AddEditComponent;
2020-08-18 22:13:15 +02:00
@ViewChild(CiphersComponent, { static: true }) ciphersComponent: CiphersComponent;
@ViewChild("generator", { read: ViewContainerRef, static: true })
generatorModalRef: ViewContainerRef;
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
@ViewChild(VaultFilterComponent, { static: true }) vaultFilterComponent: VaultFilterComponent;
2020-08-18 22:13:15 +02:00
@ViewChild("attachments", { read: ViewContainerRef, static: true })
attachmentsModalRef: ViewContainerRef;
@ViewChild("passwordHistory", { read: ViewContainerRef, static: true })
passwordHistoryModalRef: ViewContainerRef;
@ViewChild("share", { read: ViewContainerRef, static: true }) shareModalRef: ViewContainerRef;
@ViewChild("collections", { read: ViewContainerRef, static: true })
collectionsModalRef: ViewContainerRef;
2021-02-22 19:17:02 +01:00
@ViewChild("folderAddEdit", { read: ViewContainerRef, static: true })
2018-01-27 05:56:43 +01:00
folderAddEditModalRef: ViewContainerRef;
2021-12-20 15:47:17 +01:00
2018-01-27 05:56:43 +01:00
action: string;
cipherId: string = null;
2022-02-24 20:50:19 +01:00
favorites = false;
2018-02-08 21:58:47 +01:00
type: CipherType = null;
folderId: string = null;
2019-04-02 15:02:31 +02:00
collectionId: string = null;
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
organizationId: string = null;
myVaultOnly = false;
addType: CipherType = null;
2018-11-30 16:12:30 +01:00
addOrganizationId: string = null;
addCollectionIds: string[] = null;
showingModal = false;
2018-02-08 21:58:47 +01:00
deleted = false;
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
userHasPremiumAccess = false;
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
activeFilter: VaultFilter = new VaultFilter();
2021-12-20 15:47:17 +01:00
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
private modal: ModalRef = null;
2021-12-20 15:47:17 +01:00
2018-02-10 21:22:07 +01:00
constructor(
private route: ActivatedRoute,
private router: Router,
2018-02-08 21:58:47 +01:00
private i18nService: I18nService,
private modalService: ModalService,
2018-02-08 21:58:47 +01:00
private broadcasterService: BroadcasterService,
2018-02-09 18:12:41 +01:00
private changeDetectorRef: ChangeDetectorRef,
private ngZone: NgZone,
private syncService: SyncService,
2018-02-09 18:12:41 +01:00
private messagingService: MessagingService,
private platformUtilsService: PlatformUtilsService,
private eventService: EventService,
private totpService: TotpService,
private passwordRepromptService: PasswordRepromptService,
2018-02-12 21:06:39 +01:00
private stateService: StateService,
private searchBarService: SearchBarService
2021-12-20 15:47:17 +01:00
) {}
async ngOnInit() {
this.userHasPremiumAccess = await this.stateService.getCanAccessPremium();
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
this.ngZone.run(async () => {
let detectChanges = true;
2021-12-20 15:47:17 +01:00
switch (message.command) {
case "newLogin":
await this.addCipher(CipherType.Login);
break;
case "newCard":
await this.addCipher(CipherType.Card);
break;
case "newIdentity":
await this.addCipher(CipherType.Identity);
2021-12-20 15:47:17 +01:00
break;
case "newSecureNote":
await this.addCipher(CipherType.SecureNote);
2021-12-20 15:47:17 +01:00
break;
case "focusSearch":
(document.querySelector("#search") as HTMLInputElement).select();
2018-02-08 21:58:47 +01:00
detectChanges = false;
break;
case "openGenerator":
await this.openGenerator(false);
2018-02-08 21:58:47 +01:00
break;
2018-02-09 19:47:59 +01:00
case "syncCompleted":
await this.ciphersComponent.reload(this.buildFilter());
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
await this.vaultFilterComponent.reloadCollectionsAndFolders(this.activeFilter);
await this.vaultFilterComponent.reloadOrganizations();
2019-04-14 03:17:05 +02:00
break;
2018-02-10 21:22:07 +01:00
case "refreshCiphers":
2018-02-09 19:47:59 +01:00
this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
break;
2018-02-09 19:47:59 +01:00
case "modalShown":
this.showingModal = true;
break;
case "modalClosed":
2021-02-22 21:00:19 +01:00
this.showingModal = false;
2021-12-20 15:47:17 +01:00
break;
2022-02-24 20:50:19 +01:00
case "copyUsername": {
const uComponent =
this.addEditComponent == null ? this.viewComponent : this.addEditComponent;
const uCipher = uComponent != null ? uComponent.cipher : null;
2021-12-20 15:47:17 +01:00
if (
this.cipherId != null &&
uCipher != null &&
uCipher.id === this.cipherId &&
uCipher.login != null &&
uCipher.login.username != null
2018-02-09 19:47:59 +01:00
) {
this.copyValue(uCipher, uCipher.login.username, "username", "Username");
2018-01-27 05:56:43 +01:00
}
2018-02-09 19:47:59 +01:00
break;
2022-02-24 20:50:19 +01:00
}
case "copyPassword": {
2018-01-26 20:56:54 +01:00
const pComponent =
2018-01-25 17:21:08 +01:00
this.addEditComponent == null ? this.viewComponent : this.addEditComponent;
const pCipher = pComponent != null ? pComponent.cipher : null;
if (
this.cipherId != null &&
pCipher != null &&
pCipher.id === this.cipherId &&
pCipher.login != null &&
pCipher.login.password != null &&
pCipher.viewPassword
) {
this.copyValue(pCipher, pCipher.login.password, "password", "Password");
2021-12-20 15:47:17 +01:00
}
break;
2022-02-24 20:50:19 +01:00
}
case "copyTotp": {
const tComponent =
this.addEditComponent == null ? this.viewComponent : this.addEditComponent;
const tCipher = tComponent != null ? tComponent.cipher : null;
if (
this.cipherId != null &&
tCipher != null &&
tCipher.id === this.cipherId &&
tCipher.login != null &&
tCipher.login.hasTotp &&
this.userHasPremiumAccess
) {
const value = await this.totpService.getCode(tCipher.login.totp);
this.copyValue(tCipher, value, "verificationCodeTotp", "TOTP");
2018-01-25 17:28:52 +01:00
}
2022-02-24 20:50:19 +01:00
break;
}
2021-12-20 15:47:17 +01:00
default:
2018-01-25 17:21:08 +01:00
detectChanges = false;
break;
}
if (detectChanges) {
this.changeDetectorRef.detectChanges();
}
2021-12-20 15:47:17 +01:00
});
});
if (!this.syncService.syncInProgress) {
await this.load();
}
2019-04-14 03:17:05 +02:00
document.body.classList.remove("layout_frontend");
this.searchBarService.setEnabled(true);
this.searchBarService.setPlaceholderText(this.i18nService.t("searchVault"));
2018-01-25 17:28:52 +01:00
}
2018-01-25 17:21:08 +01:00
ngOnDestroy() {
2018-01-26 20:56:54 +01:00
this.searchBarService.setEnabled(false);
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
2018-01-27 14:52:39 +01:00
document.body.classList.add("layout_frontend");
2018-01-26 20:56:54 +01:00
}
async load() {
this.route.queryParams.pipe(first()).subscribe(async (params) => {
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
if (params.cipherId) {
const cipherView = new CipherView();
cipherView.id = params.cipherId;
if (params.action === "clone") {
await this.cloneCipher(cipherView);
} else if (params.action === "edit") {
await this.editCipher(cipherView);
2021-12-20 15:47:17 +01:00
} else {
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
await this.viewCipher(cipherView);
2018-10-23 21:50:21 +02:00
}
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
} else if (params.action === "add") {
this.addType = Number(params.addType);
this.addCipher(this.addType);
2021-12-20 15:47:17 +01:00
}
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
this.activeFilter = new VaultFilter({
status: params.deleted ? "trash" : params.favorites ? "favorites" : "all",
cipherType:
params.action === "add" || params.type == null ? null : parseInt(params.type, null),
selectedFolderId: params.folderId,
selectedCollectionId: params.selectedCollectionId,
selectedOrganizationId: params.selectedOrganizationId,
myVaultOnly: params.myVaultOnly ?? false,
});
await this.ciphersComponent.reload(this.buildFilter());
2021-12-20 15:47:17 +01:00
});
}
async viewCipher(cipher: CipherView) {
if (!(await this.canNavigateAway("view", cipher))) {
return;
2021-12-20 15:47:17 +01:00
}
2021-02-03 19:21:22 +01:00
this.cipherId = cipher.id;
this.action = "view";
2018-01-27 14:52:39 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
2018-10-23 21:50:21 +02:00
viewCipherMenu(cipher: CipherView) {
const menu: RendererMenuItem[] = [
2021-12-20 15:47:17 +01:00
{
2018-10-23 21:50:21 +02:00
label: this.i18nService.t("view"),
click: () =>
this.functionWithChangeDetection(() => {
this.viewCipher(cipher);
2021-12-20 15:47:17 +01:00
}),
},
2018-10-23 21:50:21 +02:00
];
if (!cipher.isDeleted) {
menu.push({
label: this.i18nService.t("edit"),
click: () =>
this.functionWithChangeDetection(() => {
this.editCipher(cipher);
2021-12-20 15:47:17 +01:00
}),
2018-10-23 21:50:21 +02:00
});
menu.push({
label: this.i18nService.t("clone"),
click: () =>
this.functionWithChangeDetection(() => {
this.cloneCipher(cipher);
2021-12-20 15:47:17 +01:00
}),
});
}
switch (cipher.type) {
case CipherType.Login:
2018-10-23 21:50:21 +02:00
if (
cipher.login.canLaunch ||
2018-10-23 21:50:21 +02:00
cipher.login.username != null ||
cipher.login.password != null
2018-10-23 21:50:21 +02:00
) {
menu.push({ type: "separator" });
}
if (cipher.login.canLaunch) {
menu.push({
label: this.i18nService.t("launch"),
click: () => this.platformUtilsService.launchUri(cipher.login.launchUri),
2018-10-23 21:50:21 +02:00
});
}
2018-01-26 20:56:54 +01:00
if (cipher.login.username != null) {
2018-01-27 05:32:03 +01:00
menu.push({
[Account Switching] [Feature] Add the ability to maintain state for up to 5 accounts at once (#1079) * [refactor] Remove references to deprecated services * [feature] Implement account switching * [bug] Fix state handling for authentication dependent system menu items * [bug] Enable the account switcher to fucntion properly when switching to a locked accounts * [feature] Enable locking any account from the menu * [bug] Ensure the avatar instance used in the account switcher updates on account change * [style] Fix lint complaints * [bug] Ensure the logout command callback can handle any user in state * [style] Fix lint complaints * rollup * [style] Fix lint complaints * [bug] Don't clean up state until everything else is done on logout * [bug] Navigate to vault on a succesful account switch * [bug] Init the state service on start * [feature] Limit account switching to 5 account maximum * [bug] Resolve app lock state with 5 logged out accounts * [chore] Update account refrences to match recent jslib restructuring * [bug] Add missing awaits * [bug] Update app menu on logout * [bug] Hide the switcher if there are no authed accounts * [bug] Move authenticationStatus display information out of jslib * [bug] Remove unused active style from scss * [refactor] Rewrite the menu bar * [style] Fix lint complaints * [bug] Clean state of loggout out user after redirect * [bug] Redirect on logout if not explicity provided a userId that isn't active * [bug] Relocated several settings items to persistant storage * [bug] Correct account switcher styles on all themes * [chore] Include state migration service in services * [bug] Swap to next account on logout * [bug] Correct DI service * [bug] fix loginGuard deps in services.module * [chore] update jslib * [bug] Remove badly merged scss * [chore] update jslib * [review] Code review cleanup * [review] Code review cleanup Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-15 23:32:00 +01:00
label: this.i18nService.t("copyUsername"),
2021-02-03 19:21:22 +01:00
click: () => this.copyValue(cipher, cipher.login.username, "username", "Username"),
});
2018-02-09 18:12:41 +01:00
}
2019-01-25 15:30:29 +01:00
if (cipher.login.password != null && cipher.viewPassword) {
menu.push({
label: this.i18nService.t("copyPassword"),
2018-01-29 22:33:38 +01:00
click: () => {
this.copyValue(cipher, cipher.login.password, "password", "Password");
2021-02-22 19:17:02 +01:00
this.eventService.collect(EventType.Cipher_ClientCopiedPassword, cipher.id);
2018-01-30 21:40:06 +01:00
},
2018-02-09 18:36:33 +01:00
});
}
if (cipher.login.hasTotp && (cipher.organizationUseTotp || this.userHasPremiumAccess)) {
2018-01-30 21:40:06 +01:00
menu.push({
label: this.i18nService.t("copyVerificationCodeTotp"),
click: async () => {
const value = await this.totpService.getCode(cipher.login.totp);
2018-01-27 05:56:43 +01:00
this.copyValue(cipher, value, "verificationCodeTotp", "TOTP");
},
});
}
2018-11-30 16:12:30 +01:00
break;
case CipherType.Card:
if (cipher.card.number != null || cipher.card.code != null) {
2021-02-03 19:21:22 +01:00
menu.push({ type: "separator" });
}
if (cipher.card.number != null) {
menu.push({
label: this.i18nService.t("copyNumber"),
click: () => this.copyValue(cipher, cipher.card.number, "number", "Card Number"),
});
}
if (cipher.card.code != null) {
menu.push({
label: this.i18nService.t("copySecurityCode"),
click: () => {
this.copyValue(cipher, cipher.card.code, "securityCode", "Security Code");
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
2021-12-20 15:47:17 +01:00
},
});
}
break;
default:
break;
}
invokeMenu(menu);
2021-12-20 15:47:17 +01:00
}
async editCipher(cipher: CipherView) {
if (!(await this.canNavigateAway("edit", cipher))) {
return;
} else if (!(await this.passwordReprompt(cipher))) {
2021-12-20 15:47:17 +01:00
return;
}
await this.editCipherWithoutPasswordPrompt(cipher);
2021-12-20 15:47:17 +01:00
}
async editCipherWithoutPasswordPrompt(cipher: CipherView) {
if (!(await this.canNavigateAway("edit", cipher))) {
2021-12-20 15:47:17 +01:00
return;
}
2018-01-26 20:56:54 +01:00
this.cipherId = cipher.id;
this.action = "edit";
2018-01-27 14:52:39 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
async cloneCipher(cipher: CipherView) {
if (!(await this.canNavigateAway("clone", cipher))) {
2021-12-20 15:47:17 +01:00
return;
} else if (!(await this.passwordReprompt(cipher))) {
2021-12-20 15:47:17 +01:00
return;
}
await this.cloneCipherWithoutPasswordPrompt(cipher);
2021-12-20 15:47:17 +01:00
}
async cloneCipherWithoutPasswordPrompt(cipher: CipherView) {
if (!(await this.canNavigateAway("edit", cipher))) {
2021-12-20 15:47:17 +01:00
return;
}
2018-01-26 20:56:54 +01:00
this.cipherId = cipher.id;
this.action = "clone";
2018-01-27 14:52:39 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
async addCipher(type: CipherType = null) {
if (!(await this.canNavigateAway("add", null))) {
2021-12-20 15:47:17 +01:00
return;
}
2018-02-08 21:58:47 +01:00
this.addType = type;
2018-01-25 17:21:08 +01:00
this.action = "add";
this.cipherId = null;
this.prefillNewCipherFromFilter();
2018-01-27 14:52:39 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
addCipherOptions() {
const menu: RendererMenuItem[] = [
2021-12-20 15:47:17 +01:00
{
label: this.i18nService.t("typeLogin"),
click: () => this.addCipherWithChangeDetection(CipherType.Login),
2021-12-20 15:47:17 +01:00
},
{
label: this.i18nService.t("typeCard"),
click: () => this.addCipherWithChangeDetection(CipherType.Card),
2021-12-20 15:47:17 +01:00
},
{
label: this.i18nService.t("typeIdentity"),
click: () => this.addCipherWithChangeDetection(CipherType.Identity),
2021-12-20 15:47:17 +01:00
},
{
label: this.i18nService.t("typeSecureNote"),
click: () => this.addCipherWithChangeDetection(CipherType.SecureNote),
2021-12-20 15:47:17 +01:00
},
];
invokeMenu(menu);
2021-12-20 15:47:17 +01:00
}
async savedCipher(cipher: CipherView) {
2018-01-26 20:56:54 +01:00
this.cipherId = cipher.id;
this.action = "view";
this.go();
await this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
}
async deletedCipher(cipher: CipherView) {
this.cipherId = null;
2018-01-26 20:56:54 +01:00
this.action = null;
this.go();
await this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
}
async restoredCipher(cipher: CipherView) {
this.cipherId = null;
2018-01-26 20:56:54 +01:00
this.action = null;
this.go();
await this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
}
async editCipherAttachments(cipher: CipherView) {
2018-10-23 21:50:21 +02:00
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
const [modal, childComponent] = await this.modalService.openViewRef(
AttachmentsComponent,
this.attachmentsModalRef,
(comp) => (comp.cipherId = cipher.id)
2021-12-20 15:47:17 +01:00
);
this.modal = modal;
2021-12-20 15:47:17 +01:00
2018-06-09 19:29:23 +02:00
let madeAttachmentChanges = false;
childComponent.onUploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
childComponent.onDeletedAttachment.subscribe(() => (madeAttachmentChanges = true));
2021-12-20 15:47:17 +01:00
2018-10-23 21:50:21 +02:00
this.modal.onClosed.subscribe(async () => {
this.modal = null;
2018-06-09 19:29:23 +02:00
if (madeAttachmentChanges) {
await this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
}
2018-06-09 19:29:23 +02:00
madeAttachmentChanges = false;
2021-12-20 15:47:17 +01:00
});
}
async shareCipher(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
const [modal, childComponent] = await this.modalService.openViewRef(
ShareComponent,
this.shareModalRef,
(comp) => (comp.cipherId = cipher.id)
2021-12-20 15:47:17 +01:00
);
this.modal = modal;
2021-12-20 15:47:17 +01:00
2018-01-30 21:40:06 +01:00
childComponent.onSharedCipher.subscribe(async () => {
this.modal.close();
2018-10-23 21:50:21 +02:00
this.viewCipher(cipher);
await this.ciphersComponent.refresh();
2021-12-20 15:47:17 +01:00
});
this.modal.onClosed.subscribe(async () => {
this.modal = null;
2021-12-20 15:47:17 +01:00
});
}
async cipherCollections(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
const [modal, childComponent] = await this.modalService.openViewRef(
CollectionsComponent,
this.collectionsModalRef,
(comp) => (comp.cipherId = cipher.id)
2021-12-20 15:47:17 +01:00
);
this.modal = modal;
2021-12-20 15:47:17 +01:00
2018-10-23 21:50:21 +02:00
childComponent.onSavedCollections.subscribe(() => {
2018-02-09 18:36:33 +01:00
this.modal.close();
2018-10-23 21:50:21 +02:00
this.viewCipher(cipher);
2021-12-20 15:47:17 +01:00
});
this.modal.onClosed.subscribe(async () => {
this.modal = null;
2021-12-20 15:47:17 +01:00
});
}
async viewCipherPasswordHistory(cipher: CipherView) {
2018-02-09 18:36:33 +01:00
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
[this.modal] = await this.modalService.openViewRef(
PasswordHistoryComponent,
this.passwordHistoryModalRef,
(comp) => (comp.cipherId = cipher.id)
2021-12-20 15:47:17 +01:00
);
this.modal.onClosed.subscribe(async () => {
2018-08-02 05:21:32 +02:00
this.modal = null;
2021-12-20 15:47:17 +01:00
});
}
2018-01-26 20:56:54 +01:00
cancelledAddEdit(cipher: CipherView) {
this.cipherId = cipher.id;
this.action = this.cipherId != null ? "view" : null;
2018-01-27 05:56:43 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
async applyVaultFilter(vaultFilter: VaultFilter) {
this.searchBarService.setPlaceholderText(
this.i18nService.t(this.calculateSearchBarLocalizationString(vaultFilter))
);
this.activeFilter = vaultFilter;
await this.ciphersComponent.reload(this.buildFilter());
2018-01-27 05:56:43 +01:00
this.go();
2021-12-20 15:47:17 +01:00
}
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
private calculateSearchBarLocalizationString(vaultFilter: VaultFilter): string {
if (vaultFilter.status === "favorites") {
return "searchFavorites";
}
if (vaultFilter.status === "trash") {
return "searchTrash";
}
if (vaultFilter.cipherType != null) {
return "searchType";
}
if (vaultFilter.selectedFolderId != null && vaultFilter.selectedFolderId != "none") {
return "searchFolder";
}
if (vaultFilter.selectedCollectionId != null) {
return "searchCollection";
}
if (vaultFilter.selectedOrganizationId != null) {
return "searchOrganization";
}
if (vaultFilter.myVaultOnly) {
return "searchMyVault";
}
2021-12-20 15:47:17 +01:00
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
return "searchVault";
2021-12-20 15:47:17 +01:00
}
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
private buildFilter(): (cipher: CipherView) => boolean {
return (cipher) => {
let cipherPassesFilter = true;
if (this.activeFilter.status === "favorites" && cipherPassesFilter) {
cipherPassesFilter = cipher.favorite;
}
if (this.activeFilter.status === "trash" && cipherPassesFilter) {
cipherPassesFilter = cipher.isDeleted;
}
if (this.activeFilter.cipherType != null && cipherPassesFilter) {
cipherPassesFilter = cipher.type === this.activeFilter.cipherType;
}
if (
this.activeFilter.selectedFolderId != null &&
this.activeFilter.selectedFolderId != "none" &&
cipherPassesFilter
) {
cipherPassesFilter = cipher.folderId === this.activeFilter.selectedFolderId;
}
if (this.activeFilter.selectedCollectionId != null && cipherPassesFilter) {
cipherPassesFilter =
cipher.collectionIds != null &&
cipher.collectionIds.indexOf(this.activeFilter.selectedCollectionId) > -1;
}
if (this.activeFilter.selectedOrganizationId != null && cipherPassesFilter) {
cipherPassesFilter = cipher.organizationId === this.activeFilter.selectedOrganizationId;
}
if (this.activeFilter.myVaultOnly && cipherPassesFilter) {
cipherPassesFilter = cipher.organizationId === null;
}
return cipherPassesFilter;
};
2021-12-20 15:47:17 +01:00
}
async openGenerator(comingFromAddEdit: boolean, passwordType = true) {
2018-02-09 18:36:33 +01:00
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
const cipher = this.addEditComponent?.cipher;
const loginType = cipher != null && cipher.type === CipherType.Login && cipher.login != null;
const [modal, childComponent] = await this.modalService.openViewRef(
GeneratorComponent,
this.generatorModalRef,
(comp) => {
comp.comingFromAddEdit = comingFromAddEdit;
if (comingFromAddEdit) {
comp.type = passwordType ? "password" : "username";
if (loginType && cipher.login.hasUris && cipher.login.uris[0].hostname != null) {
comp.usernameWebsite = cipher.login.uris[0].hostname;
}
}
}
2021-12-20 15:47:17 +01:00
);
this.modal = modal;
2021-12-20 15:47:17 +01:00
childComponent.onSelected.subscribe((value: string) => {
2018-02-09 18:36:33 +01:00
this.modal.close();
if (loginType) {
this.addEditComponent.markPasswordAsDirty();
if (passwordType) {
this.addEditComponent.cipher.login.password = value;
} else {
this.addEditComponent.cipher.login.username = value;
}
2021-12-20 15:47:17 +01:00
}
});
2018-02-09 18:36:33 +01:00
this.modal.onClosed.subscribe(() => {
this.modal = null;
2021-12-20 15:47:17 +01:00
});
}
2018-01-30 21:40:06 +01:00
async addFolder() {
this.messagingService.send("newFolder");
2021-12-20 15:47:17 +01:00
}
2018-01-30 21:40:06 +01:00
async editFolder(folderId: string) {
2018-02-09 18:36:33 +01:00
if (this.modal != null) {
this.modal.close();
2021-12-20 15:47:17 +01:00
}
const [modal, childComponent] = await this.modalService.openViewRef(
FolderAddEditComponent,
this.folderAddEditModalRef,
(comp) => (comp.folderId = folderId)
2021-12-20 15:47:17 +01:00
);
this.modal = modal;
2021-12-20 15:47:17 +01:00
2018-01-30 21:40:06 +01:00
childComponent.onSavedFolder.subscribe(async (folder: FolderView) => {
2018-02-09 18:36:33 +01:00
this.modal.close();
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
await this.vaultFilterComponent.reloadCollectionsAndFolders(this.activeFilter);
2021-12-20 15:47:17 +01:00
});
2018-01-30 21:40:06 +01:00
childComponent.onDeletedFolder.subscribe(async (folder: FolderView) => {
2018-02-09 18:36:33 +01:00
this.modal.close();
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
await this.vaultFilterComponent.reloadCollectionsAndFolders(this.activeFilter);
2021-12-20 15:47:17 +01:00
});
2018-02-09 18:36:33 +01:00
this.modal.onClosed.subscribe(() => {
this.modal = null;
2021-12-20 15:47:17 +01:00
});
}
private dirtyInput(): boolean {
2021-12-20 15:47:17 +01:00
return (
(this.action === "add" || this.action === "edit" || this.action === "clone") &&
document.querySelectorAll("app-vault-add-edit .ng-dirty").length > 0
2021-12-20 15:47:17 +01:00
);
}
private async wantsToSaveChanges(): Promise<boolean> {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t("unsavedChangesConfirmation"),
this.i18nService.t("unsavedChangesTitle"),
this.i18nService.t("yes"),
this.i18nService.t("no"),
2021-12-20 15:47:17 +01:00
"warning"
);
return !confirmed;
2021-12-20 15:47:17 +01:00
}
2018-01-27 05:56:43 +01:00
private go(queryParams: any = null) {
if (queryParams == null) {
2018-01-27 05:56:43 +01:00
queryParams = {
action: this.action,
2018-01-26 20:56:54 +01:00
cipherId: this.cipherId,
2018-01-27 05:56:43 +01:00
favorites: this.favorites ? true : null,
type: this.type,
folderId: this.folderId,
collectionId: this.collectionId,
deleted: this.deleted ? true : null,
[Feature] End User Vault Refresh (#2545) * Initial org filter work * update jslib * Move filter to below cipher length check * don't show vault filter in personal or org folder * Use family icon for families org * jslib and auth guard updates * lint fixes * rename GroupingsComponent to VaultFilterComponent * fix no folder showing all items * Add checks for PersonalOwnership policy * update css class names * lint fixes * cleanup * Some final cleanup * import order lint fix * remove unused import * Use smaller icon for chevron * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * Update src/popup/vault/organization-filter.component.ts Co-authored-by: Addison Beck <addisonbeck1@gmail.com> * fix lint error * remove extra localizations * rename orgFilter -> vaultSelect * Rename orgFilterService to VaultSelectService * lint fixes * combine vault select service with vault filter service * Use base vault filter service methods * Use VaultFilter model and other small fixes * lint fixes * Final restructuring pass * Update jslib and remove extra function * Remove extra imports * remove space * Remove vaultFilterService from background services * Update jslib to latest on feature branch * merge fix * update jslib * [feat] Implement EUVR for desktop Should contain only https://github.com/bitwarden/desktop/pull/1487, with merge resolutions and style fixes * [fix] Delete unused GroupingsComponentTemplate * [dep] Update jslib Co-authored-by: Addison Beck <addisonbeck1@gmail.com>
2022-05-09 14:19:18 +02:00
organizationId: this.organizationId,
myVaultOnly: this.myVaultOnly,
2021-12-20 15:47:17 +01:00
};
}
2018-11-30 16:12:30 +01:00
this.router.navigate([], {
relativeTo: this.route,
queryParams: queryParams,
replaceUrl: true,
2021-12-20 15:47:17 +01:00
});
}
private addCipherWithChangeDetection(type: CipherType = null) {
2018-02-23 22:31:52 +01:00
this.functionWithChangeDetection(() => this.addCipher(type));
2021-12-20 15:47:17 +01:00
}
private copyValue(cipher: CipherView, value: string, labelI18nKey: string, aType: string) {
this.functionWithChangeDetection(async () => {
2021-12-20 15:47:17 +01:00
if (
cipher.reprompt !== CipherRepromptType.None &&
this.passwordRepromptService.protectedFields().includes(aType) &&
!(await this.passwordRepromptService.showPasswordPrompt())
2021-12-20 15:47:17 +01:00
) {
return;
}
2018-02-23 22:31:52 +01:00
this.platformUtilsService.copyToClipboard(value);
2021-12-07 20:42:31 +01:00
this.platformUtilsService.showToast(
2021-12-20 15:47:17 +01:00
"info",
null,
2018-02-23 22:31:52 +01:00
this.i18nService.t("valueCopied", this.i18nService.t(labelI18nKey))
2021-12-20 15:47:17 +01:00
);
if (this.action === "view") {
this.messagingService.send("minimizeOnCopy");
2021-12-20 15:47:17 +01:00
}
});
}
2022-02-24 20:50:19 +01:00
private functionWithChangeDetection(func: () => void) {
2019-11-07 17:25:20 +01:00
this.ngZone.run(() => {
2021-12-20 15:47:17 +01:00
func();
this.changeDetectorRef.detectChanges();
2021-12-20 15:47:17 +01:00
});
}
private prefillNewCipherFromFilter() {
if (this.activeFilter.selectedCollectionId != null) {
const collection = this.vaultFilterComponent.collections.fullList.filter(
(c) => c.id === this.activeFilter.selectedCollectionId
2021-12-20 15:47:17 +01:00
);
if (collection.length > 0) {
this.addOrganizationId = collection[0].organizationId;
this.addCollectionIds = [this.activeFilter.selectedCollectionId];
2021-12-20 15:47:17 +01:00
}
} else if (this.activeFilter.selectedOrganizationId) {
this.addOrganizationId = this.activeFilter.selectedOrganizationId;
}
if (this.activeFilter.selectedFolderId && this.activeFilter.selectedFolder) {
this.folderId = this.activeFilter.selectedFolderId;
2021-12-20 15:47:17 +01:00
}
}
private async canNavigateAway(action: string, cipher?: CipherView) {
// Don't navigate to same route
if (this.action === action && (cipher == null || this.cipherId === cipher.id)) {
return false;
} else if (this.dirtyInput() && (await this.wantsToSaveChanges())) {
return false;
2021-12-20 15:47:17 +01:00
}
return true;
}
private async passwordReprompt(cipher: CipherView) {
2021-12-20 15:47:17 +01:00
return (
cipher.reprompt === CipherRepromptType.None ||
(await this.passwordRepromptService.showPasswordPrompt())
2021-12-20 15:47:17 +01:00
);
}
2018-01-16 22:12:26 +01:00
}