diff --git a/ui/app/components/license-banners.js b/ui/app/components/license-banners.js index 41f28957e..3733b611d 100644 --- a/ui/app/components/license-banners.js +++ b/ui/app/components/license-banners.js @@ -31,15 +31,21 @@ export default class LicenseBanners extends Component { constructor() { super(...arguments); - // do not dismiss any banners if the user has updated their version - const dismissedBanner = localStorage.getItem(`dismiss-license-banner-${this.currentVersion}`); // returns either warning or expired - this.updateDismissType(dismissedBanner); + // reset and show a previously dismissed license banner if: + // the version has been updated or the license has been updated (indicated by a change in the expiry date). + const bannerType = localStorage.getItem(this.dismissedBannerKey); // returns either warning or expired + + this.updateDismissType(bannerType); } get currentVersion() { return this.version.version; } + get dismissedBannerKey() { + return `dismiss-license-banner-${this.currentVersion}-${this.args.expiry}`; + } + get licenseExpired() { if (!this.args.expiry) return false; return isAfter(timestamp.now(), new Date(this.args.expiry)); @@ -54,9 +60,9 @@ export default class LicenseBanners extends Component { @action dismissBanner(dismissAction) { // if a client's version changed their old localStorage key will still exists. - localStorage.cleanUpStorage('dismiss-license-banner', `dismiss-license-banner-${this.currentVersion}`); + localStorage.cleanupStorage('dismiss-license-banner', this.dismissedBannerKey); // updates localStorage and then updates the template by calling updateDismissType - localStorage.setItem(`dismiss-license-banner-${this.currentVersion}`, dismissAction); + localStorage.setItem(this.dismissedBannerKey, dismissAction); this.updateDismissType(dismissAction); } diff --git a/ui/app/lib/local-storage.js b/ui/app/lib/local-storage.js index 57300aea2..e3be3447b 100644 --- a/ui/app/lib/local-storage.js +++ b/ui/app/lib/local-storage.js @@ -21,7 +21,7 @@ export default { return Object.keys(window.localStorage); }, - cleanUpStorage(string, keyToKeep) { + cleanupStorage(string, keyToKeep) { if (!string) return; const relevantKeys = this.keys().filter((str) => str.startsWith(string)); relevantKeys?.forEach((key) => { diff --git a/ui/app/templates/vault/cluster.hbs b/ui/app/templates/vault/cluster.hbs index 1f66dc965..e9c55ce38 100644 --- a/ui/app/templates/vault/cluster.hbs +++ b/ui/app/templates/vault/cluster.hbs @@ -1,9 +1,11 @@ - - +{{! Only show license banners for Enterprise }} +{{#if this.activeCluster.version.isEnterprise}} + +{{/if}}
{{#each this.flashMessages.queue as |flash|}} diff --git a/ui/tests/integration/components/license-banners-test.js b/ui/tests/integration/components/license-banners-test.js index 718efd51d..cd228f90c 100644 --- a/ui/tests/integration/components/license-banners-test.js +++ b/ui/tests/integration/components/license-banners-test.js @@ -25,6 +25,7 @@ module('Integration | Component | license-banners', function (hooks) { this.yesterday = subDays(mockNow, 1); this.nextMonth = addDays(mockNow, 30); this.outside30 = addDays(mockNow, 32); + this.tomorrow = addDays(mockNow, 1); this.version = this.owner.lookup('service:version'); this.version.version = '1.13.1+ent'; }); @@ -64,58 +65,89 @@ module('Integration | Component | license-banners', function (hooks) { test('it does not render the expired banner if it has been dismissed', async function (assert) { assert.expect(3); this.set('expiry', formatRFC3339(this.yesterday)); + const key = `dismiss-license-banner-${this.version.version}-${this.expiry}`; await render(hbs``); await click('[data-test-dismiss-expired]'); assert.dom('[data-test-license-banner-expired]').doesNotExist('Expired license banner does not render'); await render(hbs``); - const localStorageResult = JSON.parse(localStorage.getItem(`dismiss-license-banner-1.13.1+ent`)); + const localStorageResult = JSON.parse(localStorage.getItem(key)); assert.strictEqual(localStorageResult, 'expired'); assert .dom('[data-test-license-banner-expired]') .doesNotExist('The expired banner still does not render after a re-render.'); - localStorage.removeItem(`dismiss-license-banner-1.13.1+ent`); + localStorage.removeItem(key); }); test('it does not render the warning banner if it has been dismissed', async function (assert) { assert.expect(3); this.set('expiry', formatRFC3339(this.nextMonth)); + const key = `dismiss-license-banner-${this.version.version}-${this.expiry}`; await render(hbs``); await click('[data-test-dismiss-warning]'); assert.dom('[data-test-license-banner-warning]').doesNotExist('Warning license banner does not render'); await render(hbs``); - const localStorageResult = JSON.parse(localStorage.getItem(`dismiss-license-banner-1.13.1+ent`)); + const localStorageResult = JSON.parse(localStorage.getItem(key)); assert.strictEqual(localStorageResult, 'warning'); assert .dom('[data-test-license-banner-warning]') .doesNotExist('The warning banner still does not render after a re-render.'); - localStorage.removeItem(`dismiss-license-banner-1.13.1+ent`); + localStorage.removeItem(key); }); test('it renders a banner if the vault license has changed', async function (assert) { assert.expect(3); this.version.version = '1.12.1+ent'; this.set('expiry', formatRFC3339(this.nextMonth)); + const keyOldVersion = `dismiss-license-banner-${this.version.version}-${this.expiry}`; await render(hbs``); await click('[data-test-dismiss-warning]'); this.version.version = '1.13.1+ent'; + const keyNewVersion = `dismiss-license-banner-${this.version.version}-${this.expiry}`; await render(hbs``); assert .dom('[data-test-license-banner-warning]') .exists('The warning banner shows even though we have dismissed it earlier.'); await click('[data-test-dismiss-warning]'); - const localStorageResultNewVersion = JSON.parse( - localStorage.getItem(`dismiss-license-banner-1.13.1+ent`) - ); - const localStorageResultOldVersion = JSON.parse( - localStorage.getItem(`dismiss-license-banner-1.12.1+ent`) - ); + const localStorageResultNewVersion = JSON.parse(localStorage.getItem(keyNewVersion)); + const localStorageResultOldVersion = JSON.parse(localStorage.getItem(keyOldVersion)); // Check that localStorage was cleaned and no longer contains the old version storage key. - assert.strictEqual(localStorageResultOldVersion, null); - assert.strictEqual(localStorageResultNewVersion, 'warning'); + assert.strictEqual(localStorageResultOldVersion, null, 'local storage was cleared for the old version'); + assert.strictEqual( + localStorageResultNewVersion, + 'warning', + 'local storage holds the new version with a warning' + ); // If debugging this test remember to clear localStorage if the test was not run to completion. - localStorage.removeItem(`dismiss-license-banner-1.13.1+ent`); + localStorage.removeItem(keyNewVersion); + }); + + test('it renders a banner if the vault expiry has changed', async function (assert) { + assert.expect(3); + this.set('expiry', formatRFC3339(this.tomorrow)); + const keyOldExpiry = `dismiss-license-banner-${this.version.version}-${this.expiry}`; + await render(hbs``); + await click('[data-test-dismiss-warning]'); + this.set('expiry', formatRFC3339(this.nextMonth)); + const keyNewExpiry = `dismiss-license-banner-${this.version.version}-${this.expiry}`; + await render(hbs``); + assert + .dom('[data-test-license-banner-warning]') + .exists('The warning banner shows even though we have dismissed it earlier.'); + + await click('[data-test-dismiss-warning]'); + const localStorageResultNewExpiry = JSON.parse(localStorage.getItem(keyNewExpiry)); + const localStorageResultOldExpiry = JSON.parse(localStorage.getItem(keyOldExpiry)); + // Check that localStorage was cleaned and no longer contains the old version storage key. + assert.strictEqual(localStorageResultOldExpiry, null, 'local storage was cleared for the old expiry'); + assert.strictEqual( + localStorageResultNewExpiry, + 'warning', + 'local storage holds the new expiry with a warning' + ); + // If debugging this test remember to clear localStorage if the test was not run to completion. + localStorage.removeItem(keyNewExpiry); }); }); diff --git a/ui/tests/unit/lib/local-storage-test.js b/ui/tests/unit/lib/local-storage-test.js index 7e3b087e3..ce3d4292b 100644 --- a/ui/tests/unit/lib/local-storage-test.js +++ b/ui/tests/unit/lib/local-storage-test.js @@ -17,7 +17,7 @@ module('Unit | lib | local-storage', function (hooks) { test('it does not error if nothing is in local storage', async function (assert) { assert.expect(1); assert.strictEqual( - LocalStorage.cleanUpStorage('something', 'something-key'), + LocalStorage.cleanupStorage('something', 'something-key'), undefined, 'returns undefined and does not throw an error when method is called and nothing exist in localStorage.' ); @@ -29,7 +29,7 @@ module('Unit | lib | local-storage', function (hooks) { LocalStorage.setItem('beep-boop-bop-key', 'beep-boop-bop-value'); LocalStorage.setItem('string-key', 'string-key-value'); const storageLengthBefore = window.localStorage.length; - LocalStorage.cleanUpStorage('string', 'string-key'); + LocalStorage.cleanupStorage('string', 'string-key'); const storageLengthAfter = window.localStorage.length; assert.strictEqual( storageLengthBefore - storageLengthAfter,