Skip to content

Commit

Permalink
[PM-13892] Update item more options component to react to changes to …
Browse files Browse the repository at this point in the history
…the cipher input (#11914)
  • Loading branch information
shane-melton authored Nov 8, 2024
1 parent 72e7e29 commit e91741b
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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() {
Expand Down

0 comments on commit e91741b

Please sign in to comment.