1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 13:53:34 +00:00

[PM-14952] - show "close" button if user doesn't have edit permission in vault dialog trash (#13036)

* show cancel button if user doesn't have edit permission in vault dialog for trash items

* show close instead of restore in vault dialog in trash

* fix logic for showing close button
This commit is contained in:
Jordan Aasen
2025-01-29 13:53:00 -08:00
committed by GitHub
parent 99ecf821dd
commit d09de817c3
2 changed files with 30 additions and 23 deletions

View File

@@ -39,7 +39,7 @@
<button *ngIf="showRestore" [bitAction]="restore" bitButton buttonType="primary" type="button"> <button *ngIf="showRestore" [bitAction]="restore" bitButton buttonType="primary" type="button">
{{ "restore" | i18n }} {{ "restore" | i18n }}
</button> </button>
<ng-container *ngIf="showCipherView && !showRestore"> <ng-container *ngIf="showEdit">
<button <button
bitButton bitButton
[bitAction]="switchToEdit" [bitAction]="switchToEdit"
@@ -60,15 +60,12 @@
> >
{{ "save" | i18n }} {{ "save" | i18n }}
</button> </button>
<button <button bitButton type="button" buttonType="secondary" (click)="cancel()" *ngIf="showCancel">
bitButton
type="button"
buttonType="secondary"
(click)="cancel()"
*ngIf="!showCipherView && !showRestore"
>
{{ "cancel" | i18n }} {{ "cancel" | i18n }}
</button> </button>
<button bitButton type="button" buttonType="secondary" (click)="cancel()" *ngIf="showClose">
{{ "close" | i18n }}
</button>
<div class="tw-ml-auto" *ngIf="showDelete"> <div class="tw-ml-auto" *ngIf="showDelete">
<button <button
bitIconButton="bwi-trash" bitIconButton="bwi-trash"
@@ -76,7 +73,7 @@
buttonType="danger" buttonType="danger"
[appA11yTitle]="'delete' | i18n" [appA11yTitle]="'delete' | i18n"
[bitAction]="delete" [bitAction]="delete"
[disabled]="!(canDeleteCipher$ | async)" [disabled]="!canDelete"
data-testid="delete-cipher-btn" data-testid="delete-cipher-btn"
></button> ></button>
</div> </div>

View File

@@ -4,7 +4,7 @@ import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { Component, ElementRef, Inject, OnDestroy, OnInit, ViewChild } from "@angular/core"; import { Component, ElementRef, Inject, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { firstValueFrom, Observable, Subject, switchMap } from "rxjs"; import { firstValueFrom, Subject, switchMap } from "rxjs";
import { map } from "rxjs/operators"; import { map } from "rxjs/operators";
import { CollectionView } from "@bitwarden/admin-console/common"; import { CollectionView } from "@bitwarden/admin-console/common";
@@ -207,16 +207,24 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy {
), ),
); );
protected get isTrashFilter() {
return this.filter?.type === "trash";
}
protected get showCancel() {
return !this.isTrashFilter && !this.showCipherView;
}
protected get showClose() {
return this.isTrashFilter && !this.showRestore;
}
/** /**
* Determines if the user may restore the item. * Determines if the user may restore the item.
* A user may restore items if they have delete permissions and the item is in the trash. * A user may restore items if they have delete permissions and the item is in the trash.
*/ */
protected async canUserRestore() { protected async canUserRestore() {
return ( return this.isTrashFilter && this.cipher?.isDeleted && this.canDelete;
this.filter?.type === "trash" &&
this.cipher?.isDeleted &&
(await firstValueFrom(this.canDeleteCipher$))
);
} }
protected showRestore: boolean; protected showRestore: boolean;
@@ -229,8 +237,8 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy {
return this.params.disableForm; return this.params.disableForm;
} }
protected get canDelete() { protected get showEdit() {
return this.cipher?.edit ?? false; return this.showCipherView && !this.isTrashFilter && !this.showRestore;
} }
protected get showDelete() { protected get showDelete() {
@@ -258,10 +266,10 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy {
protected formConfig: CipherFormConfig = this.params.formConfig; protected formConfig: CipherFormConfig = this.params.formConfig;
protected canDeleteCipher$: Observable<boolean>;
protected filter: RoutedVaultFilterModel; protected filter: RoutedVaultFilterModel;
protected canDelete = false;
constructor( constructor(
@Inject(DIALOG_DATA) protected params: VaultItemDialogParams, @Inject(DIALOG_DATA) protected params: VaultItemDialogParams,
private dialogRef: DialogRef<VaultItemDialogResult>, private dialogRef: DialogRef<VaultItemDialogResult>,
@@ -302,10 +310,12 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy {
(o) => o.id === this.cipher.organizationId, (o) => o.id === this.cipher.organizationId,
); );
this.canDeleteCipher$ = this.cipherAuthorizationService.canDeleteCipher$( this.canDelete = await firstValueFrom(
this.cipherAuthorizationService.canDeleteCipher$(
this.cipher, this.cipher,
[this.params.activeCollectionId], [this.params.activeCollectionId],
this.params.isAdminConsoleAction, this.params.isAdminConsoleAction,
),
); );
await this.eventCollectionService.collect( await this.eventCollectionService.collect(