From 4e5190245e267fe85e0a3ad6ce69c52194fddb5b Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 26 Jul 2022 17:29:37 +0100 Subject: [PATCH] ui: Make peered intentions read-only (#13814) * ui: Make peered intentions read-only * Replace "" to undefined for SourcePeer so its the same as PeerName * Fixup copypasta * Ensure tests run with no peers --- ui/packages/consul-ui/app/abilities/intention.js | 7 ++++++- .../components/consul/intention/list/table/index.hbs | 12 ++++++++++-- ui/packages/consul-ui/app/models/intention.js | 4 ++-- .../tests/acceptance/dc/intentions/delete.feature | 1 + .../acceptance/dc/intentions/navigation.feature | 1 + .../dc/services/show/intentions/index.feature | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ui/packages/consul-ui/app/abilities/intention.js b/ui/packages/consul-ui/app/abilities/intention.js index 91f3a013b..a9435f975 100644 --- a/ui/packages/consul-ui/app/abilities/intention.js +++ b/ui/packages/consul-ui/app/abilities/intention.js @@ -4,7 +4,12 @@ export default class IntentionAbility extends BaseAbility { resource = 'intention'; get canWrite() { - return super.canWrite && (typeof this.item === 'undefined' || !this.canViewCRD); + // Peered intentions aren't writable + if(typeof this.item !== 'undefined' && typeof this.item.SourcePeer !== 'undefined') { + return false; + } + return super.canWrite && + (typeof this.item === 'undefined' || !this.canViewCRD); } get canViewCRD() { return (typeof this.item !== 'undefined' && this.item.IsManagedByCRD); diff --git a/ui/packages/consul-ui/app/components/consul/intention/list/table/index.hbs b/ui/packages/consul-ui/app/components/consul/intention/list/table/index.hbs index 03e47c17e..e8190f483 100644 --- a/ui/packages/consul-ui/app/components/consul/intention/list/table/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/intention/list/table/index.hbs @@ -71,7 +71,6 @@ as |item index|> {{/if}} -{{#if (and (or (can "write intention" item=item) (can "view CRD intention" item=item)) (not-eq item.Meta.external-source 'consul-api-gateway'))}} + {{else}} +
  • + + View + +
  • {{/if}}
    -{{/if}} diff --git a/ui/packages/consul-ui/app/models/intention.js b/ui/packages/consul-ui/app/models/intention.js index b074425ea..f7fa85a47 100644 --- a/ui/packages/consul-ui/app/models/intention.js +++ b/ui/packages/consul-ui/app/models/intention.js @@ -1,7 +1,7 @@ import Model, { attr } from '@ember-data/model'; import { computed } from '@ember/object'; import { fragmentArray } from 'ember-data-model-fragments/attributes'; -import { nullValue } from 'consul-ui/decorators/replace'; +import replace, { nullValue } from 'consul-ui/decorators/replace'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'ID'; @@ -13,7 +13,7 @@ export default class Intention extends Model { @attr('string') Datacenter; @attr('string') Description; - @attr('string') SourcePeer; + @replace('', undefined) @attr('string') SourcePeer; @attr('string', { defaultValue: () => '*' }) SourceName; @attr('string', { defaultValue: () => '*' }) DestinationName; @attr('string', { defaultValue: () => 'default' }) SourceNS; diff --git a/ui/packages/consul-ui/tests/acceptance/dc/intentions/delete.feature b/ui/packages/consul-ui/tests/acceptance/dc/intentions/delete.feature index 52ca40690..85424e943 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/intentions/delete.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/intentions/delete.feature @@ -4,6 +4,7 @@ Feature: dc / intentions / deleting: Deleting items with confirmations, success Given 1 datacenter model with the value "datacenter" And 1 intention model from yaml --- + SourcePeer: "" SourceName: name DestinationName: destination SourceNS: default diff --git a/ui/packages/consul-ui/tests/acceptance/dc/intentions/navigation.feature b/ui/packages/consul-ui/tests/acceptance/dc/intentions/navigation.feature index 4b1bd2318..ff35ca22a 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/intentions/navigation.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/intentions/navigation.feature @@ -7,6 +7,7 @@ Feature: dc / intentions / navigation - ID: 755b72bd-f5ab-4c92-90cc-bed0e7d8e9f0 Action: allow Meta: ~ + SourcePeer: "" - ID: 755b72bd-f5ab-4c92-90cc-bed0e7d8e9f1 Action: deny Meta: ~ diff --git a/ui/packages/consul-ui/tests/acceptance/dc/services/show/intentions/index.feature b/ui/packages/consul-ui/tests/acceptance/dc/services/show/intentions/index.feature index 05521e23a..16e0b2bc6 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/services/show/intentions/index.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/services/show/intentions/index.feature @@ -21,13 +21,16 @@ Feature: dc / services / show / intentions / index: Intentions per service DestinationNS: default SourcePartition: default DestinationPartition: default + SourcePeer: "" - ID: 755b72bd-f5ab-4c92-90cc-bed0e7d8e9f1 Action: deny Meta: ~ + SourcePeer: "" - ID: 0755b72bd-f5ab-4c92-90cc-bed0e7d8e9f2 Action: deny Meta: ~ + SourcePeer: "" --- When I visit the service page for yaml --- @@ -41,7 +44,7 @@ Feature: dc / services / show / intentions / index: Intentions per service Scenario: I can see intentions And I see 3 intention models on the intentionList component And I click intention on the intentionList.intentions component - Then the url should be /dc1/services/service-0/intentions/peer:billing:default:name:default:default:destination + Then the url should be /dc1/services/service-0/intentions/default:default:name:default:default:destination Scenario: I can delete intentions And I click actions on the intentionList.intentions component And I click delete on the intentionList.intentions component