1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 13:40:06 +00:00

feat(change-password-component): Change Password Update [18720] - Stopping work and going to switch to a new branch to pare down some of the solutions that were made to get this over the finish line

This commit is contained in:
Patrick Pimentel
2025-06-24 14:17:47 -04:00
parent e6913dca03
commit 6e3c315507
8 changed files with 112 additions and 38 deletions

View File

@@ -191,6 +191,15 @@ import { ExtensionAnonLayoutWrapperDataService } from "../components/extension-a
import { DebounceNavigationService } from "./debounce-navigation.service";
import { InitService } from "./init.service";
import { PopupCloseWarningService } from "./popup-close-warning.service";
import {
MasterPasswordPolicyServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/master-password-policy.service.abstraction";
import {
DefaultMasterPasswordPolicyService
} from "@bitwarden/common/admin-console/services/policy/default-master-password-policy.service";
import {
PolicyApiServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
const OBSERVABLE_LARGE_OBJECT_MEMORY_STORAGE = new SafeInjectionToken<
AbstractStorageService & ObservableStorageService
@@ -554,6 +563,11 @@ const safeProviders: SafeProvider[] = [
useClass: DefaultOrganizationInviteService,
deps: [],
}),
safeProvider({
provide: MasterPasswordPolicyServiceAbstraction,
useClass: DefaultMasterPasswordPolicyService,
deps: [PolicyApiServiceAbstraction],
}),
safeProvider({
provide: LockComponentService,
useClass: ExtensionLockComponentService,

View File

@@ -142,6 +142,15 @@ import { DesktopSetPasswordJitService } from "./desktop-set-password-jit.service
import { InitService } from "./init.service";
import { NativeMessagingManifestService } from "./native-messaging-manifest.service";
import { RendererCryptoFunctionService } from "./renderer-crypto-function.service";
import {
MasterPasswordPolicyServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/master-password-policy.service.abstraction";
import {
DefaultMasterPasswordPolicyService
} from "@bitwarden/common/admin-console/services/policy/default-master-password-policy.service";
import {
PolicyApiServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
const RELOAD_CALLBACK = new SafeInjectionToken<() => any>("RELOAD_CALLBACK");
@@ -383,16 +392,20 @@ const safeProviders: SafeProvider[] = [
useValue: DefaultOrganizationInviteService,
deps: [],
}),
safeProvider({
provide: MasterPasswordPolicyServiceAbstraction,
useClass: DefaultMasterPasswordPolicyService,
deps: [PolicyApiServiceAbstraction],
}),
safeProvider({
provide: SetPasswordJitService,
useClass: DesktopSetPasswordJitService,
deps: [
ApiService,
MasterPasswordApiService,
KeyService,
EncryptService,
I18nServiceAbstraction,
KdfConfigService,
KeyService,
MasterPasswordApiService,
InternalMasterPasswordServiceAbstraction,
OrganizationApiServiceAbstraction,
OrganizationUserApiService,

View File

@@ -41,11 +41,17 @@ import {
} from "@bitwarden/auth/common";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
import {
MasterPasswordPolicyServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/master-password-policy.service.abstraction";
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
import {
InternalPolicyService,
PolicyService,
} from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import {
DefaultMasterPasswordPolicyService
} from "@bitwarden/common/admin-console/services/policy/default-master-password-policy.service";
import { AccountApiService as AccountApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/account-api.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
@@ -250,6 +256,11 @@ const safeProviders: SafeProvider[] = [
useClass: WebOrganizationInviteService,
deps: [GlobalStateProvider],
}),
safeProvider({
provide: MasterPasswordPolicyServiceAbstraction,
useClass: DefaultMasterPasswordPolicyService,
deps: [PolicyApiServiceAbstraction],
}),
safeProvider({
provide: RegistrationFinishServiceAbstraction,
useClass: WebRegistrationFinishService,

View File

@@ -15,11 +15,9 @@ import { SyncService } from "@bitwarden/common/platform/sync";
import { UserId } from "@bitwarden/common/types/guid";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
// eslint-disable-next-line no-restricted-imports
import { DialogService, ToastService } from "@bitwarden/components";
import { AnonLayoutWrapperDataService, DialogService, ToastService, Icons } from "@bitwarden/components";
import { I18nPipe } from "@bitwarden/ui-common";
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
import { LockIcon } from "../icons";
import {
InputPasswordComponent,
InputPasswordFlow,
@@ -94,38 +92,41 @@ export class ChangePasswordComponent implements OnInit {
);
// New Master Password Policy Options service
const orgInvite = await this.organizationInviteService.getOrganizationInvite();
// const orgInvite = await this.organizationInviteService.getOrganizationInvite();
switch (this.forceSetPasswordReason) {
case ForceSetPasswordReason.WeakMasterPassword:
if (orgInvite) {
if (!orgInvite.token) {
this.logService.error("No org token found when trying to retrieve policies.");
return;
}
this.masterPasswordPolicyOptions =
await this.masterPasswordPolicyOptionsService.getForInvitedMember(orgInvite.token);
} else {
this.masterPasswordPolicyOptions =
await this.masterPasswordPolicyOptionsService.getByUserId(this.userId);
}
break;
case ForceSetPasswordReason.AdminForcePasswordReset:
default:
this.masterPasswordPolicyOptions =
await this.masterPasswordPolicyOptionsService.getByUserId(this.userId);
break;
}
// switch (this.forceSetPasswordReason) {
// case ForceSetPasswordReason.WeakMasterPassword:
// if (orgInvite) {
// if (!orgInvite.token) {
// this.logService.error("No org token found when trying to retrieve policies.");
// return;
// }
// // Jared I think you wanted this to fetch the token inside the function call but we have
// // it here and it could make sense to just pass it in? but it does go against the whole
// // self-sufficient notion of this service.
// this.masterPasswordPolicyOptions =
// await this.masterPasswordPolicyOptionsService.getForInvitedMember(orgInvite.token);
// } else {
// this.masterPasswordPolicyOptions =
// await this.masterPasswordPolicyOptionsService.getByUserId(this.userId);
// }
// break;
// case ForceSetPasswordReason.AdminForcePasswordReset:
// default:
// this.masterPasswordPolicyOptions =
// await this.masterPasswordPolicyOptionsService.getByUserId(this.userId);
// break;
// }
if (this.forceSetPasswordReason === ForceSetPasswordReason.AdminForcePasswordReset) {
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageIcon: LockIcon,
pageIcon: Icons.LockIcon,
pageTitle: { key: "updateMasterPassword" },
pageSubtitle: { key: "accountRecoveryUpdateMasterPasswordSubtitle" },
});
} else if (this.forceSetPasswordReason === ForceSetPasswordReason.WeakMasterPassword) {
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageIcon: LockIcon,
pageIcon: Icons.LockIcon,
pageTitle: { key: "updateMasterPassword" },
pageSubtitle: { key: "updateMasterPasswordSubtitle" },
maxWidth: "lg",

View File

@@ -6,7 +6,7 @@ export abstract class MasterPasswordPolicyServiceAbstraction {
* Used for a logged-in user is changing their password. Would probably be deprecated once
* PolicyService is refactored.
*/
abstract getByUserId: (loggedInUserId: UserId) => Promise<MasterPasswordPolicyOptions>;
abstract getByUserId: (userId: UserId) => Promise<MasterPasswordPolicyOptions>;
/**
* Used to evaluate compliance before accepting an invite.
@@ -16,7 +16,7 @@ export abstract class MasterPasswordPolicyServiceAbstraction {
/**
* Used when resetting a grantor's password during an emergency access takeover.
*/
abstract getForEmergencyAccessGrantor: (grantorUserId: UserId) => MasterPasswordPolicyOptions;
// abstract getForEmergencyAccessGrantor: (grantorUserId: UserId) => MasterPasswordPolicyOptions;
/**
* Used when resetting a member's password during an account recovery. Gets the master
@@ -24,5 +24,5 @@ export abstract class MasterPasswordPolicyServiceAbstraction {
* that an admin is keeping the user in compliance with the users whose password
* they are setting and not using the policies that they are a part of.
*/
abstract getForAccountRecoveryMember: (userId: UserId) => Promise<MasterPasswordPolicyOptions>;
// abstract getForAccountRecoveryMember: (userId: UserId) => Promise<MasterPasswordPolicyOptions>;
}

View File

@@ -1,5 +1,3 @@
import { MasterPasswordPolicyResponse } from "@bitwarden/common/auth/models/response/master-password-policy.response";
import { ListResponse } from "../../../models/response/list.response";
import { PolicyType } from "../../enums";
import { MasterPasswordPolicyOptions } from "../../models/domain/master-password-policy-options";
@@ -11,8 +9,6 @@ export abstract class PolicyApiServiceAbstraction {
abstract getPolicy: (organizationId: string, type: PolicyType) => Promise<PolicyResponse>;
abstract getPolicies: (organizationId: string) => Promise<ListResponse<PolicyResponse>>;
abstract getMasterPasswordPoliciesForAcceptedOrConfirmedUser: () => Promise<MasterPasswordPolicyResponse>;
abstract getPoliciesByToken: (
organizationId: string,
token: string,
@@ -20,8 +16,11 @@ export abstract class PolicyApiServiceAbstraction {
organizationUserId: string,
) => Promise<Policy[] | undefined>;
/**
* This takes an organization id to get org policies for. The user is inferred by the
*/
abstract getMasterPasswordPolicyOptsForOrgUser: (
orgId: string,
organizationId: string,
) => Promise<MasterPasswordPolicyOptions | null>;
abstract putPolicy: (
organizationId: string,

View File

@@ -0,0 +1,36 @@
import {
MasterPasswordPolicyServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/master-password-policy.service.abstraction";
import {
PolicyApiServiceAbstraction
} from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
import {
MasterPasswordPolicyOptions
} from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { UserId } from "@bitwarden/common/types/guid";
export class DefaultMasterPasswordPolicyService implements MasterPasswordPolicyServiceAbstraction {
constructor(
private readonly policyApiService: PolicyApiServiceAbstraction,
) {
}
getByUserId(userId: UserId): Promise<MasterPasswordPolicyOptions> {
//
// const result = await this.policyApiService.getMasterPasswordPolicyOptsForOrgUser(userId);
//
// if (!result) {
// throw new Error("No policy found for user id.");
// }
//
// return result;
return new Promise<MasterPasswordPolicyOptions>((resolve, reject) => resolve(new MasterPasswordPolicyOptions()));
}
getForInvitedMember(inviteToken: string): Promise<MasterPasswordPolicyOptions> {
return new Promise<MasterPasswordPolicyOptions>((resolve, reject) => resolve(new MasterPasswordPolicyOptions()));
}
}

View File

@@ -160,7 +160,7 @@ export class DialogService {
* but we get the base CDK DialogRef instance *from* `Dialog.open`.
*
* To break the circle, we define CDKDialogRef as a wrapper for the CDKDialogRefBase.
* This allows us to create the class instance and provide the base instance later, almost like "deferred inheritance".
provide the base instance later, almost like "deferred inheritance".
**/
const ref = new CdkDialogRef<R, C>();
const injector = this.createInjector({