From 9a0188048c657eea6e5aebb1dc1134b5b2c24bff Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Fri, 26 Jul 2024 14:10:17 -0700 Subject: [PATCH] [PM-9959] Add support for name and username to be passed in as query params for initial form values --- .../vault-v2/add-edit/add-edit-v2.component.ts | 18 ++++++++++++++++++ .../abstractions/cipher-form-config.service.ts | 2 ++ .../components/identity/identity.component.ts | 4 ++++ .../item-details-section.component.ts | 2 +- .../login-details-section.component.ts | 7 ++++--- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts b/apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts index 84fd9295ab..d819440047 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts +++ b/apps/browser/src/vault/popup/components/vault-v2/add-edit/add-edit-v2.component.ts @@ -46,6 +46,8 @@ class QueryParams { this.organizationId = params.organizationId; this.collectionId = params.collectionId; this.uri = params.uri; + this.username = params.username; + this.name = params.name; } /** @@ -82,6 +84,16 @@ class QueryParams { * Optional URI to pre-fill for login ciphers. */ uri?: string; + + /** + * Optional username to pre-fill for login/identity ciphers. + */ + username?: string; + + /** + * Optional name to pre-fill for the cipher. + */ + name?: string; } export type AddEditQueryParams = Partial>; @@ -261,6 +273,12 @@ export class AddEditV2Component implements OnInit { if (params.uri) { config.initialValues.loginUri = params.uri; } + if (params.username) { + config.initialValues.username = params.username; + } + if (params.name) { + config.initialValues.name = params.name; + } } setHeader(mode: CipherFormMode, type: CipherType) { diff --git a/libs/vault/src/cipher-form/abstractions/cipher-form-config.service.ts b/libs/vault/src/cipher-form/abstractions/cipher-form-config.service.ts index 334fbae590..837c9d11ed 100644 --- a/libs/vault/src/cipher-form/abstractions/cipher-form-config.service.ts +++ b/libs/vault/src/cipher-form/abstractions/cipher-form-config.service.ts @@ -22,6 +22,8 @@ export type OptionalInitialValues = { organizationId?: OrganizationId; collectionIds?: CollectionId[]; loginUri?: string; + username?: string; + name?: string; }; /** diff --git a/libs/vault/src/cipher-form/components/identity/identity.component.ts b/libs/vault/src/cipher-form/components/identity/identity.component.ts index 9e84f8ea6c..ae712b915b 100644 --- a/libs/vault/src/cipher-form/components/identity/identity.component.ts +++ b/libs/vault/src/cipher-form/components/identity/identity.component.ts @@ -113,6 +113,10 @@ export class IdentitySectionComponent implements OnInit { if (this.originalCipherView && this.originalCipherView.id) { this.populateFormData(); + } else { + this.identityForm.patchValue({ + username: this.cipherFormContainer.config.initialValues?.username || "", + }); } } diff --git a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts index 75cb160c92..99ecd84cd2 100644 --- a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts +++ b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.ts @@ -165,7 +165,7 @@ export class ItemDetailsSectionComponent implements OnInit { await this.initFromExistingCipher(); } else { this.itemDetailsForm.setValue({ - name: "", + name: this.initialValues?.name || "", organizationId: this.initialValues?.organizationId || this.defaultOwner, folderId: this.initialValues?.folderId || null, collectionIds: [], diff --git a/libs/vault/src/cipher-form/components/login-details-section/login-details-section.component.ts b/libs/vault/src/cipher-form/components/login-details-section/login-details-section.component.ts index 61a51fadaa..57d2243820 100644 --- a/libs/vault/src/cipher-form/components/login-details-section/login-details-section.component.ts +++ b/libs/vault/src/cipher-form/components/login-details-section/login-details-section.component.ts @@ -144,9 +144,10 @@ export class LoginDetailsSectionComponent implements OnInit { } private async initNewCipher() { - this.loginDetailsForm.controls.password.patchValue( - await this.generationService.generateInitialPassword(), - ); + this.loginDetailsForm.patchValue({ + username: this.cipherFormContainer.config.initialValues?.username || "", + password: await this.generationService.generateInitialPassword(), + }); } captureTotp = async () => {