1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +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">
{{ "restore" | i18n }}
</button>
<ng-container *ngIf="showCipherView && !showRestore">
<ng-container *ngIf="showEdit">
<button
bitButton
[bitAction]="switchToEdit"
@@ -60,15 +60,12 @@
>
{{ "save" | i18n }}
</button>
<button
bitButton
type="button"
buttonType="secondary"
(click)="cancel()"
*ngIf="!showCipherView && !showRestore"
>
<button bitButton type="button" buttonType="secondary" (click)="cancel()" *ngIf="showCancel">
{{ "cancel" | i18n }}
</button>
<button bitButton type="button" buttonType="secondary" (click)="cancel()" *ngIf="showClose">
{{ "close" | i18n }}
</button>
<div class="tw-ml-auto" *ngIf="showDelete">
<button
bitIconButton="bwi-trash"
@@ -76,7 +73,7 @@
buttonType="danger"
[appA11yTitle]="'delete' | i18n"
[bitAction]="delete"
[disabled]="!(canDeleteCipher$ | async)"
[disabled]="!canDelete"
data-testid="delete-cipher-btn"
></button>
</div>

View File

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