From 0cd6d3f68125033803e772aa80d59ec8445d26ce Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Tue, 4 May 2021 14:33:54 -0600 Subject: [PATCH 01/33] initial setup, modify toolbar header --- ui/app/components/secret-edit.js | 2 + ui/app/styles/components/modal.scss | 14 ++ ui/app/templates/components/secret-edit.hbs | 212 ++++++++++++------ .../components/secret-version-menu.hbs | 30 ++- 4 files changed, 191 insertions(+), 67 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index 4adbc148bbc0..efed2949e43a 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -39,6 +39,8 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { isWrapping: false, showWrapButton: not('wrappedData'), + showDeleteModal: false, + // called with a bool indicating if there's been a change in the secretData onDataChange() {}, onRefresh() {}, diff --git a/ui/app/styles/components/modal.scss b/ui/app/styles/components/modal.scss index fe629265737a..9378ced2f1df 100644 --- a/ui/app/styles/components/modal.scss +++ b/ui/app/styles/components/modal.scss @@ -76,3 +76,17 @@ pre { background: #f7f8fa; border-top: 1px solid #bac1cc; } + +.modal-radio-button { + display: flex; + align-items: baseline; + margin-bottom: $spacing-xs; + + input { + top: 2px; + } + + .helper-text { + margin-left: 10px; + } +} diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index cefe55f43818..23348c837d52 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -33,74 +33,18 @@ {{/unless}} - {{#if (and (eq @mode "show") this.isV2 (not @model.failedServerRead))}} - - - - History - - - - - + Delete +
{{/if}} - {{#if (and (eq mode 'show') canDelete)}} - - Delete secret - - {{/if}} - {{#if (and (eq mode 'show') (or canEditV2Secret canEdit))}} {{#let (concat 'vault.cluster.secrets.backend.' (if (eq mode 'show') 'edit' 'show')) as |targetRoute|}} {{#unless (and isV2 (or isWriteWithoutRead modelForData.destroyed modelForData.deleted))}} @@ -116,7 +60,7 @@ @class={{concat "toolbar-link" (if D.isOpen " is-active")}} @tagName="button" > - Copy secret + Copy @@ -159,7 +103,66 @@ {{/unless}} + {{/let}} + {{/if}} + {{#if (and (eq @mode "show") this.isV2 (not @model.failedServerRead))}} + + {{!-- ARG TODO this content will move to under Version dropdown --}} + {{!-- + + History + + + + + +
--}} + {{/if}} + {{#if (and (eq mode 'show') (or canEditV2Secret canEdit))}} + {{#let (concat 'vault.cluster.secrets.backend.' (if (eq mode 'show') 'edit' 'show')) as |targetRoute|}} {{#if isV2}} +{{log this.showDeleteModal "showDelete modal"}} + + +
+ {{!-- + --}} +
+
+ + {{partial partialName}} diff --git a/ui/app/templates/components/secret-version-menu.hbs b/ui/app/templates/components/secret-version-menu.hbs index 15bc2d0e0b2c..1dd6edddd381 100644 --- a/ui/app/templates/components/secret-version-menu.hbs +++ b/ui/app/templates/components/secret-version-menu.hbs @@ -22,7 +22,33 @@ {{#if (has-block)}} {{yield}} {{/if}} - {{#if this.version.destroyed}} + {{!-- ARG TODO Add permissions here --}} + {{#each (reverse model.versions) as |secretVersion|}} +
  • + + Version {{secretVersion.version}} + {{#if (and (eq secretVersion.version model.currentVersion) (not secretVersion.deleted))}} + + {{else if secretVersion.deleted}} + + {{/if}} + +
  • + {{/each}} +
  • + + View version history + +
  • + + {{!-- ARG TODO this will all go under Delete in secret-edit.hbs --}} + {{!-- {{#if this.version.destroyed}}
  • {{/if}} {{/if}} - {{/if}} + {{/if}} --}} From 9b02bd19b9ba62cffe374563861c8b0ca60370e2 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 5 May 2021 09:57:54 -0600 Subject: [PATCH 02/33] footer buttons setup --- ui/app/components/secret-edit.js | 17 +++++++ ui/app/templates/components/secret-edit.hbs | 51 ++++++++++----------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index efed2949e43a..adddd32c3268 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -397,5 +397,22 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { formatJSON() { this.set('codemirrorString', this.secretData.toJSONString(true)); }, + + handleDelete() { + if (!this.deleteType) { + return; + } + console.log(this.deleteType, 'do something with the deleteType'); + this.router.transitionTo('vault.cluster.metrics.config'); + // this.rotateCredentials(backend, name) + // .then(() => { + // this.flashMessages.success(`Successfully rotated root credentials for connection "${name}"`); + // this.transitionToRoute(SHOW_ROUTE, name); + // }) + // .catch(e => { + // this.flashMessages.danger(`Error rotating root credentials: ${e.errors}`); + // this.transitionToRoute(SHOW_ROUTE, name); + // }); + }, }, }); diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index 23348c837d52..5a1151cc8961 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -186,7 +186,6 @@ -{{log this.showDeleteModal "showDelete modal"}}
    @@ -215,13 +213,12 @@
  • - - {{!-- ARG TODO this will all go under Delete in secret-edit.hbs --}} - {{!-- {{#if this.version.destroyed}} -
  • - -
  • - {{else}} - {{#if isFetchingVersionCapabilities}} -
  • - -
  • - {{else}} -
  • - {{#if this.version.deleted}} - {{#if canUndeleteVersion}} - - {{else}} - - {{/if}} - {{else if canDeleteVersion}} - - Delete version - - {{else}} - - {{/if}} -
  • - {{#if canDestroyVersion}} -
  • - - Permanently destroy version - -
  • - {{else}} - - {{/if}} - {{/if}} - {{/if}} --}} From a37eadcf4d67e1f1b62cfdfdc51200a9ceab51a3 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Tue, 11 May 2021 10:10:38 -0600 Subject: [PATCH 16/33] glimmerize secret-version-menu --- ui/app/components/secret-version-menu.js | 14 +++++++------- ui/app/templates/components/secret-edit.hbs | 1 - .../templates/components/secret-version-menu.hbs | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ui/app/components/secret-version-menu.js b/ui/app/components/secret-version-menu.js index ba03b3d02fc1..b7709943992f 100644 --- a/ui/app/components/secret-version-menu.js +++ b/ui/app/components/secret-version-menu.js @@ -1,8 +1,8 @@ -import Component from '@ember/component'; +import Component from '@glimmer/component'; -export default Component.extend({ - tagName: '', - version: null, - useDefaultTrigger: false, - onRefresh() {}, -}); +export default class SecretVersionMenu extends Component { + onRefresh() {} + get useDefaultTrigger() { + return this.args.useDefaultTrigger || false; + } +} diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index 9773dd2b68cb..f355cff5d487 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -173,7 +173,6 @@ +
    + + +
    + +{{/unless}} \ No newline at end of file diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index f090d77479d3..e07876a2918c 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -40,6 +40,7 @@ @canDelete={{canDelete}} @canUpdate={{canUpdate}} @navToNearestAncestor={{this.navToNearestAncestor}} + @isV2={{isV2}} /> {{/if}} {{#if (and (eq mode 'show') (or canEditV2Secret canUpdate))}} From e56898393b9e4033db085e5a7efe5af1416a5854 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 12 May 2021 12:19:44 -0600 Subject: [PATCH 25/33] refining --- ui/app/components/secret-delete-menu.js | 24 +++++++++++++++- .../components/secret-delete-menu.hbs | 28 ++++++++++--------- ui/app/templates/components/secret-edit.hbs | 2 -- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/ui/app/components/secret-delete-menu.js b/ui/app/components/secret-delete-menu.js index e4f468fc9fb1..f21d537a8753 100644 --- a/ui/app/components/secret-delete-menu.js +++ b/ui/app/components/secret-delete-menu.js @@ -11,6 +11,28 @@ export default class SecretDeleteMenu extends Component { @tracked showDeleteModal = false; + @maybeQueryRecord( + 'capabilities', + context => { + if (!context.args.model) { + return; + } + let backend = context.args.model.backend; + let id = context.args.model.id; + let path = context.args.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`; + return { + id: path, + }; + }, + 'isV2', + 'model', + 'model.id', + 'mode' + ) + updatePath; + @alias('updatePath.canDelete') canDelete; + @alias('updatePath.canUpdate') canUpdate; + @maybeQueryRecord( 'capabilities', context => { @@ -91,7 +113,7 @@ export default class SecretDeleteMenu extends Component { if (!deleteType) { return; } - if (deleteType === 'destroy-all-versions') { + if (deleteType === 'destroy-all-versions' || deleteType === 'v1') { let { id } = this.args.model; this.args.model.destroyRecord().then(() => { this.args.navToNearestAncestor.perform(id); diff --git a/ui/app/templates/components/secret-delete-menu.hbs b/ui/app/templates/components/secret-delete-menu.hbs index e4a6c1c13bce..5c2337b18f85 100644 --- a/ui/app/templates/components/secret-delete-menu.hbs +++ b/ui/app/templates/components/secret-delete-menu.hbs @@ -1,13 +1,15 @@ -{{#unless isV2}} - - Delete Secret - +{{#unless @isV2}} + {{#if this.canDelete}} + + Delete + + {{/if}} {{else}} {{#if (and this.canUndeleteVersion @modelForData.deleted)}} -{{/unless}} \ No newline at end of file +{{/unless}} diff --git a/ui/app/templates/components/secret-version-menu.hbs b/ui/app/templates/components/secret-version-menu.hbs index 548c22721618..672be6d5cb1e 100644 --- a/ui/app/templates/components/secret-version-menu.hbs +++ b/ui/app/templates/components/secret-version-menu.hbs @@ -5,7 +5,7 @@ as |D| > diff --git a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs index 2eceee3f4e58..9281ce6cedfe 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs @@ -22,31 +22,31 @@
    -
    - - Version {{list.item.version}} -
    - {{#if (eq list.item.version model.currentVersion)}} +
    + + Version {{list.item.version}} +
    + {{#if (eq list.item.version model.currentVersion)}}
    - - Current - + + Current +
    - {{/if}} - {{#if list.item.deleted}} + {{/if}} + {{#if list.item.deleted}}
    - - Deleted - + + Deleted +
    - {{/if}} - {{#if list.item.destroyed}} + {{/if}} + {{#if list.item.destroyed}}
    - - Destroyed - + + Destroyed +
    - {{/if}} + {{/if}}
    diff --git a/ui/tests/acceptance/secrets/backend/kv/secret-test.js b/ui/tests/acceptance/secrets/backend/kv/secret-test.js index 9fdde5a011f4..81f23ab6016f 100644 --- a/ui/tests/acceptance/secrets/backend/kv/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/kv/secret-test.js @@ -144,7 +144,7 @@ module('Acceptance | secrets/secret/create', function(hooks) { .submit(); await listPage.create(); await editPage.createSecret(secretPath, 'foo', 'bar'); - await showPage.deleteSecret(); + await showPage.deleteSecretV1(); assert.equal( currentRouteName(), 'vault.cluster.secrets.backend.list-root', @@ -305,7 +305,7 @@ module('Acceptance | secrets/secret/create', function(hooks) { await listPage.create(); await editPage.createSecret(secretPath, 'foo', 'bar'); await settled(); - await click('[data-test-popup-menu-trigger="history"]'); + await click('[data-test-popup-menu-trigger="version"]'); await settled(); await click('[data-test-version-history]'); await settled(); diff --git a/ui/tests/pages/secrets/backend/kv/show.js b/ui/tests/pages/secrets/backend/kv/show.js index 7d1071a94cf8..2ae41dc63e92 100644 --- a/ui/tests/pages/secrets/backend/kv/show.js +++ b/ui/tests/pages/secrets/backend/kv/show.js @@ -8,6 +8,7 @@ export default create({ text: text(), }), deleteBtn: clickable('[data-test-secret-delete] button'), + deleteBtnV1: clickable('[data-test-secret-v1-delete="true"] button'), confirmBtn: clickable('[data-test-confirm-button]'), rows: collection('data-test-row-label'), toggleJSON: clickable('[data-test-secret-json-toggle]'), @@ -22,4 +23,7 @@ export default create({ deleteSecret() { return this.deleteBtn().confirmBtn(); }, + deleteSecretV1() { + return this.deleteBtnV1().confirmBtn(); + }, }); From 0c912f89f9dca15552c3660b82154f2591d1216d Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Thu, 13 May 2021 10:40:41 -0600 Subject: [PATCH 29/33] add to test --- .../components/secret-delete-menu.hbs | 33 +++++----- .../secrets/backend/kv/secret-test.js | 63 +++++++++++++++++++ ui/tests/pages/secrets/backend/kv/show.js | 4 ++ 3 files changed, 85 insertions(+), 15 deletions(-) diff --git a/ui/app/templates/components/secret-delete-menu.hbs b/ui/app/templates/components/secret-delete-menu.hbs index 0dc8847c4227..195d98a3d142 100644 --- a/ui/app/templates/components/secret-delete-menu.hbs +++ b/ui/app/templates/components/secret-delete-menu.hbs @@ -26,6 +26,7 @@ type="button" class="toolbar-link" {{on "click" (fn this.toggleDeleteModal)}} + data-test-delete-open-modal > {{if (and (not @modelForData.deleted) (not @modelForData.destroyed)) "Delete" "Destroy"}} @@ -57,23 +58,25 @@

    How would you like to proceed?

    {{#unless @modelForData.destroyed}} {{#unless @modelForData.deleted}} -