Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-17948] Migrate export from generator legacy to generator core #13238

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { EventType } from "@bitwarden/common/enums";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.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 { Utils } from "@bitwarden/common/platform/misc/utils";
import {
AsyncActionsModule,
Expand All @@ -56,7 +55,8 @@ import {
SelectModule,
ToastService,
} from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { GeneratorServicesModule } from "@bitwarden/generator-components";
import { CredentialGeneratorService, GenerateRequest, Generators } from "@bitwarden/generator-core";
import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core";

import { EncryptedExportType } from "../enums/encrypted-export-type.enum";
Expand All @@ -81,6 +81,7 @@ import { ExportScopeCalloutComponent } from "./export-scope-callout.component";
ExportScopeCalloutComponent,
UserVerificationDialogComponent,
PasswordStrengthV2Component,
GeneratorServicesModule,
],
})
export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
Expand Down Expand Up @@ -175,14 +176,14 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {

private destroy$ = new Subject<void>();
private onlyManagedCollections = true;
private onGenerate$ = new Subject<GenerateRequest>();
audreyality marked this conversation as resolved.
Show resolved Hide resolved

constructor(
protected i18nService: I18nService,
protected toastService: ToastService,
protected exportService: VaultExportServiceAbstraction,
protected eventCollectionService: EventCollectionService,
protected passwordGenerationService: PasswordGenerationServiceAbstraction,
private platformUtilsService: PlatformUtilsService,
protected generatorService: CredentialGeneratorService,
private policyService: PolicyService,
private logService: LogService,
private formBuilder: UntypedFormBuilder,
Expand Down Expand Up @@ -218,6 +219,17 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {

const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));

// Wire up the password generation for the password-protected export
this.generatorService
.generate$(Generators.password, { on$: this.onGenerate$ })
.pipe(takeUntil(this.destroy$))
audreyality marked this conversation as resolved.
Show resolved Hide resolved
.subscribe((generated) => {
this.exportForm.patchValue({
filePassword: generated.credential,
confirmFilePassword: generated.credential,
});
});

if (this.organizationId) {
this.organizations$ = this.organizationService
.memberOrganizations$(userId)
Expand Down Expand Up @@ -302,10 +314,7 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
}

generatePassword = async () => {
const [options] = await this.passwordGenerationService.getOptions();
const generatedPassword = await this.passwordGenerationService.generatePassword(options);
this.exportForm.get("filePassword").setValue(generatedPassword);
this.exportForm.get("confirmFilePassword").setValue(generatedPassword);
this.onGenerate$.next({ source: "export" });
};

submit = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@bitwarden/common/*": ["../../../../common/src/*"],
"@bitwarden/components": ["../../../../components/src"],
"@bitwarden/generator-core": ["../../../../tools/generator/core/src"],
"@bitwarden/generator-components": ["../../../../tools/generator/components/src"],
"@bitwarden/generator-history": ["../../../../tools/generator/extensions/history/src"],
"@bitwarden/generator-legacy": ["../../../../tools/generator/extensions/legacy/src"],
"@bitwarden/generator-navigation": ["../../../../tools/generator/extensions/navigation/src"],
Expand Down
Loading