[PM-9959] Add support for name and username to be passed in as query params for initial form values

This commit is contained in:
Shane Melton 2024-07-26 14:10:17 -07:00
parent 7090e3fa96
commit 9a0188048c
No known key found for this signature in database
5 changed files with 29 additions and 4 deletions

View File

@ -46,6 +46,8 @@ class QueryParams {
this.organizationId = params.organizationId; this.organizationId = params.organizationId;
this.collectionId = params.collectionId; this.collectionId = params.collectionId;
this.uri = params.uri; 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. * Optional URI to pre-fill for login ciphers.
*/ */
uri?: string; 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<Record<keyof QueryParams, string>>; export type AddEditQueryParams = Partial<Record<keyof QueryParams, string>>;
@ -261,6 +273,12 @@ export class AddEditV2Component implements OnInit {
if (params.uri) { if (params.uri) {
config.initialValues.loginUri = 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) { setHeader(mode: CipherFormMode, type: CipherType) {

View File

@ -22,6 +22,8 @@ export type OptionalInitialValues = {
organizationId?: OrganizationId; organizationId?: OrganizationId;
collectionIds?: CollectionId[]; collectionIds?: CollectionId[];
loginUri?: string; loginUri?: string;
username?: string;
name?: string;
}; };
/** /**

View File

@ -113,6 +113,10 @@ export class IdentitySectionComponent implements OnInit {
if (this.originalCipherView && this.originalCipherView.id) { if (this.originalCipherView && this.originalCipherView.id) {
this.populateFormData(); this.populateFormData();
} else {
this.identityForm.patchValue({
username: this.cipherFormContainer.config.initialValues?.username || "",
});
} }
} }

View File

@ -165,7 +165,7 @@ export class ItemDetailsSectionComponent implements OnInit {
await this.initFromExistingCipher(); await this.initFromExistingCipher();
} else { } else {
this.itemDetailsForm.setValue({ this.itemDetailsForm.setValue({
name: "", name: this.initialValues?.name || "",
organizationId: this.initialValues?.organizationId || this.defaultOwner, organizationId: this.initialValues?.organizationId || this.defaultOwner,
folderId: this.initialValues?.folderId || null, folderId: this.initialValues?.folderId || null,
collectionIds: [], collectionIds: [],

View File

@ -144,9 +144,10 @@ export class LoginDetailsSectionComponent implements OnInit {
} }
private async initNewCipher() { private async initNewCipher() {
this.loginDetailsForm.controls.password.patchValue( this.loginDetailsForm.patchValue({
await this.generationService.generateInitialPassword(), username: this.cipherFormContainer.config.initialValues?.username || "",
); password: await this.generationService.generateInitialPassword(),
});
} }
captureTotp = async () => { captureTotp = async () => {