Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Fix toast message text when deleting a kv v2 secret #28093

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/28093.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fixes toast (flash) alert message saying "created" when deleting a kv v2 secret
```
3 changes: 2 additions & 1 deletion ui/lib/kv/addon/components/page/secret/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export default class KvSecretDetails extends Component {
const { secret } = this.args;
try {
await secret.destroyRecord({ adapterOptions: { deleteType: type, deleteVersions: this.version } });
this.flashMessages.success(`Successfully ${secret.state} Version ${this.version} of ${secret.path}.`);
const verb = type.includes('delete') ? 'deleted' : 'destroyed';
this.flashMessages.success(`Successfully ${verb} Version ${this.version} of ${secret.path}.`);
this.refreshRoute();
} catch (err) {
const verb = type.includes('delete') ? 'deleting' : 'destroying';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { clearRecords, deleteLatestCmd, writeVersionedSecret } from 'vault/tests
import { setupControlGroup } from 'vault/tests/helpers/control-groups';
import { click, currentURL, visit } from '@ember/test-helpers';
import { PAGE } from 'vault/tests/helpers/kv/kv-selectors';
import sinon from 'sinon';

const ALL_DELETE_ACTIONS = ['delete', 'destroy', 'undelete'];
const assertDeleteActions = (assert, expected = ['delete', 'destroy']) => {
Expand Down Expand Up @@ -65,7 +66,8 @@ module('Acceptance | kv-v2 workflow | delete, undelete, destroy', function (hook
return;
});
test('can delete and undelete the latest secret version (a)', async function (assert) {
assert.expect(17);
assert.expect(18);
const flashSuccess = sinon.spy(this.owner.lookup('service:flash-messages'), 'success');
// go to secret details
await visit(`/vault/secrets/${this.backend}/kv/${this.secretPath}/details`);
// correct toolbar options & details show
Expand All @@ -78,6 +80,10 @@ module('Acceptance | kv-v2 workflow | delete, undelete, destroy', function (hook
assert.dom(PAGE.detail.deleteOptionLatest).isNotDisabled('delete latest option is selectable');
await click(PAGE.detail.deleteOptionLatest);
await click(PAGE.detail.deleteConfirm);
const expected = `Successfully deleted Version 4 of ${this.secretPath}.`;
const [actual] = flashSuccess.lastCall.args;
assert.strictEqual(actual, expected, 'renders correct flash message');

// details update accordingly
assert
.dom(PAGE.emptyStateTitle)
Expand Down Expand Up @@ -123,7 +129,8 @@ module('Acceptance | kv-v2 workflow | delete, undelete, destroy', function (hook
assertDeleteActions(assert, ['delete', 'destroy']);
});
test('can destroy a secret version (a)', async function (assert) {
assert.expect(9);
assert.expect(10);
const flashSuccess = sinon.spy(this.owner.lookup('service:flash-messages'), 'success');
// go to secret details
await visit(`/vault/secrets/${this.backend}/kv/${this.secretPath}/details?version=3`);
// correct toolbar options show
Expand All @@ -132,6 +139,9 @@ module('Acceptance | kv-v2 workflow | delete, undelete, destroy', function (hook
await click(PAGE.detail.destroy);
assert.dom(PAGE.detail.deleteModalTitle).includesText('Destroy version?', 'modal has correct title');
await click(PAGE.detail.deleteConfirm);
const expected = `Successfully destroyed Version 3 of ${this.secretPath}.`;
const [actual] = flashSuccess.lastCall.args;
assert.strictEqual(actual, expected, 'renders correct flash message');
// details update accordingly
assert
.dom(PAGE.emptyStateTitle)
Expand Down
Loading