Skip to content

Commit

Permalink
Use UserVerificationDialogComponent for account recovery enrollment (
Browse files Browse the repository at this point in the history
  • Loading branch information
addisonbeck committed Apr 12, 2024
1 parent 8d698d9 commit bf11b90
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
import { Component, Inject } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";

import { UserVerificationDialogComponent } from "@bitwarden/auth/angular";
import { OrganizationUserService } from "@bitwarden/common/admin-console/abstractions/organization-user/organization-user.service";
import { OrganizationUserResetPasswordEnrollmentRequest } from "@bitwarden/common/admin-console/abstractions/organization-user/requests";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { Verification } from "@bitwarden/common/auth/types/verification";
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";
Expand All @@ -19,63 +14,58 @@ interface EnrollMasterPasswordResetData {
organization: Organization;
}

@Component({
selector: "app-enroll-master-password-reset",
templateUrl: "enroll-master-password-reset.component.html",
})
export class EnrollMasterPasswordReset {
protected organization: Organization;

protected formGroup = new FormGroup({
verification: new FormControl<Verification>(null, Validators.required),
});
constructor() {}

constructor(
private dialogRef: DialogRef,
@Inject(DIALOG_DATA) protected data: EnrollMasterPasswordResetData,
private resetPasswordService: OrganizationUserResetPasswordService,
private userVerificationService: UserVerificationService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private syncService: SyncService,
private logService: LogService,
private organizationUserService: OrganizationUserService,
static async open(
dialogService: DialogService,
data: EnrollMasterPasswordResetData,
resetPasswordService: OrganizationUserResetPasswordService,
organizationUserService: OrganizationUserService,
platformUtilsService: PlatformUtilsService,
i18nService: I18nService,
syncService: SyncService,
logService: LogService,
) {
this.organization = data.organization;
}
const result = await UserVerificationDialogComponent.open(dialogService, {
title: "enrollAccountRecovery",
calloutOptions: {
text: "resetPasswordEnrollmentWarning",
type: "warning",
},
});

// Handle the result of the dialog based on user action and verification success
if (result.userAction === "cancel") {
return;
}

submit = async () => {
// User confirmed the dialog so check verification success
if (!result.verificationSuccess) {
// verification failed
return;
}

// Verification succeeded
try {
await this.userVerificationService
.buildRequest(
this.formGroup.value.verification,
OrganizationUserResetPasswordEnrollmentRequest,
)
.then(async (request) => {
// Create request and execute enrollment
request.resetPasswordKey = await this.resetPasswordService.buildRecoveryKey(
this.organization.id,
);
await this.organizationUserService.putOrganizationUserResetPasswordEnrollment(
this.organization.id,
this.organization.userId,
request,
);
// This object is missing most of the properties in the
// `OrganizationUserResetPasswordEnrollmentRequest()`, but those
// properties don't carry over to the server model anyway and are
// never used by this flow.
const request = new OrganizationUserResetPasswordEnrollmentRequest();
request.resetPasswordKey = await resetPasswordService.buildRecoveryKey(data.organization.id);

await this.syncService.fullSync(true);
});
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("enrollPasswordResetSuccess"),
await organizationUserService.putOrganizationUserResetPasswordEnrollment(
data.organization.id,
data.organization.userId,
request,
);
this.dialogRef.close();

platformUtilsService.showToast("success", null, i18nService.t("enrollPasswordResetSuccess"));

await syncService.fullSync(true);
} catch (e) {
this.logService.error(e);
logService.error(e);
}
};

static open(dialogService: DialogService, data: EnrollMasterPasswordResetData) {
return dialogService.open(EnrollMasterPasswordReset, { data });
}
}

This file was deleted.

2 changes: 0 additions & 2 deletions apps/web/src/app/oss.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NgModule } from "@angular/core";

import { OrganizationUserModule } from "./admin-console/organizations/users/organization-user.module";
import { AuthModule } from "./auth";
import { LoginModule } from "./auth/login/login.module";
import { TrialInitiationModule } from "./auth/trial-initiation/trial-initiation.module";
Expand All @@ -16,7 +15,6 @@ import { VaultFilterModule } from "./vault/individual-vault/vault-filter/vault-f
TrialInitiationModule,
VaultFilterModule,
OrganizationBadgeModule,
OrganizationUserModule,
LoginModule,
AuthModule,
AccessComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { DialogService } from "@bitwarden/components";

import { OrganizationUserResetPasswordService } from "../../../../admin-console/organizations/members/services/organization-user-reset-password/organization-user-reset-password.service";
import { EnrollMasterPasswordReset } from "../../../../admin-console/organizations/users/enroll-master-password-reset.component";
import { OptionsInput } from "../shared/components/vault-filter-section.component";
import { OrganizationFilter } from "../shared/models/vault-filter.type";
Expand Down Expand Up @@ -46,6 +47,7 @@ export class OrganizationOptionsComponent implements OnInit, OnDestroy {
private organizationUserService: OrganizationUserService,
private userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
private dialogService: DialogService,
private resetPasswordService: OrganizationUserResetPasswordService,
) {}

async ngOnInit() {
Expand Down Expand Up @@ -144,7 +146,16 @@ export class OrganizationOptionsComponent implements OnInit, OnDestroy {

async toggleResetPasswordEnrollment(org: Organization) {
if (!this.organization.resetPasswordEnrolled) {
EnrollMasterPasswordReset.open(this.dialogService, { organization: org });
await EnrollMasterPasswordReset.open(
this.dialogService,
{ organization: org },
this.resetPasswordService,
this.organizationUserService,
this.platformUtilsService,
this.i18nService,
this.syncService,
this.logService,
);
} else {
// Remove reset password
const request = new OrganizationUserResetPasswordEnrollmentRequest();
Expand Down

0 comments on commit bf11b90

Please sign in to comment.