1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +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;
if (this.activeFilter.collectionId) { comp.type = this.activeFilter.cipherType;
component.collectionIds = [this.activeFilter.collectionId]; comp.collections = collections;
} if (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,28 +255,35 @@ export class VaultComponent implements OnInit, OnDestroy {
} }
} }
const defaultComponentParameters = (comp: AddEditComponent) => {
comp.organization = this.organization;
comp.cipherId = cipherId;
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
comp.onSavedCipher.subscribe(async () => {
modal.close();
await this.vaultItemsComponent.refresh();
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
comp.onDeletedCipher.subscribe(async () => {
modal.close();
await this.vaultItemsComponent.refresh();
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
comp.onRestoredCipher.subscribe(async () => {
modal.close();
await this.vaultItemsComponent.refresh();
});
};
const [modal, childComponent] = await this.modalService.openViewRef( const [modal, childComponent] = await this.modalService.openViewRef(
AddEditComponent, AddEditComponent,
this.cipherAddEditModalRef, this.cipherAddEditModalRef,
(comp) => { additionalComponentParameters == null
comp.organization = this.organization; ? defaultComponentParameters
comp.cipherId = cipherId; : (comp) => {
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe defaultComponentParameters(comp);
comp.onSavedCipher.subscribe(async () => { additionalComponentParameters(comp);
modal.close(); }
await this.vaultItemsComponent.refresh();
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
comp.onDeletedCipher.subscribe(async () => {
modal.close();
await this.vaultItemsComponent.refresh();
});
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
comp.onRestoredCipher.subscribe(async () => {
modal.close();
await this.vaultItemsComponent.refresh();
});
}
); );
modal.onClosedPromise().then(() => { modal.onClosedPromise().then(() => {
@@ -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) {