From da42f7a00b19889a37c3436de6fec081417deb99 Mon Sep 17 00:00:00 2001 From: Chris Hut Date: Mon, 29 Jan 2024 15:38:21 -0800 Subject: [PATCH] Hide the hcp link banner behind an env variable (#20392) --- .../consul-ui/app/services/hcp-link-status.js | 6 +++-- .../consul-ui/app/utils/get-environment.js | 2 +- .../acceptance/link-to-hcp-banner-test.js | 25 ++++++++++++++++--- .../components/link-to-hcp-banner-test.js | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ui/packages/consul-ui/app/services/hcp-link-status.js b/ui/packages/consul-ui/app/services/hcp-link-status.js index cf03d8fc98..cdde716ee4 100644 --- a/ui/packages/consul-ui/app/services/hcp-link-status.js +++ b/ui/packages/consul-ui/app/services/hcp-link-status.js @@ -3,17 +3,19 @@ * SPDX-License-Identifier: BUSL-1.1 */ -import Service from '@ember/service'; +import Service, { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; const LOCAL_STORAGE_KEY = 'consul:hideHcpLinkBanner'; export default class HcpLinkStatus extends Service { + @service('env') env; @tracked userDismissedBanner = false; get shouldDisplayBanner() { - return !this.userDismissedBanner; + const hcpLinkEnabled = this.env.var('CONSUL_HCP_LINK_ENABLED'); + return !this.userDismissedBanner && hcpLinkEnabled; } constructor() { diff --git a/ui/packages/consul-ui/app/utils/get-environment.js b/ui/packages/consul-ui/app/utils/get-environment.js index faf4e787e8..91195d8962 100644 --- a/ui/packages/consul-ui/app/utils/get-environment.js +++ b/ui/packages/consul-ui/app/utils/get-environment.js @@ -146,7 +146,7 @@ export default function (config = {}, win = window, doc = document) { case 'CONSUL_API_PREFIX': // we want API prefix to look like an env var for if we ever change // operator config to be an API request, we need this variable before we - // make and API request so this specific variable should never be be + // make and API request so this specific variable should never be // retrived via an API request return operatorConfig.APIPrefix; case 'CONSUL_HCP_URL': diff --git a/ui/packages/consul-ui/tests/acceptance/link-to-hcp-banner-test.js b/ui/packages/consul-ui/tests/acceptance/link-to-hcp-banner-test.js index aa501a78e3..4761634d3d 100644 --- a/ui/packages/consul-ui/tests/acceptance/link-to-hcp-banner-test.js +++ b/ui/packages/consul-ui/tests/acceptance/link-to-hcp-banner-test.js @@ -6,6 +6,7 @@ import { module, test } from 'qunit'; import { click, visit } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; +import { EnvStub } from 'consul-ui/services/env'; const bannerSelector = '[data-test-link-to-hcp-banner]'; module('Acceptance | link to hcp banner', function (hooks) { @@ -14,9 +15,14 @@ module('Acceptance | link to hcp banner', function (hooks) { hooks.beforeEach(function () { // clear local storage so we don't have any settings window.localStorage.clear(); - // setupTestEnv(this.owner, { - // CONSUL_ACLS_ENABLED: true, - // }); + this.owner.register( + 'service:env', + class Stub extends EnvStub { + stubEnv = { + CONSUL_HCP_LINK_ENABLED: true, + }; + } + ); }); test('the banner is initially displayed on services page', async function (assert) { @@ -32,4 +38,17 @@ module('Acceptance | link to hcp banner', function (hooks) { await visit('/'); assert.dom(bannerSelector).doesNotExist('Banner is still gone after refresh'); }); + + test('the banner is not displayed if the env var is not set', async function (assert) { + this.owner.register( + 'service:env', + class Stub extends EnvStub { + stubEnv = {}; + } + ); + // default route is services page so we're good here + await visit('/'); + // Expect the banner to be visible by default + assert.dom(bannerSelector).doesNotExist('Banner is not here'); + }); }); diff --git a/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js b/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js index 424958a0f7..e3be9d5309 100644 --- a/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js +++ b/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js @@ -31,7 +31,7 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) { 'service:env', class Stub extends EnvStub { stubEnv = { - isEnterprise: false, + CONSUL_HCP_LINK_ENABLED: true, }; } );