From 44e182e32ece3af4234a3d9173a9b98e740870d3 Mon Sep 17 00:00:00 2001
From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com>
Date: Thu, 24 Oct 2024 10:30:46 -0500
Subject: [PATCH] [PM-13187] Hide "Assign To Collections" when the user has no
orgs (#11668)
* web - hide assign to collections button when the user has no organizations
* browser - hide assign to collections button when the user has no organizations
* hide assign to collections in the bulk edit menu when the user doesn't belong to an organization
---
.../item-more-options.component.html | 2 +-
.../item-more-options.component.ts | 13 +++++++++++--
.../vault-items/vault-cipher-row.component.ts | 2 +-
.../components/vault-items/vault-items.component.ts | 5 +++++
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.html b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.html
index 8374bb0cc7..03287c75fa 100644
--- a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.html
+++ b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.html
@@ -28,7 +28,7 @@
{{ "clone" | i18n }}
-
+
{{ "assignToCollections" | i18n }}
diff --git a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts
index 2bc3fcea2f..8c52ee7ed8 100644
--- a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts
+++ b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts
@@ -1,9 +1,10 @@
import { CommonModule } from "@angular/common";
-import { booleanAttribute, Component, Input } from "@angular/core";
+import { booleanAttribute, Component, Input, OnInit } from "@angular/core";
import { Router, RouterModule } from "@angular/router";
import { firstValueFrom, map } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
+import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@@ -29,7 +30,7 @@ import { AddEditQueryParams } from "../add-edit/add-edit-v2.component";
templateUrl: "./item-more-options.component.html",
imports: [ItemModule, IconButtonModule, MenuModule, CommonModule, JslibModule, RouterModule],
})
-export class ItemMoreOptionsComponent {
+export class ItemMoreOptionsComponent implements OnInit {
@Input({
required: true,
})
@@ -44,6 +45,9 @@ export class ItemMoreOptionsComponent {
protected autofillAllowed$ = this.vaultPopupAutofillService.autofillAllowed$;
+ /** Boolean dependent on the current user having access to an organization */
+ protected hasOrganizations = false;
+
constructor(
private cipherService: CipherService,
private passwordRepromptService: PasswordRepromptService,
@@ -53,8 +57,13 @@ export class ItemMoreOptionsComponent {
private i18nService: I18nService,
private vaultPopupAutofillService: VaultPopupAutofillService,
private accountService: AccountService,
+ private organizationService: OrganizationService,
) {}
+ async ngOnInit(): Promise {
+ this.hasOrganizations = await this.organizationService.hasOrganizations();
+ }
+
get canEdit() {
return this.cipher.edit;
}
diff --git a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.ts b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.ts
index 67b02d364f..355f0240ec 100644
--- a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.ts
+++ b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.ts
@@ -92,7 +92,7 @@ export class VaultCipherRowComponent implements OnInit {
}
protected get showAssignToCollections() {
- return this.canEditCipher && !this.cipher.isDeleted;
+ return this.organizations?.length && this.canEditCipher && !this.cipher.isDeleted;
}
protected get showClone() {
diff --git a/apps/web/src/app/vault/components/vault-items/vault-items.component.ts b/apps/web/src/app/vault/components/vault-items/vault-items.component.ts
index f469cec75a..db1c2d6b56 100644
--- a/apps/web/src/app/vault/components/vault-items/vault-items.component.ts
+++ b/apps/web/src/app/vault/components/vault-items/vault-items.component.ts
@@ -299,6 +299,11 @@ export class VaultItemsComponent {
return false;
}
+ // When the user doesn't belong to an organization, hide assign to collections
+ if (this.allOrganizations.length === 0) {
+ return false;
+ }
+
if (this.selection.selected.length === 0) {
return true;
}