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.

768 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
2022-06-14 17:10:53 +02:00
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
import { ModalService } from "@bitwarden/angular/services/modal.service";
[SG-360] Remove the /modules/ folder (#3225) * Move Web's SharedModule to /app/shared/ This commit relocates `SharedModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `SharedModule`. * Move /modules/pipes to /shared/pipes This commit relocates `PipesModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `PipesModule`. * Move LooseComponentsModule to /shared/ This commit relocates `LooseComponentsModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `LooseComponentsModule`. * Move VerticalStepperModule to /shared/ This commit relocates `VerticalStepperModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `VerticalStepperModule`. * Move TrialInitiationModule to /shared/ This commit relocates `TrialInitiationModule` & `RegisterFormModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `TrialInitiationModule` or `RegisterFormModule`. * Move /modules/organization to /organization This commit relocates all modules in `/app/modules/organization` to `/app/organization` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move /modules/vault/ to /vault This commit relocates the IndividualVaultModule to `/app/modules/vault`, and the OrganizationVaultModule to `/app/organization/vault` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move VaultFiltersModule to /vault This commit relocates the `VaultFilterModule` to `/app/vault/vault-filter`, and the OrganizationVaultFilterComponent to `/app/organization/vault/vault-filter` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Remove the /modules/ folder from desktop This commit relocates the `VaultFilterModule` to `/app/vault/vault-filter`, and the OrganizationVaultFilterComponent to `/app/organization/vault/vault-filter` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move Libs' VaultFiltersComponent to /vault/ This commit moves the lib's logic for `VaultFiltersModule` from `/modules/` to `/vault/` All other changes are just to adjust imports that reference the moved files. * Rename VaultModule -> SharedVaultModule * Rename IndividualVaultModule -> VaultModule * Rename OrganizationVaultModule -> VaultModule * Rename OrganizationVaultFilterComponent Rename OrganizationVaultFilterComponent to VaultFilterComponent * Seperate the two VaultFilterComponents This commit seperate the `OrganizationVaultFilterComponent` from the `VaultFilerModule`, which is only used by the individual vault. A `VaultFilterSharedModule` was created to declare shared components and provide shared services between the two implementations. This was done to align with best practices for NgModules. * [r] Move VerticalStepperModule to /account/ More specifically, /account/trial/ * [r] Declare PaymentComponent in LooseComponentsModule `PaymentComponent` is not reused across domains and should not be declared in `SharedModule`. I've moved it to `LooseComponentsModule` for now, but later it will need to be exported from a `SettingsModule`. * [r] Declare TaxInfoComponent in LooseComponentsModule * [r] Reloacte Pipes out of /shared/ * [r] Extract locales out of SharedModule * [r] Add documentation to shared module * [r] Cleanup imports * [r] Use an index.ts file for /shared/ * [r] Add eslint rule restricting access to /shared/ Co-authored-by: Hinton <hinton@users.noreply.github.com>
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 { EventService } from "@bitwarden/common/abstractions/event.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
2022-06-14 17:10:53 +02:00
import { TotpService } from "@bitwarden/common/abstractions/totp.service";
import { CipherRepromptType } from "@bitwarden/common/enums/cipherRepromptType";
import { CipherType } from "@bitwarden/common/enums/cipherType";
import { EventType } from "@bitwarden/common/enums/eventType";
import { CipherView } from "@bitwarden/common/models/view/cipher.view";
import { FolderView } from "@bitwarden/common/models/view/folder.view";
2021-12-20 15:47:17 +01:00
import { invokeMenu, RendererMenuItem } from "../../utils";
2022-02-24 20:50:19 +01:00
import { SearchBarService } from "../layout/search/search-bar.service";
import { AddEditComponent } from "./add-edit.component";
import { AttachmentsComponent } from "./attachments.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";
[SG-360] Remove the /modules/ folder (#3225) * Move Web's SharedModule to /app/shared/ This commit relocates `SharedModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `SharedModule`. * Move /modules/pipes to /shared/pipes This commit relocates `PipesModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `PipesModule`. * Move LooseComponentsModule to /shared/ This commit relocates `LooseComponentsModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `LooseComponentsModule`. * Move VerticalStepperModule to /shared/ This commit relocates `VerticalStepperModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `VerticalStepperModule`. * Move TrialInitiationModule to /shared/ This commit relocates `TrialInitiationModule` & `RegisterFormModule` from `/app/modules` to `/app/shared` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference `TrialInitiationModule` or `RegisterFormModule`. * Move /modules/organization to /organization This commit relocates all modules in `/app/modules/organization` to `/app/organization` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move /modules/vault/ to /vault This commit relocates the IndividualVaultModule to `/app/modules/vault`, and the OrganizationVaultModule to `/app/organization/vault` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move VaultFiltersModule to /vault This commit relocates the `VaultFilterModule` to `/app/vault/vault-filter`, and the OrganizationVaultFilterComponent to `/app/organization/vault/vault-filter` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Remove the /modules/ folder from desktop This commit relocates the `VaultFilterModule` to `/app/vault/vault-filter`, and the OrganizationVaultFilterComponent to `/app/organization/vault/vault-filter` to align with [ADR #11](https://adr.bitwarden.com/decisions/0011-angular-folder-structure) All other changes are just to adjust imports that reference the moved modules. * Move Libs' VaultFiltersComponent to /vault/ This commit moves the lib's logic for `VaultFiltersModule` from `/modules/` to `/vault/` All other changes are just to adjust imports that reference the moved files. * Rename VaultModule -> SharedVaultModule * Rename IndividualVaultModule -> VaultModule * Rename OrganizationVaultModule -> VaultModule * Rename OrganizationVaultFilterComponent Rename OrganizationVaultFilterComponent to VaultFilterComponent * Seperate the two VaultFilterComponents This commit seperate the `OrganizationVaultFilterComponent` from the `VaultFilerModule`, which is only used by the individual vault. A `VaultFilterSharedModule` was created to declare shared components and provide shared services between the two implementations. This was done to align with best practices for NgModules. * [r] Move VerticalStepperModule to /account/ More specifically, /account/trial/ * [r] Declare PaymentComponent in LooseComponentsModule `PaymentComponent` is not reused across domains and should not be declared in `SharedModule`. I've moved it to `LooseComponentsModule` for now, but later it will need to be exported from a `SettingsModule`. * [r] Declare TaxInfoComponent in LooseComponentsModule * [r] Reloacte Pipes out of /shared/ * [r] Extract locales out of SharedModule * [r] Add documentation to shared module * [r] Cleanup imports * [r] Use an index.ts file for /shared/ * [r] Add eslint rule restricting access to /shared/ Co-authored-by: Hinton <hinton@users.noreply.github.com>
2022-08-08 21:08:35 +02:00
import { VaultFilterComponent } from "./vault-filter/vault-filter.component";
import { VaultItemsComponent } from "./vault-items.component";
2022-02-24 20:50:19 +01:00
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;
@ViewChild(VaultItemsComponent, { static: true }) vaultItemsComponent: VaultItemsComponent;
@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.vaultItemsComponent.reload(this.activeFilter.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":
this.vaultItemsComponent.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() {
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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.vaultItemsComponent.reload(this.activeFilter.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.vaultItemsComponent.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.vaultItemsComponent.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.vaultItemsComponent.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;
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
2018-06-09 19:29:23 +02:00
childComponent.onUploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
2018-06-09 19:29:23 +02:00
childComponent.onDeletedAttachment.subscribe(() => (madeAttachmentChanges = true));
2021-12-20 15:47:17 +01:00
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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.vaultItemsComponent.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
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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.vaultItemsComponent.refresh();
2021-12-20 15:47:17 +01:00
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
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
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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
);
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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.vaultItemsComponent.reload(
this.activeFilter.buildFilter(),
vaultFilter.status === "trash"
);
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
}
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
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
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
}
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
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
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
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
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
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
}