From 22b16b20a7a5509bda5bd975077c81758c583457 Mon Sep 17 00:00:00 2001 From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:53:20 -0500 Subject: [PATCH] remove user match strategy on the web (#11385) --- .../autofill-options.component.spec.ts | 4 ++++ .../autofill-options/autofill-options.component.ts | 10 ++++++++-- .../autofill-options/uri-option.component.spec.ts | 7 +++++++ .../autofill-options/uri-option.component.ts | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.spec.ts b/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.spec.ts index e4dba11525..f1e5af2868 100644 --- a/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.spec.ts +++ b/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.spec.ts @@ -7,6 +7,7 @@ import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/s import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { UriMatchStrategy } from "@bitwarden/common/models/domain/domain-service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view"; import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; @@ -23,10 +24,12 @@ describe("AutofillOptionsComponent", () => { let liveAnnouncer: MockProxy; let domainSettingsService: MockProxy; let autofillSettingsService: MockProxy; + let platformUtilsService: MockProxy; beforeEach(async () => { cipherFormContainer = mock(); liveAnnouncer = mock(); + platformUtilsService = mock(); domainSettingsService = mock(); domainSettingsService.defaultUriMatchStrategy$ = new BehaviorSubject(null); @@ -45,6 +48,7 @@ describe("AutofillOptionsComponent", () => { { provide: LiveAnnouncer, useValue: liveAnnouncer }, { provide: DomainSettingsService, useValue: domainSettingsService }, { provide: AutofillSettingsServiceAbstraction, useValue: autofillSettingsService }, + { provide: PlatformUtilsService, useValue: platformUtilsService }, ], }).compileComponents(); diff --git a/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.ts b/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.ts index eb5767b534..40f7eeecf0 100644 --- a/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.ts +++ b/libs/vault/src/cipher-form/components/autofill-options/autofill-options.component.ts @@ -3,13 +3,15 @@ import { AsyncPipe, NgForOf, NgIf } from "@angular/common"; import { Component, OnInit, QueryList, ViewChildren } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { FormBuilder, ReactiveFormsModule } from "@angular/forms"; -import { Subject, switchMap, take } from "rxjs"; +import { filter, Subject, switchMap, take } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; +import { ClientType } from "@bitwarden/common/enums"; import { UriMatchStrategySetting } from "@bitwarden/common/models/domain/domain-service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view"; import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; import { @@ -69,7 +71,10 @@ export class AutofillOptionsComponent implements OnInit { return this.autofillOptionsForm.controls.uris.controls; } - protected defaultMatchDetection$ = this.domainSettingsService.defaultUriMatchStrategy$; + protected defaultMatchDetection$ = this.domainSettingsService.defaultUriMatchStrategy$.pipe( + // The default match detection should only be shown when used on the browser + filter(() => this.platformUtilsService.getClientType() == ClientType.Browser), + ); protected autofillOnPageLoadEnabled$ = this.autofillSettingsService.autofillOnPageLoad$; protected autofillOptions: { label: string; value: boolean | null }[] = [ @@ -90,6 +95,7 @@ export class AutofillOptionsComponent implements OnInit { private liveAnnouncer: LiveAnnouncer, private domainSettingsService: DomainSettingsService, private autofillSettingsService: AutofillSettingsServiceAbstraction, + private platformUtilsService: PlatformUtilsService, ) { this.cipherFormContainer.registerChildForm("autoFillOptions", this.autofillOptionsForm); diff --git a/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.spec.ts b/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.spec.ts index cf298b19ac..fdb306ff76 100644 --- a/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.spec.ts +++ b/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.spec.ts @@ -51,6 +51,13 @@ describe("UriOptionComponent", () => { expect(component).toBeTruthy(); }); + it("should not update the default uri match strategy label when it is null", () => { + component.defaultMatchDetection = null; + fixture.detectChanges(); + + expect(component["uriMatchOptions"][0].label).toBe("default"); + }); + it("should update the default uri match strategy label", () => { component.defaultMatchDetection = UriMatchStrategy.Exact; fixture.detectChanges(); diff --git a/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.ts b/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.ts index a7741ae1bc..82870befa1 100644 --- a/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.ts +++ b/libs/vault/src/cipher-form/components/autofill-options/uri-option.component.ts @@ -83,6 +83,11 @@ export class UriOptionComponent implements ControlValueAccessor { */ @Input({ required: true }) set defaultMatchDetection(value: UriMatchStrategySetting) { + // The default selection has a value of `null` avoid showing "Default (Default)" + if (!value) { + return; + } + this.uriMatchOptions[0].label = this.i18nService.t( "defaultLabel", this.uriMatchOptions.find((o) => o.value === value)?.label,