From 60e7315a28da415c7557a733c5ea6125ce6de00e Mon Sep 17 00:00:00 2001 From: Evan Moncuso Date: Wed, 18 Dec 2024 17:52:31 -0800 Subject: [PATCH 1/3] add check for admin namespace on managed clusters --- ui/app/components/dashboard/overview.hbs | 9 ++--- ui/app/components/dashboard/overview.ts | 46 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 ui/app/components/dashboard/overview.ts diff --git a/ui/app/components/dashboard/overview.hbs b/ui/app/components/dashboard/overview.hbs index bc3abf150637..0d56a1007788 100644 --- a/ui/app/components/dashboard/overview.hbs +++ b/ui/app/components/dashboard/overview.hbs @@ -7,12 +7,14 @@
- {{#if (and @version.isEnterprise @isRootNamespace)}} + {{#if @version.isEnterprise}}
- {{#if (has-permission "clients" routeParams="activity")}} + {{#if (and (has-permission "clients" routeParams="activity") this.shouldShowClientCount)}} {{/if}} - {{#if (and (has-permission "status" routeParams="replication") (not (is-empty-value @replication)))}} + {{#if + (and (has-permission "status" routeParams="replication") (not (is-empty-value @replication)) @isRootNamespace) + }}
- {{else}}
diff --git a/ui/app/components/dashboard/overview.ts b/ui/app/components/dashboard/overview.ts new file mode 100644 index 000000000000..06dffea602f4 --- /dev/null +++ b/ui/app/components/dashboard/overview.ts @@ -0,0 +1,46 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +import Component from '@glimmer/component'; +import { service } from '@ember/service'; + +import type flagsService from 'vault/services/flags'; +import NamespaceService from 'vault/services/namespace'; + +export type Args = { + isRootNamespace: boolean; + replication: unknown; + secretsEngines: unknown; + vaultConfiguration: unknown; + version: { isEnterprise: boolean }; +}; + +export default class OverviewComponent extends Component { + @service declare readonly flags: flagsService; + @service declare readonly namespace: NamespaceService; + + /** + * the client count card should show in the following conditions + * Self Managed clusters that are running enterprise and showing the `root` namespace + * Managed clusters that are running enterprise and show the `admin` namespace + */ + // for self managed clusters, this is the `root` namespace + // for HVD clusters, this is the `admin` namespace + get shouldShowClientCount() { + const { version, isRootNamespace } = this.args; + const { flags, namespace } = this; + + // don't show client count if this isn't an enterprise cluster + if (!version.isEnterprise) return false; + + // HVD clusters + if (flags.isHvdManaged && namespace.currentNamespace === 'admin') return true; + + // SM clusters + if (isRootNamespace) return true; + + return false; + } +} From 1343597bb5e89625a6bc6d4eb4a4c4fae9e5b3cd Mon Sep 17 00:00:00 2001 From: Evan Moncuso Date: Wed, 18 Dec 2024 17:52:59 -0800 Subject: [PATCH 2/3] add tests for client count card in managed clusters --- .../components/dashboard/overview-test.js | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/ui/tests/integration/components/dashboard/overview-test.js b/ui/tests/integration/components/dashboard/overview-test.js index c64ead6d4ec7..0cb9df8474c3 100644 --- a/ui/tests/integration/components/dashboard/overview-test.js +++ b/ui/tests/integration/components/dashboard/overview-test.js @@ -15,8 +15,10 @@ module('Integration | Component | dashboard/overview', function (hooks) { setupMirage(hooks); hooks.beforeEach(function () { - this.store = this.owner.lookup('service:store'); + this.flags = this.owner.lookup('service:flags'); + this.namespace = this.owner.lookup('service:namespace'); this.permissions = this.owner.lookup('service:permissions'); + this.store = this.owner.lookup('service:store'); this.version = this.owner.lookup('service:version'); this.version.version = '1.13.1+ent'; this.version.type = 'enterprise'; @@ -151,6 +153,46 @@ module('Integration | Component | dashboard/overview', function (hooks) { assert.dom(DASHBOARD.cardName('replication')).exists(); }); + test('it should show client count on enterprise in admin namespace when running a managed mode', async function (assert) { + this.permissions.exactPaths = { + 'admin/sys/internal/counters/activity': { + capabilities: ['read'], + }, + 'admin/sys/replication/status': { + capabilities: ['read'], + }, + }; + + this.version.type = 'enterprise'; + this.flags.featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE']; + this.namespace.path = 'admin'; + this.isRootNamespace = false; + + await this.renderComponent(); + + assert.dom(DASHBOARD.cardName('client-count')).exists(); + }); + + test('it should hide client count on enterprise in any other namespace when running a managed mode', async function (assert) { + this.permissions.exactPaths = { + 'sys/internal/counters/activity': { + capabilities: ['read'], + }, + 'sys/replication/status': { + capabilities: ['read'], + }, + }; + + this.version.type = 'enterprise'; + this.flags.featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE']; + this.namespace.path = 'groceries'; + this.isRootNamespace = false; + + await this.renderComponent(); + + assert.dom(DASHBOARD.cardName('client-count')).doesNotExist(); + }); + test('it should hide cards on enterprise in root namespace but no permission', async function (assert) { await this.renderComponent(); assert.dom(DASHBOARD.cardName('client-count')).doesNotExist(); From 0f6b3d5f2f2d08834161f4ca4f9dc3046e065c19 Mon Sep 17 00:00:00 2001 From: Evan Moncuso Date: Thu, 19 Dec 2024 14:45:46 -0800 Subject: [PATCH 3/3] add changelog --- changelog/29241.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/29241.txt diff --git a/changelog/29241.txt b/changelog/29241.txt new file mode 100644 index 000000000000..06699fdf1271 --- /dev/null +++ b/changelog/29241.txt @@ -0,0 +1,3 @@ +```release-note:bug +UI: Fix missing Client Count card when running as a Vault Dedicated cluster +```