From d157c63fe4f9fa64b801c54496da310c5b343b06 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 27 Sep 2021 17:19:32 +0100 Subject: [PATCH] ui: Don't show the CRD menu for read-only intentions (#11149) * ui: Don't show the CRD menu for read-only intentions The UI bug here manifests itself only when a user/token is configured to have read-only access to intentions. Instead of only letting folks click to see a read only page of the intention, we would show an additional message saying that the intention was read-only due to it being 'Managed by [a kubernetes] CRD'. Whilst the intention was still read only, this extra message was still confusing for users. This PR fixes up the conditional logic and further moves the logic to use ember-can - looking at the history of the files in question, this bug snuck itself in partly due to it being 'permission-y type stuff' previous to using ember-can and when something being editable or not was nothing to do with ACLs. Then we moved to start using ember-can without completely realising what IsEditable previously meant. So overall the code here is a tiny bit clearer/cleaner by adding a proper can view CRD intention instead of overloading the idea of 'editability'. --- .changelog/11149.txt | 3 +++ ui/packages/consul-ui/app/abilities/intention.js | 5 ++++- .../app/components/consul/intention/list/table/index.hbs | 4 +++- ui/packages/consul-ui/app/models/intention.js | 5 ----- ui/packages/consul-ui/app/templates/dc/intentions/edit.hbs | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .changelog/11149.txt diff --git a/.changelog/11149.txt b/.changelog/11149.txt new file mode 100644 index 000000000..b028e0ac7 --- /dev/null +++ b/.changelog/11149.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Don't show a CRD warning for read-only intentions +``` diff --git a/ui/packages/consul-ui/app/abilities/intention.js b/ui/packages/consul-ui/app/abilities/intention.js index 35551e670..91f3a013b 100644 --- a/ui/packages/consul-ui/app/abilities/intention.js +++ b/ui/packages/consul-ui/app/abilities/intention.js @@ -4,6 +4,9 @@ export default class IntentionAbility extends BaseAbility { resource = 'intention'; get canWrite() { - return super.canWrite && (typeof this.item === 'undefined' || this.item.IsEditable); + 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 35e2bd39a..25044226e 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 @@ -65,6 +65,7 @@ as |item index|> {{/if}} +{{#if (or (can "write intention" item=item) (can "view CRD intention" item=item))}} - {{else}} + {{else if (can "view CRD intention" item=item)}}
  • +{{/if}} diff --git a/ui/packages/consul-ui/app/models/intention.js b/ui/packages/consul-ui/app/models/intention.js index a0c8544f1..4f19696d2 100644 --- a/ui/packages/consul-ui/app/models/intention.js +++ b/ui/packages/consul-ui/app/models/intention.js @@ -41,9 +41,4 @@ export default class Intention extends Model { ); return typeof meta !== 'undefined'; } - - @computed('IsManagedByCRD') - get IsEditable() { - return !this.IsManagedByCRD; - } } diff --git a/ui/packages/consul-ui/app/templates/dc/intentions/edit.hbs b/ui/packages/consul-ui/app/templates/dc/intentions/edit.hbs index f933c7c25..56d54c379 100644 --- a/ui/packages/consul-ui/app/templates/dc/intentions/edit.hbs +++ b/ui/packages/consul-ui/app/templates/dc/intentions/edit.hbs @@ -31,7 +31,7 @@ as |item|}}

    - {{#if item.IsEditable}} + {{#if (can "write intention" item=item)}} {{#if item.ID}} {{else}}