From 7bae3d9f6b2ef83efc5c186b72585193af6c211e Mon Sep 17 00:00:00 2001 From: Patrick Pimentel Date: Wed, 11 Jun 2025 21:19:46 -0600 Subject: [PATCH] feat(change-password-component): Change Password Update [18720] - Minor fixes. --- apps/browser/src/_locales/en/messages.json | 3 +++ apps/browser/src/popup/app-routing.module.ts | 2 +- .../app/auth/settings/change-password.component.ts | 3 +-- .../change-password/change-password.component.ts | 5 ++--- .../change-password.service.abstraction.ts | 5 ++++- .../default-change-password.service.ts | 4 ++-- .../models/domain/master-password-policy-options.ts | 11 ++++++++++- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 09c997bafaa..298c4db01f5 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -3421,6 +3421,9 @@ "logInRequestSent": { "message": "Request sent" }, + "masterPasswordChanged": { + "message": "Master password saved" + }, "exposedMasterPassword": { "message": "Exposed Master Password" }, diff --git a/apps/browser/src/popup/app-routing.module.ts b/apps/browser/src/popup/app-routing.module.ts index c735595b562..e869275233e 100644 --- a/apps/browser/src/popup/app-routing.module.ts +++ b/apps/browser/src/popup/app-routing.module.ts @@ -719,7 +719,7 @@ export class NoRouteReuseStrategy implements RouteReuseStrategy { RouterModule.forRoot(routes, { useHash: true, onSameUrlNavigation: "reload", - /*enableTracing: true,*/ + enableTracing: true, }), ], exports: [RouterModule], diff --git a/apps/web/src/app/auth/settings/change-password.component.ts b/apps/web/src/app/auth/settings/change-password.component.ts index 15d106057ba..8faeee16cd2 100644 --- a/apps/web/src/app/auth/settings/change-password.component.ts +++ b/apps/web/src/app/auth/settings/change-password.component.ts @@ -244,8 +244,7 @@ export class ChangePasswordComponent await this.masterPasswordApiService.postPassword(request); this.toastService.showToast({ variant: "success", - title: this.i18nService.t("masterPasswordChanged"), - message: this.i18nService.t("masterPasswordChangedDesc"), + message: this.i18nService.t("masterPasswordChanged"), }); this.messagingService.send("logout"); } catch { diff --git a/libs/auth/src/angular/change-password/change-password.component.ts b/libs/auth/src/angular/change-password/change-password.component.ts index c4bd7f12b0b..26a6118e1d6 100644 --- a/libs/auth/src/angular/change-password/change-password.component.ts +++ b/libs/auth/src/angular/change-password/change-password.component.ts @@ -43,7 +43,7 @@ export class ChangePasswordComponent implements OnInit { @Input() inputPasswordFlow: InputPasswordFlow = InputPasswordFlow.ChangePassword; activeAccount: Account | null = null; - email!: string; + email?: string; userId?: UserId; masterPasswordPolicyOptions?: MasterPasswordPolicyOptions; initializing = true; @@ -157,8 +157,7 @@ export class ChangePasswordComponent implements OnInit { this.toastService.showToast({ variant: "success", - title: this.i18nService.t("masterPasswordChanged"), - message: this.i18nService.t("masterPasswordChangedDesc"), + message: this.i18nService.t("masterPasswordChanged"), }); this.messagingService.send("logout"); diff --git a/libs/auth/src/angular/change-password/change-password.service.abstraction.ts b/libs/auth/src/angular/change-password/change-password.service.abstraction.ts index c6150968887..5cbd012ec6c 100644 --- a/libs/auth/src/angular/change-password/change-password.service.abstraction.ts +++ b/libs/auth/src/angular/change-password/change-password.service.abstraction.ts @@ -32,7 +32,10 @@ export abstract class ChangePasswordService { * @param userId the `userId` * @throws if the `userId`, `currentMasterKey`, or `currentServerMasterKeyHash` is not found */ - abstract changePassword(passwordInputResult: PasswordInputResult, userId: UserId): Promise; + abstract changePassword( + passwordInputResult: PasswordInputResult, + userId: UserId | null, + ): Promise; /** * Changes the user's password and re-encrypts the user key with the `newMasterKey`. diff --git a/libs/auth/src/angular/change-password/default-change-password.service.ts b/libs/auth/src/angular/change-password/default-change-password.service.ts index ac2e1e3c1c1..e024cd545be 100644 --- a/libs/auth/src/angular/change-password/default-change-password.service.ts +++ b/libs/auth/src/angular/change-password/default-change-password.service.ts @@ -27,7 +27,7 @@ export class DefaultChangePasswordService implements ChangePasswordService { private async preparePasswordChange( passwordInputResult: PasswordInputResult, - userId: UserId, + userId: UserId | null, ): Promise<[UserKey, EncString]> { if (!userId) { throw new Error("userId not found"); @@ -51,7 +51,7 @@ export class DefaultChangePasswordService implements ChangePasswordService { ); } - async changePassword(passwordInputResult: PasswordInputResult, userId: UserId) { + async changePassword(passwordInputResult: PasswordInputResult, userId: UserId | null) { const newMasterKeyEncryptedUserKey = await this.preparePasswordChange( passwordInputResult, userId, diff --git a/libs/common/src/admin-console/models/domain/master-password-policy-options.ts b/libs/common/src/admin-console/models/domain/master-password-policy-options.ts index 340b21aaf0d..8447f8cf8e0 100644 --- a/libs/common/src/admin-console/models/domain/master-password-policy-options.ts +++ b/libs/common/src/admin-console/models/domain/master-password-policy-options.ts @@ -19,7 +19,16 @@ export class MasterPasswordPolicyOptions extends Domain { enforceOnLogin = false; static fromResponse(policy: MasterPasswordPolicyResponse): MasterPasswordPolicyOptions { - if (policy == null) { + // Check if the policy is null or if all the values in the response object is null. + // Exclude the response object because the MasterPasswordPolicyResponse extends + // BaseResponse and we should omit that when checking for null values. Doing this + // programmatically makes this less brittle for future contract changes. + if ( + policy == null || + Object.entries(policy) + .filter(([key]) => key !== "response") + .every(([, value]) => value == null) + ) { return null; } const options = new MasterPasswordPolicyOptions();