From ba33c04cc937f23604372fdad6541e900092a29c Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Thu, 18 Oct 2018 13:03:05 -0500 Subject: [PATCH] check capabilities for version actions --- ui/app/components/secret-edit.js | 47 ++++++++++- ui/app/templates/components/secret-edit.hbs | 89 ++++++++++++--------- 2 files changed, 96 insertions(+), 40 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index b4dde7147..ab8ba64b0 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -93,7 +93,7 @@ export default Component.extend(FocusOnInsertMixin, { if (context.mode === 'create') { return; } - let backend = context.isV2 ? context.model.belongsTo('engine').id : context.model.backend; + let backend = context.isV2 ? context.get('model.engine.id') : context.model.backend; let id = context.model.id; let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; return { @@ -114,7 +114,7 @@ export default Component.extend(FocusOnInsertMixin, { if (context.mode === 'create' || context.isV2 === false) { return; } - let backend = context.model.belongsTo('engine').id; + let backend = context.get('model.engine.id'); let id = context.model.id; return { id: `${backend}/metadata/${id}`, @@ -127,6 +127,49 @@ export default Component.extend(FocusOnInsertMixin, { ), canEditV2Secret: alias('v2UpdatePath.canUpdate'), + deleteVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let backend = context.get('model.engine.id'); + let id = context.model.id; + return { + id: `${backend}/delete/${id}`, + }; + }, + 'model.id' + ), + canDeleteVersion: alias('deleteVersionPath.canUpdate'), + destroyVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let backend = context.get('model.engine.id'); + let id = context.model.id; + return { + id: `${backend}/destroy/${id}`, + }; + }, + 'model.id' + ), + canDestroyVersion: alias('destroyVersionPath.canUpdate'), + undeleteVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let backend = context.get('model.engine.id'); + let id = context.model.id; + return { + id: `${backend}/undelete/${id}`, + }; + }, + 'model.id' + ), + canUndeleteVersion: alias('undeleteVersionPath.canUpdate'), + + isFetchingVersionCapabilities: or( + 'deleteVersionPath.isLoading', + 'destroyVersionPath.isLoading', + 'undeleteVersionPath.isLoading' + ), + requestInFlight: or('model.isLoading', 'model.isReloading', 'model.isSaving'), buttonDisabled: or( diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index 532721966..751fea9c3 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -27,7 +27,7 @@ @buttonClasses="button is-compact is-ghost has-icon-right" @onConfirmAction={{action "deleteKey"}} @confirmMessage={{if isV2 - (concat "Are you sure you want to delete " model.id " AND ALL ITS VERSIONS?") + (concat "This will permanently delete " model.id " and all its versions. Are you sure you want to do this?") (concat "Are you sure you want to delete " model.id "?") }} @cancelButtonText="Cancel" @@ -52,7 +52,7 @@ /> - {{#if (and (eq mode 'show') canEdit)}} + {{#if (and (eq mode 'show') (or canEditV2Secret canEdit))}}
{{#let (concat 'vault.cluster.secrets.backend.' (if (eq mode 'show') 'edit' 'show')) as |targetRoute|}} {{#if isV2}} @@ -101,44 +101,57 @@ {{else}} -
  • - {{#if this.modelForData.deleted}} - - {{else}} - - Delete version - - {{/if}} -
  • - {{!-- TODO - check if canDestroy --}} - {{#if true}} + {{#if isFetchingVersionCapabilities}}
  • - - Permanently destroy version - +
  • + {{else}} +
  • + {{#if this.modelForData.deleted}} + {{#if canUndeleteVersion}} + + {{else}} + + {{/if}} + {{else if canDeleteVersion}} + + Delete version + + {{/if}} +
  • + {{#if canDestroyVersion}} +
  • + + Permanently destroy version + +
  • + {{/if}} {{/if}} {{/if}}