Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: wrap client count card in permission conditional #26848

Merged
3 changes: 3 additions & 0 deletions changelog/26848.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I removed the license call in 1.17, I thought a changelog might be prudent because we're changing behavior here.

ui: Hide dashboard client count card if user does not have permission to view clients.
```
8 changes: 4 additions & 4 deletions ui/app/components/dashboard/overview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<div class="is-flex-row gap-24">
{{#if (and @version.isEnterprise @isRootNamespace)}}
<div class="is-flex-column is-flex-1 gap-24">
<Dashboard::ClientCountCard @isEnterprise={{@version.isEnterprise}} />
{{#if
(and @isRootNamespace (has-permission "status" routeParams="replication") (not (is-empty-value @replication)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed @isRootNamespace since that check happens above on line 10

}}
{{#if (has-permission "clients" routeParams="activity")}}
<Dashboard::ClientCountCard @isEnterprise={{@version.isEnterprise}} />
{{/if}}
{{#if (and (has-permission "status" routeParams="replication") (not (is-empty-value @replication)))}}
<Dashboard::ReplicationCard
@replication={{@replication}}
@version={{@version}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/dashboard/replication-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
/>
<small class="has-left-margin-xs has-text-grey">
Updated
{{date-format @updatedAt "MMM dd, yyyy hh:mm:ss"}}
{{date-format @updatedAt "MMM d yyyy, h:mm:ss aaa" withTimeZone=true}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent with our response timestamp format elsewhere in the app

</small>
</div>
{{else}}
Expand Down
94 changes: 40 additions & 54 deletions ui/tests/integration/components/dashboard/overview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { DASHBOARD } from 'vault/tests/helpers/components/dashboard/dashboard-selectors';
import { LICENSE_START } from 'vault/mirage/handlers/clients';
import { stubFeaturesAndPermissions } from 'vault/tests/helpers/components/sidebar-nav';

module('Integration | Component | dashboard/overview', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);

hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');

this.version = this.owner.lookup('service:version');
this.replication = {
dr: {
clusterId: '123',
Expand Down Expand Up @@ -69,10 +70,25 @@ module('Integration | Component | dashboard/overview', function (hooks) {
},
};
});

this.renderComponent = async () => {
return await render(
hbs`
<Dashboard::Overview
@secretsEngines={{this.secretsEngines}}
@vaultConfiguration={{this.vaultConfiguration}}
@replication={{this.replication}}
@version={{this.version}}
@isRootNamespace={{this.isRootNamespace}}
@refreshModel={{this.refreshModel}}
@replicationUpdatedAt={{this.replicationUpdatedAt}}
/>
`
);
};
});

test('it should show dashboard empty states', async function (assert) {
this.version = this.owner.lookup('service:version');
this.version.version = '1.13.1';
this.isRootNamespace = true;
await render(
Expand All @@ -95,21 +111,10 @@ module('Integration | Component | dashboard/overview', function (hooks) {
});

test('it should hide client count and replication card on community', async function (assert) {
this.version = this.owner.lookup('service:version');
this.version.version = '1.13.1';
this.version.type = 'community';
this.isRootNamespace = true;

await render(
hbs`
<Dashboard::Overview
@secretsEngines={{this.secretsEngines}}
@vaultConfiguration={{this.vaultConfiguration}}
@replication={{this.replication}}
@version={{this.version}}
@isRootNamespace={{this.isRootNamespace}}
@refreshModel={{this.refreshModel}} />
`
);
await this.renderComponent();

assert.dom(DASHBOARD.cardHeader('Vault version')).exists();
assert.dom(DASHBOARD.cardName('secrets-engines')).exists();
Expand All @@ -120,63 +125,44 @@ module('Integration | Component | dashboard/overview', function (hooks) {
assert.dom(DASHBOARD.cardName('client-count')).doesNotExist();
});

test('it should show client count on enterprise w/ license', async function (assert) {
this.version = this.owner.lookup('service:version');
test('it should show client count and replication on enterprise if has permission and in root namespace', async function (assert) {
this.version.version = '1.13.1+ent';
this.version.type = 'enterprise';
this.license = {
autoloaded: {
license_id: '7adbf1f4-56ef-35cd-3a6c-50ef2627865d',
},
};

await render(
hbs`
<Dashboard::Overview
@secretsEngines={{this.secretsEngines}}
@vaultConfiguration={{this.vaultConfiguration}}
@replication={{this.replication}}
@version={{this.version}}
@isRootNamespace={{true}}
@refreshModel={{this.refreshModel}} />`
);
assert.dom(DASHBOARD.cardHeader('Vault version')).exists();
assert.dom(DASHBOARD.cardName('secrets-engines')).exists();
assert.dom(DASHBOARD.cardName('learn-more')).exists();
assert.dom(DASHBOARD.cardName('quick-actions')).exists();
assert.dom(DASHBOARD.cardName('configuration-details')).exists();
this.isRootNamespace = true;
stubFeaturesAndPermissions(this.owner, true);
await this.renderComponent();
assert.dom(DASHBOARD.cardName('client-count')).exists();
assert.dom(DASHBOARD.cardName('replication')).exists();
});

test('it should hide replication on enterprise not on root namespace', async function (assert) {
this.version = this.owner.lookup('service:version');
test('it should hide on enterprise if no permission and in root namespace', async function (assert) {
this.version.version = '1.13.1+ent';
this.version.type = 'enterprise';
this.isRootNamespace = false;

await render(
hbs`
<Dashboard::Overview
@version={{this.version}}
@isRootNamespace={{this.isRootNamespace}}
@secretsEngines={{this.secretsEngines}}
@vaultConfiguration={{this.vaultConfiguration}}
@replication={{this.replication}}
@refreshModel={{this.refreshModel}} />`
);

this.isRootNamespace = true;
await this.renderComponent();
assert.dom(DASHBOARD.cardHeader('Vault version')).exists();
assert.dom('[data-test-badge-namespace]').exists();
assert.dom(DASHBOARD.cardName('secrets-engines')).exists();
assert.dom(DASHBOARD.cardName('learn-more')).exists();
assert.dom(DASHBOARD.cardName('quick-actions')).exists();
assert.dom(DASHBOARD.cardName('configuration-details')).exists();
assert.dom(DASHBOARD.cardName('client-count')).doesNotExist();
assert.dom(DASHBOARD.cardName('replication')).doesNotExist();
});

test('it should hide on enterprise if permission and not in root namespace', async function (assert) {
this.version.version = '1.13.1+ent';
this.version.type = 'enterprise';
this.isRootNamespace = false;
stubFeaturesAndPermissions(this.owner, true);
await this.renderComponent();
assert.dom(DASHBOARD.cardName('client-count')).doesNotExist();
assert.dom(DASHBOARD.cardName('replication')).doesNotExist();
});
// TODO separate tests for permission for one and not the other

module('learn more card', function () {
test('shows the learn more card on community', async function (assert) {
this.version.type = 'community';
await render(
hbs`<Dashboard::Overview @secretsEngines={{this.secretsEngines}} @vaultConfiguration={{this.vaultConfiguration}} @replication={{this.replication}} @refreshModel={{this.refreshModel}} />`
);
Expand Down
Loading