1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Fix race condition when setting modal properties (#4701)

This commit is contained in:
Thomas Rittson
2023-02-10 03:50:19 +10:00
committed by GitHub
parent db202f9e9e
commit 1c18a73a56

View File

@@ -218,26 +218,35 @@ export class VaultComponent implements OnInit, OnDestroy {
} }
async addCipher() { async addCipher() {
const component = await this.editCipher(null); const collections = (await firstValueFrom(this.vaultFilterService.filteredCollections$)).filter(
component.organizationId = this.organization.id; (c) => !c.readOnly && c.id != null
component.type = this.activeFilter.cipherType; );
component.collections = (
await firstValueFrom(this.vaultFilterService.filteredCollections$) await this.editCipher(null, (comp) => {
).filter((c) => !c.readOnly && c.id != null); comp.organizationId = this.organization.id;
comp.type = this.activeFilter.cipherType;
comp.collections = collections;
if (this.activeFilter.collectionId) { if (this.activeFilter.collectionId) {
component.collectionIds = [this.activeFilter.collectionId]; comp.collectionIds = [this.activeFilter.collectionId];
} }
});
} }
async navigateToCipher(cipher: CipherView) { async navigateToCipher(cipher: CipherView) {
this.go({ itemId: cipher?.id }); this.go({ itemId: cipher?.id });
} }
async editCipher(cipher: CipherView) { async editCipher(
return this.editCipherId(cipher?.id); cipher: CipherView,
additionalComponentParameters?: (comp: AddEditComponent) => void
) {
return this.editCipherId(cipher?.id, additionalComponentParameters);
} }
async editCipherId(cipherId: string) { async editCipherId(
cipherId: string,
additionalComponentParameters?: (comp: AddEditComponent) => void
) {
const cipher = await this.cipherService.get(cipherId); const cipher = await this.cipherService.get(cipherId);
if (cipher != null && cipher.reprompt != 0) { if (cipher != null && cipher.reprompt != 0) {
if (!(await this.passwordRepromptService.showPasswordPrompt())) { if (!(await this.passwordRepromptService.showPasswordPrompt())) {
@@ -246,10 +255,7 @@ export class VaultComponent implements OnInit, OnDestroy {
} }
} }
const [modal, childComponent] = await this.modalService.openViewRef( const defaultComponentParameters = (comp: AddEditComponent) => {
AddEditComponent,
this.cipherAddEditModalRef,
(comp) => {
comp.organization = this.organization; comp.organization = this.organization;
comp.cipherId = cipherId; comp.cipherId = cipherId;
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
@@ -267,6 +273,16 @@ export class VaultComponent implements OnInit, OnDestroy {
modal.close(); modal.close();
await this.vaultItemsComponent.refresh(); await this.vaultItemsComponent.refresh();
}); });
};
const [modal, childComponent] = await this.modalService.openViewRef(
AddEditComponent,
this.cipherAddEditModalRef,
additionalComponentParameters == null
? defaultComponentParameters
: (comp) => {
defaultComponentParameters(comp);
additionalComponentParameters(comp);
} }
); );
@@ -278,13 +294,16 @@ export class VaultComponent implements OnInit, OnDestroy {
} }
async cloneCipher(cipher: CipherView) { async cloneCipher(cipher: CipherView) {
const component = await this.editCipher(cipher); const collections = (await firstValueFrom(this.vaultFilterService.filteredCollections$)).filter(
component.cloneMode = true; (c) => !c.readOnly && c.id != null
component.organizationId = this.organization.id; );
component.collections = (
await firstValueFrom(this.vaultFilterService.filteredCollections$) await this.editCipher(cipher, (comp) => {
).filter((c) => !c.readOnly && c.id != null); comp.cloneMode = true;
component.collectionIds = cipher.collectionIds; comp.collections = collections;
comp.organizationId = this.organization.id;
comp.collectionIds = cipher.collectionIds;
});
} }
async viewEvents(cipher: CipherView) { async viewEvents(cipher: CipherView) {