From 4d68952ef39255e2a252137add77c0082cd20944 Mon Sep 17 00:00:00 2001 From: Brandon Treston Date: Fri, 14 Mar 2025 09:51:40 -0400 Subject: [PATCH] [PM-18089] Update cipher permissions model and consumers (#13606) * update cipher permissions model and consumers * add new property to tests * fix test, add property to toCipherData() * add missing ConfigService * fix story * refactor * fix error, cleanup * revert refactor * refactor * remove uneeded test * cleanup * fix build error * refactor * clean up * add tests * move validation check to after featrue flagged logic * iterate on feedback * feedback --- .../browser/src/background/main.background.ts | 1 + .../service-container/service-container.ts | 1 + .../vault-item-dialog.component.ts | 10 +- .../vault-cipher-row.component.html | 21 +++- .../vault-items/vault-cipher-row.component.ts | 16 ++- .../vault-items/vault-items.component.html | 26 ++++- .../vault-items/vault-items.component.ts | 63 +++++++++++ .../vault-items/vault-items.stories.ts | 11 +- .../src/services/jslib-services.module.ts | 7 +- .../models/api/cipher-permissions.api.ts | 21 ++++ .../src/vault/models/data/cipher.data.ts | 7 +- .../src/vault/models/domain/cipher.spec.ts | 18 +++ libs/common/src/vault/models/domain/cipher.ts | 4 + .../vault/models/response/cipher.response.ts | 3 + .../src/vault/models/view/cipher.view.ts | 3 + .../cipher-authorization.service.spec.ts | 104 ++++++++++++++++++ .../services/cipher-authorization.service.ts | 77 ++++++++++--- .../src/vault/services/cipher.service.spec.ts | 2 + 18 files changed, 372 insertions(+), 23 deletions(-) create mode 100644 libs/common/src/vault/models/api/cipher-permissions.api.ts diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 713e3e3e353..807767455a5 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1281,6 +1281,7 @@ export default class MainBackground { this.collectionService, this.organizationService, this.accountService, + this.configService, ); this.inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); diff --git a/apps/cli/src/service-container/service-container.ts b/apps/cli/src/service-container/service-container.ts index 3beb01b563b..75a74d42bbd 100644 --- a/apps/cli/src/service-container/service-container.ts +++ b/apps/cli/src/service-container/service-container.ts @@ -845,6 +845,7 @@ export class ServiceContainer { this.collectionService, this.organizationService, this.accountService, + this.configService, ); this.masterPasswordApiService = new MasterPasswordApiService(this.apiService, this.logService); diff --git a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts index 881903e79e5..f7169d9dbd4 100644 --- a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts +++ b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts @@ -15,6 +15,8 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions"; import { EventType } from "@bitwarden/common/enums"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; @@ -231,7 +233,10 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy { * A user may restore items if they have delete permissions and the item is in the trash. */ protected async canUserRestore() { - return this.isTrashFilter && this.cipher?.isDeleted && this.canDelete; + const featureFlagEnabled = await firstValueFrom(this.limitItemDeletion$); + return this.isTrashFilter && this.cipher?.isDeleted && featureFlagEnabled + ? this.cipher?.permissions.restore + : this.canDelete; } protected showRestore: boolean; @@ -277,6 +282,8 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy { protected canDelete = false; + protected limitItemDeletion$ = this.configService.getFeatureFlag$(FeatureFlag.LimitItemDeletion); + constructor( @Inject(DIALOG_DATA) protected params: VaultItemDialogParams, private dialogRef: DialogRef, @@ -294,6 +301,7 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy { private apiService: ApiService, private eventCollectionService: EventCollectionService, private routedVaultFilterService: RoutedVaultFilterService, + private configService: ConfigService, ) { this.updateTitle(); } diff --git a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html index befeee43f69..ef6a347f7d3 100644 --- a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html +++ b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html @@ -86,7 +86,12 @@ appStopProp > - - - - -