1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-14 10:26:19 +01:00

[PM-13892] Update item more options component to react to changes to the cipher input (#11914)

This commit is contained in:
Shane Melton 2024-11-08 08:43:33 -08:00 committed by GitHub
parent 72e7e295ba
commit e91741b146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,8 @@
import { CommonModule } from "@angular/common";
import { booleanAttribute, Component, Input, OnInit } from "@angular/core";
import { Router, RouterModule } from "@angular/router";
import { firstValueFrom, map, Observable } from "rxjs";
import { BehaviorSubject, firstValueFrom, map, switchMap } from "rxjs";
import { filter } from "rxjs/operators";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
@ -30,10 +31,18 @@ import { AddEditQueryParams } from "../add-edit/add-edit-v2.component";
imports: [ItemModule, IconButtonModule, MenuModule, CommonModule, JslibModule, RouterModule],
})
export class ItemMoreOptionsComponent implements OnInit {
private _cipher$ = new BehaviorSubject<CipherView>(undefined);
@Input({
required: true,
})
cipher: CipherView;
set cipher(c: CipherView) {
this._cipher$.next(c);
}
get cipher() {
return this._cipher$.value;
}
/**
* Flag to hide the autofill menu options. Used for items that are
@ -43,7 +52,15 @@ export class ItemMoreOptionsComponent implements OnInit {
hideAutofillOptions: boolean;
protected autofillAllowed$ = this.vaultPopupAutofillService.autofillAllowed$;
protected canClone$: Observable<boolean>;
/**
* Observable that emits a boolean value indicating if the user is authorized to clone the cipher.
* @protected
*/
protected canClone$ = this._cipher$.pipe(
filter((c) => c != null),
switchMap((c) => this.cipherAuthorizationService.canCloneCipher$(c)),
);
/** Boolean dependent on the current user having access to an organization */
protected hasOrganizations = false;
@ -63,7 +80,6 @@ export class ItemMoreOptionsComponent implements OnInit {
async ngOnInit(): Promise<void> {
this.hasOrganizations = await this.organizationService.hasOrganizations();
this.canClone$ = this.cipherAuthorizationService.canCloneCipher$(this.cipher);
}
get canEdit() {