1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00

[PM-6564] migrate auth toasts to CL toastService (#10665)

* migrate auth toasts to CL toastService

* fix component args

* fix component args

* fix specs

* fix toastService args
This commit is contained in:
Jordan Aasen
2024-08-27 10:33:58 -07:00
committed by GitHub
parent e255d84121
commit 9041a4cd4c
75 changed files with 782 additions and 457 deletions

View File

@@ -6,6 +6,7 @@ import { EnvironmentService } from "@bitwarden/common/platform/abstractions/envi
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { ToastService } from "@bitwarden/components";
@Component({
selector: "app-accessibility-cookie",
@@ -25,6 +26,7 @@ export class AccessibilityCookieComponent {
protected environmentService: EnvironmentService,
protected i18nService: I18nService,
protected ngZone: NgZone,
private toastService: ToastService,
) {}
registerhCaptcha() {
@@ -42,28 +44,28 @@ export class AccessibilityCookieComponent {
}
onCookieSavedSuccess() {
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("accessibilityCookieSaved"),
);
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("accessibilityCookieSaved"),
});
}
onCookieSavedFailure() {
this.platformUtilsService.showToast(
"error",
null,
this.i18nService.t("noAccessibilityCookieSaved"),
);
this.toastService.showToast({
variant: "error",
title: null,
message: this.i18nService.t("noAccessibilityCookieSaved"),
});
}
async submit() {
if (Utils.getHostname(this.accessibilityForm.value.link) !== "accounts.hcaptcha.com") {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
this.i18nService.t("invalidUrl"),
);
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccurred"),
message: this.i18nService.t("invalidUrl"),
});
return;
}
this.listenForCookie = true;

View File

@@ -13,6 +13,7 @@ import {
CalloutModule,
DialogModule,
DialogService,
ToastService,
} from "@bitwarden/components";
import { UserVerificationComponent } from "../app/components/user-verification.component";
@@ -41,6 +42,7 @@ export class DeleteAccountComponent {
private platformUtilsService: PlatformUtilsService,
private formBuilder: FormBuilder,
private accountApiService: AccountApiService,
private toastService: ToastService,
) {}
static open(dialogService: DialogService): DialogRef<DeleteAccountComponent> {
@@ -54,10 +56,10 @@ export class DeleteAccountComponent {
submit = async () => {
const verification = this.deleteForm.get("verification").value;
await this.accountApiService.deleteAccount(verification);
this.platformUtilsService.showToast(
"success",
this.i18nService.t("accountDeleted"),
this.i18nService.t("accountDeletedDesc"),
);
this.toastService.showToast({
variant: "success",
title: this.i18nService.t("accountDeleted"),
message: this.i18nService.t("accountDeletedDesc"),
});
};
}

View File

@@ -5,6 +5,7 @@ import { ModalService } from "@bitwarden/angular/services/modal.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";
@Component({
selector: "app-environment",
@@ -16,7 +17,8 @@ export class EnvironmentComponent extends BaseEnvironmentComponent {
environmentService: EnvironmentService,
i18nService: I18nService,
modalService: ModalService,
toastService: ToastService,
) {
super(platformUtilsService, environmentService, i18nService, modalService);
super(platformUtilsService, environmentService, i18nService, modalService, toastService);
}
}

View File

@@ -7,6 +7,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";
@Component({
selector: "app-hint",
@@ -20,7 +21,16 @@ export class HintComponent extends BaseHintComponent {
apiService: ApiService,
logService: LogService,
loginEmailService: LoginEmailServiceAbstraction,
toastService: ToastService,
) {
super(router, i18nService, apiService, platformUtilsService, logService, loginEmailService);
super(
router,
i18nService,
apiService,
platformUtilsService,
logService,
loginEmailService,
toastService,
);
}
}

View File

@@ -34,7 +34,7 @@ import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/sp
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { UserId } from "@bitwarden/common/types/guid";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { BiometricsService } from "src/platform/main/biometric";
@@ -62,6 +62,7 @@ describe("LockComponent", () => {
let platformUtilsServiceMock: MockProxy<PlatformUtilsService>;
let activatedRouteMock: MockProxy<ActivatedRoute>;
let mockMasterPasswordService: FakeMasterPasswordService;
let mockToastService: MockProxy<ToastService>;
const mockUserId = Utils.newGuid() as UserId;
const accountService: FakeAccountService = mockAccountServiceWith(mockUserId);
@@ -72,6 +73,7 @@ describe("LockComponent", () => {
messagingServiceMock = mock<MessagingService>();
broadcasterServiceMock = mock<BroadcasterService>();
platformUtilsServiceMock = mock<PlatformUtilsService>();
mockToastService = mock<ToastService>();
activatedRouteMock = mock<ActivatedRoute>();
activatedRouteMock.queryParams = mock<ActivatedRoute["queryParams"]>();
@@ -187,6 +189,10 @@ describe("LockComponent", () => {
provide: SyncService,
useValue: mock<SyncService>(),
},
{
provide: ToastService,
useValue: mockToastService,
},
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();

View File

@@ -28,7 +28,7 @@ import { BiometricStateService } from "@bitwarden/common/platform/biometrics/bio
import { BiometricsService } from "@bitwarden/common/platform/biometrics/biometric.service";
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
const BroadcasterSubscriptionId = "LockComponent";
@@ -72,6 +72,7 @@ export class LockComponent extends BaseLockComponent implements OnInit, OnDestro
authService: AuthService,
kdfConfigService: KdfConfigService,
syncService: SyncService,
toastService: ToastService,
) {
super(
masterPasswordService,
@@ -100,6 +101,7 @@ export class LockComponent extends BaseLockComponent implements OnInit, OnDestro
authService,
kdfConfigService,
syncService,
toastService,
);
}

View File

@@ -18,6 +18,7 @@ import {
ButtonModule,
DialogModule,
DialogService,
ToastService,
} from "@bitwarden/components";
const RequestTimeOut = 60000 * 15; //15 Minutes
@@ -54,6 +55,7 @@ export class LoginApprovalComponent implements OnInit, OnDestroy {
protected appIdService: AppIdService,
protected cryptoService: CryptoService,
private dialogRef: DialogRef,
private toastService: ToastService,
) {
this.notificationId = params.notificationId;
}
@@ -117,11 +119,11 @@ export class LoginApprovalComponent implements OnInit, OnDestroy {
private async retrieveAuthRequestAndRespond(approve: boolean) {
this.authRequestResponse = await this.apiService.getAuthRequest(this.notificationId);
if (this.authRequestResponse.requestApproved || this.authRequestResponse.responseDate != null) {
this.platformUtilsService.showToast(
"info",
null,
this.i18nService.t("thisRequestIsNoLongerValid"),
);
this.toastService.showToast({
variant: "info",
title: null,
message: this.i18nService.t("thisRequestIsNoLongerValid"),
});
} else {
const loginResponse = await this.authRequestService.approveOrDenyAuthRequest(
approve,
@@ -133,21 +135,21 @@ export class LoginApprovalComponent implements OnInit, OnDestroy {
showResultToast(loginResponse: AuthRequestResponse) {
if (loginResponse.requestApproved) {
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t(
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(
"logInConfirmedForEmailOnDevice",
this.email,
loginResponse.requestDeviceType,
),
);
});
} else {
this.platformUtilsService.showToast(
"info",
null,
this.i18nService.t("youDeniedALogInAttemptFromAnotherDevice"),
);
this.toastService.showToast({
variant: "info",
title: null,
message: this.i18nService.t("youDeniedALogInAttemptFromAnotherDevice"),
});
}
}
@@ -186,11 +188,11 @@ export class LoginApprovalComponent implements OnInit, OnDestroy {
} else {
clearInterval(this.interval);
this.dialogRef.close();
this.platformUtilsService.showToast(
"info",
null,
this.i18nService.t("loginRequestHasAlreadyExpired"),
);
this.toastService.showToast({
variant: "info",
title: null,
message: this.i18nService.t("loginRequestHasAlreadyExpired"),
});
}
}
}

View File

@@ -23,6 +23,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { EnvironmentComponent } from "../environment.component";
@@ -58,6 +59,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
loginStrategyService: LoginStrategyServiceAbstraction,
accountService: AccountService,
private location: Location,
toastService: ToastService,
) {
super(
router,
@@ -78,6 +80,7 @@ export class LoginViaAuthRequestComponent extends BaseLoginWithDeviceComponent {
deviceTrustService,
authRequestService,
loginStrategyService,
toastService,
);
super.onSuccessfulLogin = () => {

View File

@@ -25,6 +25,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { EnvironmentComponent } from "../environment.component";
@@ -74,6 +75,7 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest
ssoLoginService: SsoLoginServiceAbstraction,
webAuthnLoginService: WebAuthnLoginServiceAbstraction,
registerRouteService: RegisterRouteService,
toastService: ToastService,
) {
super(
devicesApiService,
@@ -95,6 +97,7 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest
ssoLoginService,
webAuthnLoginService,
registerRouteService,
toastService,
);
super.onSuccessfulLogin = () => {
return syncService.fullSync(true);
@@ -162,11 +165,11 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest
async continue() {
await super.validateEmail();
if (!this.formGroup.controls.email.valid) {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccured"),
this.i18nService.t("invalidEmail"),
);
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccured"),
message: this.i18nService.t("invalidEmail"),
});
return;
}
this.focusInput();

View File

@@ -14,7 +14,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
const BroadcasterSubscriptionId = "RegisterComponent";
@@ -41,6 +41,7 @@ export class RegisterComponent extends BaseRegisterComponent implements OnInit,
logService: LogService,
auditService: AuditService,
dialogService: DialogService,
toastService: ToastService,
) {
super(
formValidationErrorService,
@@ -57,6 +58,7 @@ export class RegisterComponent extends BaseRegisterComponent implements OnInit,
logService,
auditService,
dialogService,
toastService,
);
}

View File

@@ -22,7 +22,7 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { MasterKey, UserKey } from "@bitwarden/common/types/key";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
const BroadcasterSubscriptionId = "SetPasswordComponent";
@@ -56,6 +56,7 @@ export class SetPasswordComponent extends BaseSetPasswordComponent implements On
dialogService: DialogService,
kdfConfigService: KdfConfigService,
encryptService: EncryptService,
toastService: ToastService,
) {
super(
accountService,
@@ -79,6 +80,7 @@ export class SetPasswordComponent extends BaseSetPasswordComponent implements On
dialogService,
kdfConfigService,
encryptService,
toastService,
);
}

View File

@@ -18,6 +18,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
@Component({
@@ -43,6 +44,7 @@ export class SsoComponent extends BaseSsoComponent {
configService: ConfigService,
masterPasswordService: InternalMasterPasswordServiceAbstraction,
accountService: AccountService,
toastService: ToastService,
) {
super(
ssoLoginService,
@@ -61,6 +63,7 @@ export class SsoComponent extends BaseSsoComponent {
configService,
masterPasswordService,
accountService,
toastService,
);
super.onSuccessfulLogin = async () => {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.