diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index a45cd1bab..9a1fccb8e 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -467,6 +467,7 @@ export default function () { this.get('/credential-stores/:id'); this.post('/credential-stores'); this.patch('/credential-stores/:id'); + this.del('/credential-stores/:id'); // credential-libraries diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index d889b0975..b2ec4d304 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -271,6 +271,8 @@ credential-store: title: Credential Store title_plural: Credential Stores description: A credential stores is a collection of credentials and credential libraries. + actions: + delete: Delete Credential Store credential-library: title: Credential Library title_plural: Credential Libraries diff --git a/addons/rose/addon/styles/rose/components/form/_fieldset.scss b/addons/rose/addon/styles/rose/components/form/_fieldset.scss index f35d3755c..c01a77a60 100644 --- a/addons/rose/addon/styles/rose/components/form/_fieldset.scss +++ b/addons/rose/addon/styles/rose/components/form/_fieldset.scss @@ -5,7 +5,7 @@ margin-bottom: sizing.rems(m); .rose-form-fieldset-title { - @include type.type(s, bold); + @include type.type(s, semibold); } .rose-form-fieldset-description { diff --git a/ui/admin/app/routes/scopes/scope/credential-stores.js b/ui/admin/app/routes/scopes/scope/credential-stores.js index 4bac020b1..8bfce1b1d 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores.js @@ -1,6 +1,7 @@ import Route from '@ember/routing/route'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; +import { confirm } from 'core/decorators/confirm'; import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeCredentialStoresRoute extends Route { @@ -44,4 +45,19 @@ export default class ScopesScopeCredentialStoresRoute extends Route { credentialStore.rollbackAttributes(); if (isNew) this.transitionTo('scopes.scope.credential-stores'); } + + /** + * Deletes the credential store and redirects to index + * @param {CredentialStoreModel} credentialStore + */ + @action + @loading + @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') + async delete(credentialStore) { + await credentialStore.destroyRecord(); + await this.replaceWith('scopes.scope.credential-stores'); + this.refresh(); + } } diff --git a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store.js b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store.js index fa5b56baf..046b8a01c 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store.js @@ -10,7 +10,7 @@ export default class ScopesScopeCredentialStoresCredentialStoreRoute extends Rou } /** - * Render credential store header, navigation, and actions page sections. + * Render credential store header, navigation and actions page sections. * @override */ renderTemplate() { diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/-actions.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/-actions.hbs index 587d095db..c08355da6 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/-actions.hbs @@ -1,5 +1,5 @@ @@ -9,4 +9,12 @@ > {{t 'resources.credential-library.actions.create'}} + + + {{t 'resources.credential-store.actions.delete'}} + \ No newline at end of file diff --git a/ui/admin/tests/acceptance/credential-stores-test.js b/ui/admin/tests/acceptance/credential-stores-test.js index f41d31a12..3979f664e 100644 --- a/ui/admin/tests/acceptance/credential-stores-test.js +++ b/ui/admin/tests/acceptance/credential-stores-test.js @@ -5,6 +5,8 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { authenticateSession } from 'ember-simple-auth/test-support'; import { Response } from 'miragejs'; +import { resolve, reject } from 'rsvp'; +import sinon from 'sinon'; module('Acceptance | credential-stores', function (hooks) { setupApplicationTest(hooks); @@ -236,4 +238,54 @@ module('Acceptance | credential-stores', function (hooks) { ); } }); + + test('can delete credential store', async function (assert) { + assert.expect(1); + const count = getCredentialStoresCount(); + await visit(urls.credentialStore); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialStoresCount(), count - 1); + }); + + test('can accept delete credential store via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(resolve()); + const count = getCredentialStoresCount(); + await visit(urls.credentialStore); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialStoresCount(), count - 1); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot cancel delete credential store via dialog', async function (assert) { + assert.expect(2); + const confirmService = this.owner.lookup('service:confirm'); + confirmService.enabled = true; + confirmService.confirm = sinon.fake.returns(reject()); + const count = getCredentialStoresCount(); + await visit(urls.credentialStore); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialStoresCount(), count); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('deleting a credential store which errors displays error messages', async function (assert) { + assert.expect(1); + this.server.del('/credential-stores/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.credentialStore); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + }); });