mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-07 21:36:26 +02:00
[UI] Update sidebar to also hide/show billing metrics dashboard based on permissions (#14490) (#14517)
* Update sidebar to also hide/show based on permissions * Add tests Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
This commit is contained in:
parent
f0c8a6cc17
commit
00a5ed132f
@ -115,6 +115,9 @@ const API_PATHS = {
|
||||
monitoring: {
|
||||
'utilization-report': 'sys/utilization-report',
|
||||
},
|
||||
billing: {
|
||||
overview: 'sys/billing/overview',
|
||||
},
|
||||
};
|
||||
|
||||
// API_PATHS_TO_ROUTE_PARAMS is used to resolve route params for that path when checking permissions for the nav item.
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
data-test-sidebar-nav-link="Client count"
|
||||
/>
|
||||
{{/if}}
|
||||
{{#if (and this.version.hasConsumptionBilling (or this.isRootNamespace this.namespace.inHvdAdminNamespace))}}
|
||||
{{#if (display-nav-item this.routeName.billingDashboard)}}
|
||||
<Nav.Link
|
||||
@route="vault.cluster.billing.overview"
|
||||
@text="Billing metrics"
|
||||
|
||||
@ -22,6 +22,7 @@ export default class SidebarNavClusterComponent extends Component {
|
||||
|
||||
routeName = {
|
||||
vaultUsage: RouteName.VAULT_USAGE,
|
||||
billingDashboard: RouteName.BILLING_DASHBOARD,
|
||||
};
|
||||
|
||||
get cluster() {
|
||||
|
||||
@ -21,6 +21,7 @@ export enum RouteName {
|
||||
REPLICATION = 'replication',
|
||||
VAULT_USAGE = 'vault-usage',
|
||||
LICENSE = 'license',
|
||||
BILLING_DASHBOARD = 'billing-dashboard',
|
||||
}
|
||||
|
||||
export enum NavSection {
|
||||
@ -37,7 +38,8 @@ export default class NavBar extends Helper {
|
||||
@service declare readonly flags: FlagsService;
|
||||
|
||||
compute([navItem]: string[]) {
|
||||
const { SECRETS_RECOVERY, SEAL, REPLICATION, VAULT_USAGE, LICENSE, SECRETS_SYNC } = RouteName;
|
||||
const { SECRETS_RECOVERY, SEAL, REPLICATION, VAULT_USAGE, LICENSE, SECRETS_SYNC, BILLING_DASHBOARD } =
|
||||
RouteName;
|
||||
const { RESILIENCE_AND_RECOVERY, REPORTING, CLIENT_COUNT } = NavSection;
|
||||
|
||||
switch (navItem) {
|
||||
@ -54,6 +56,9 @@ export default class NavBar extends Helper {
|
||||
return this.supportsLicense;
|
||||
case REPORTING:
|
||||
return this.canAccessVaultUsageDashboard || this.supportsLicense;
|
||||
// monitoring
|
||||
case BILLING_DASHBOARD:
|
||||
return this.supportsBillingDashboard;
|
||||
// resilience and recovery nav items
|
||||
case SECRETS_RECOVERY:
|
||||
return this.supportsSnapshots;
|
||||
@ -152,6 +157,16 @@ export default class NavBar extends Helper {
|
||||
// otherwise we show the link depending on whether or not the feature exists
|
||||
return this.version.hasSecretsSync;
|
||||
}
|
||||
|
||||
get supportsBillingDashboard() {
|
||||
const isCorrectNamespace = this.isRootNamespace || this.namespace.inHvdAdminNamespace;
|
||||
|
||||
return (
|
||||
this.version.hasConsumptionBilling &&
|
||||
isCorrectNamespace &&
|
||||
this.permissions.hasNavPermission('billing', 'overview')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function computeNavBar(context: object, navItem: string): boolean {
|
||||
|
||||
@ -165,8 +165,17 @@ module('Integration | Component | sidebar-nav-cluster', function (hooks) {
|
||||
assert.dom(GENERAL.navLink('Billing metrics')).exists('Billing metrics link is visible.');
|
||||
});
|
||||
|
||||
test('it should hide billing metrics link when in namespace other than root or admin when Consumption Billing feature is enabled', async function (assert) {
|
||||
test('it should not show billing metrics link when in HVD admin namespace and Consumption Billing feature is enabled', async function (assert) {
|
||||
stubFeaturesAndPermissions(this.owner, true, false, ['Consumption Billing']);
|
||||
this.flags.featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE'];
|
||||
const namespace = this.owner.lookup('service:namespace');
|
||||
namespace.setNamespace('admin');
|
||||
await renderComponent();
|
||||
assert.dom(GENERAL.navLink('Billing metrics')).exists('Billing metrics link is visible.');
|
||||
});
|
||||
|
||||
test('it should hide billing metrics link when in namespace other than root or admin when Consumption Billing feature and does not have permission', async function (assert) {
|
||||
stubFeaturesAndPermissions(this.owner, true, false, ['Consumption Billing'], false);
|
||||
const namespace = this.owner.lookup('service:namespace');
|
||||
namespace.setNamespace('namespace-1');
|
||||
await renderComponent();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user