From 470fce1e0790ab788205955585b469008acab385 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 13 Dec 2021 15:02:36 +0000 Subject: [PATCH] ui: Ensure we show a special readonly page for intentions (#11767) --- .changelog/11767.txt | 3 +++ .../components/consul/intention/form/index.hbs | 8 +++++++- .../components/consul/intention/view/index.hbs | 5 ++++- .../mock-api/v1/connect/intentions/exact | 2 +- .../acceptance/dc/intentions/read-only.feature | 15 +++++++++++++++ .../steps/dc/intentions/read-only-steps.js | 10 ++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 .changelog/11767.txt create mode 100644 ui/packages/consul-ui/tests/acceptance/dc/intentions/read-only.feature create mode 100644 ui/packages/consul-ui/tests/acceptance/steps/dc/intentions/read-only-steps.js diff --git a/.changelog/11767.txt b/.changelog/11767.txt new file mode 100644 index 000000000..6ce06f5f5 --- /dev/null +++ b/.changelog/11767.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Ensure we show a readonly designed page for readonly intentions +``` diff --git a/ui/packages/consul-ui/app/components/consul/intention/form/index.hbs b/ui/packages/consul-ui/app/components/consul/intention/form/index.hbs index 76281fd9c..0d3f875b4 100644 --- a/ui/packages/consul-ui/app/components/consul/intention/form/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/intention/form/index.hbs @@ -56,7 +56,10 @@ as |api|> -{{#let api.data as |item|}} +{{#let + api.data + (not (can 'write intention' item=api.data)) +as |item readonly|}} {{#if (not readonly)}} {{#let (changeset-get item 'Action') as |newAction|}} @@ -193,6 +196,7 @@ as |api|> {{else}} + {{#if item.IsManagedByCRD}} {{/if}} + {{/if}} {{/let}} diff --git a/ui/packages/consul-ui/app/components/consul/intention/view/index.hbs b/ui/packages/consul-ui/app/components/consul/intention/view/index.hbs index e5e6ea49d..e77f07c50 100644 --- a/ui/packages/consul-ui/app/components/consul/intention/view/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/intention/view/index.hbs @@ -1,4 +1,7 @@ -
+
diff --git a/ui/packages/consul-ui/mock-api/v1/connect/intentions/exact b/ui/packages/consul-ui/mock-api/v1/connect/intentions/exact index 40825c210..97c7db878 100644 --- a/ui/packages/consul-ui/mock-api/v1/connect/intentions/exact +++ b/ui/packages/consul-ui/mock-api/v1/connect/intentions/exact @@ -81,7 +81,7 @@ ${fake.helpers.randomize([ ], `:``} "Precedence": ${fake.random.number({min: 1, max: 100})}, -${ !legacy && fake.random.number({min: 1, max: 10}) > 2 ? ` +${ (!legacy || source[1] === "external-source") && fake.random.number({min: 1, max: 10}) > 2 ? ` "Meta": { "external-source": "${fake.helpers.randomize(['kubernetes', 'consul-api-gateway'])}" }, diff --git a/ui/packages/consul-ui/tests/acceptance/dc/intentions/read-only.feature b/ui/packages/consul-ui/tests/acceptance/dc/intentions/read-only.feature new file mode 100644 index 000000000..c67bfd4f0 --- /dev/null +++ b/ui/packages/consul-ui/tests/acceptance/dc/intentions/read-only.feature @@ -0,0 +1,15 @@ +@setupApplicationTest +Feature: dc / intentions / read-only + Scenario: Viewing a readonly intention + Given 1 datacenter model with the value "dc1" + And 1 intention model from yaml: + --- + Meta: + external-source: kubernetes + --- + When I visit the intention page for yaml + --- + dc: dc1 + intention: default:external-source:web:default:external-source:db + --- + Then I see the "[data-test-readonly]" element diff --git a/ui/packages/consul-ui/tests/acceptance/steps/dc/intentions/read-only-steps.js b/ui/packages/consul-ui/tests/acceptance/steps/dc/intentions/read-only-steps.js new file mode 100644 index 000000000..ba1093295 --- /dev/null +++ b/ui/packages/consul-ui/tests/acceptance/steps/dc/intentions/read-only-steps.js @@ -0,0 +1,10 @@ +import steps from '../../steps'; + +// step definitions that are shared between features should be moved to the +// tests/acceptance/steps/steps.js file + +export default function(assert) { + return steps(assert).then('I should find a file', function() { + assert.ok(true, this.step); + }); +}