backport of commit 52baf01e5352968d623502a4f49dbda12a4dc322 (#21580)

Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
This commit is contained in:
hc-github-team-secure-vault-core 2023-07-05 12:16:02 -04:00 committed by GitHub
parent 94213dacde
commit 5a6be772eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 8 deletions

3
changelog/21562.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: Fixes issue with certain navigational links incorrectly displaying in child namespaces
```

View File

@ -37,7 +37,12 @@
{{/if}} {{/if}}
{{#if {{#if
(and this.version.isEnterprise this.cluster.anyReplicationEnabled (has-permission "status" routeParams="replication")) (and
this.version.isEnterprise
this.namespace.inRootNamespace
this.cluster.anyReplicationEnabled
(has-permission "status" routeParams="replication")
)
}} }}
<Nav.Title data-test-sidebar-nav-heading="Replication">Replication</Nav.Title> <Nav.Title data-test-sidebar-nav-heading="Replication">Replication</Nav.Title>
<Nav.Link <Nav.Link
@ -59,16 +64,18 @@
{{#if {{#if
(or (or
(has-permission "status" routeParams=(array "replication" "raft" "license" "seal")) (and
this.namespace.inRootNamespace (has-permission "status" routeParams=(array "replication" "raft" "license" "seal"))
)
(has-permission "clients" routeParams="activity") (has-permission "clients" routeParams="activity")
) )
}} }}
<Nav.Title data-test-sidebar-nav-heading="Monitoring">Monitoring</Nav.Title> <Nav.Title data-test-sidebar-nav-heading="Monitoring">Monitoring</Nav.Title>
{{/if}} {{/if}}
{{#if (and this.version.isEnterprise (has-permission "status" routeParams="replication"))}} {{#if (and this.version.isEnterprise this.namespace.inRootNamespace (has-permission "status" routeParams="replication"))}}
<Nav.Link @route="vault.cluster.replication.index" @text="Replication" data-test-sidebar-nav-link="Replication" /> <Nav.Link @route="vault.cluster.replication.index" @text="Replication" data-test-sidebar-nav-link="Replication" />
{{/if}} {{/if}}
{{#if (and this.cluster.usingRaft (has-permission "status" routeParams="raft"))}} {{#if (and this.cluster.usingRaft this.namespace.inRootNamespace (has-permission "status" routeParams="raft"))}}
<Nav.Link <Nav.Link
@route="vault.cluster.storage" @route="vault.cluster.storage"
@model={{this.cluster.name}} @model={{this.cluster.name}}
@ -79,7 +86,14 @@
{{#if (and (has-permission "clients" routeParams="activity") (not this.cluster.dr.isSecondary))}} {{#if (and (has-permission "clients" routeParams="activity") (not this.cluster.dr.isSecondary))}}
<Nav.Link @route="vault.cluster.clients" @text="Client count" data-test-sidebar-nav-link="Client count" /> <Nav.Link @route="vault.cluster.clients" @text="Client count" data-test-sidebar-nav-link="Client count" />
{{/if}} {{/if}}
{{#if (and this.version.features (has-permission "status" routeParams="license") (not this.cluster.dr.isSecondary))}} {{#if
(and
this.version.features
this.namespace.inRootNamespace
(has-permission "status" routeParams="license")
(not this.cluster.dr.isSecondary)
)
}}
<Nav.Link <Nav.Link
@route="vault.cluster.license" @route="vault.cluster.license"
@model={{this.cluster.name}} @model={{this.cluster.name}}
@ -87,7 +101,7 @@
data-test-sidebar-nav-link="License" data-test-sidebar-nav-link="License"
/> />
{{/if}} {{/if}}
{{#if (and (has-permission "status" routeParams="seal") (not this.cluster.dr.isSecondary))}} {{#if (and this.namespace.inRootNamespace (has-permission "status" routeParams="seal") (not this.cluster.dr.isSecondary))}}
<Nav.Link <Nav.Link
@route="vault.cluster.settings.seal" @route="vault.cluster.settings.seal"
@model={{this.cluster.name}} @model={{this.cluster.name}}

View File

@ -5,6 +5,7 @@ export default class SidebarNavClusterComponent extends Component {
@service currentCluster; @service currentCluster;
@service version; @service version;
@service auth; @service auth;
@service namespace;
get cluster() { get cluster() {
return this.currentCluster.cluster; return this.currentCluster.cluster;

View File

@ -3,11 +3,13 @@ import sinon from 'sinon';
export const stubFeaturesAndPermissions = (owner, isEnterprise = false, setCluster = false) => { export const stubFeaturesAndPermissions = (owner, isEnterprise = false, setCluster = false) => {
const permissions = owner.lookup('service:permissions'); const permissions = owner.lookup('service:permissions');
sinon.stub(permissions, 'hasNavPermission').returns(true); const hasNavPermission = sinon.stub(permissions, 'hasNavPermission');
hasNavPermission.returns(true);
sinon.stub(permissions, 'navPathParams'); sinon.stub(permissions, 'navPathParams');
const version = owner.lookup('service:version'); const version = owner.lookup('service:version');
sinon.stub(version, 'features').value(allFeatures()); const features = sinon.stub(version, 'features');
features.value(allFeatures());
sinon.stub(version, 'isEnterprise').value(isEnterprise); sinon.stub(version, 'isEnterprise').value(isEnterprise);
const auth = owner.lookup('service:auth'); const auth = owner.lookup('service:auth');
@ -20,4 +22,6 @@ export const stubFeaturesAndPermissions = (owner, isEnterprise = false, setClust
usingRaft: true, usingRaft: true,
}); });
} }
return { hasNavPermission, features };
}; };

View File

@ -64,4 +64,32 @@ module('Integration | Component | sidebar-nav-cluster', function (hooks) {
assert.dom(`[data-test-sidebar-nav-link="${link}"]`).hasText(link, `${link} link renders`); assert.dom(`[data-test-sidebar-nav-link="${link}"]`).hasText(link, `${link} link renders`);
}); });
}); });
test('it should hide enterprise related links in child namespace', async function (assert) {
const links = [
'Disaster Recovery',
'Performance',
'Replication',
'Raft Storage',
'License',
'Seal Vault',
];
this.owner.lookup('service:namespace').set('path', 'foo');
const stubs = stubFeaturesAndPermissions(this.owner, true, true);
stubs.hasNavPermission.callsFake((route) => route !== 'clients');
await renderComponent();
assert
.dom('[data-test-sidebar-nav-heading="Monitoring"]')
.doesNotExist(
'Monitoring heading is hidden in child namespace when user does not have access to Client Count'
);
links.forEach((link) => {
assert
.dom(`[data-test-sidebar-nav-link="${link}"]`)
.doesNotExist(`${link} is hidden in child namespace`);
});
});
}); });