From a7a84d64b96d9545701566148bab62f5e866fd78 Mon Sep 17 00:00:00 2001 From: dharini Date: Fri, 23 Jul 2021 15:33:29 -0700 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20delete=20cred?= =?UTF-8?q?=20library=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/core/translations/resources/en-us.yaml | 1 + .../credential-store/credential-libraries.js | 21 ++++++++++++++++++- .../credential-library/-actions.hbs | 13 ++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 8094abf9e..16d2cde4f 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -279,6 +279,7 @@ credential-library: description: A credential library is a resource that provides credentials. actions: create: New Credential Library + delete: Delete Credential Library messages: none: title: No Credential Libraries Available diff --git a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js index fa54e9691..0a0435003 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.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 ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesRoute extends Route { @@ -50,4 +51,22 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari ); this.refresh(); } -} + + /** + * Handle delete of a credential library + * @param {CredentialLibraryModel} credentialLibrary + */ + @action + @loading + @confirm('questions.delete-confirm') + @notifyError(({ message }) => message) + @notifyError(({ message }) => message, { catch: true }) + async delete(credentialLibrary) { + await credentialLibrary.destroyRecord(); + await this.replaceWith( + 'scopes.scope.credential-stores.credential-store.credential-libraries' + ); + this.refresh(); + } + } + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs index e69de29bb..759b187d5 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions.hbs @@ -0,0 +1,13 @@ + + + {{t 'resources.credential-library.actions.delete'}} + + \ No newline at end of file From ad3b9ed6849fd96e8f2bdf24ef05416e72e4534e Mon Sep 17 00:00:00 2001 From: dharini Date: Fri, 23 Jul 2021 15:41:14 -0700 Subject: [PATCH 2/3] add success message --- .../credential-store/credential-libraries.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js index 0a0435003..d9602dba4 100644 --- a/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js +++ b/ui/admin/app/routes/scopes/scope/credential-stores/credential-store/credential-libraries.js @@ -56,17 +56,16 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari * Handle delete of a credential library * @param {CredentialLibraryModel} credentialLibrary */ - @action - @loading - @confirm('questions.delete-confirm') - @notifyError(({ message }) => message) - @notifyError(({ message }) => message, { catch: true }) - async delete(credentialLibrary) { - await credentialLibrary.destroyRecord(); - await this.replaceWith( - 'scopes.scope.credential-stores.credential-store.credential-libraries' - ); - this.refresh(); - } - } - \ No newline at end of file + @action + @loading + @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') + async delete(credentialLibrary) { + await credentialLibrary.destroyRecord(); + await this.replaceWith( + 'scopes.scope.credential-stores.credential-store.credential-libraries' + ); + this.refresh(); + } +} From 1d71e3bec8120d66e9b34f7409e9424a4a799884 Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 26 Jul 2021 12:37:37 -0700 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20delete=20action=20an?= =?UTF-8?q?d=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #1996 --- .../credential-library-test.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ui/admin/tests/acceptance/credential-library/credential-library-test.js diff --git a/ui/admin/tests/acceptance/credential-library/credential-library-test.js b/ui/admin/tests/acceptance/credential-library/credential-library-test.js new file mode 100644 index 000000000..9faf69576 --- /dev/null +++ b/ui/admin/tests/acceptance/credential-library/credential-library-test.js @@ -0,0 +1,96 @@ +import { module, test } from 'qunit'; +import { visit, click } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { authenticateSession } from 'ember-simple-auth/test-support'; +import { resolve, reject } from 'rsvp'; +import sinon from 'sinon'; + +module('Acceptance | credential-library', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + let getCredentialLibraryCount; + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + }; + + const urls = { + globalScope: null, + orgScope: null, + projectScope: null, + credentialStores: null, + credentialStore: null, + credentialLibrary: null, + credentialLibraries: null, + newCredentialLibrary: null, + }; + + hooks.beforeEach(function () { + // Generate resources + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + instances.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.credentialStore = this.server.create('credential-store', { + scope: instances.scopes.project, + }); + instances.credentialLibrary = this.server.create('credential-library', { + scope: instances.scopes.project, + }); + // Generate route URLs for resources + urls.globalScope = `/scopes/global/scopes`; + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; + urls.projectScope = `/scopes/${instances.scopes.project.id}`; + urls.credentialStores = `${urls.projectScope}/credential-stores`; + urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`; + urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`; + urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`; + // Generate resource couner + getCredentialLibraryCount = () => + this.server.schema.credentialLibraries.all().models.length; + authenticateSession({}); + }); + + test('can delete credential library', async function (assert) { + assert.expect(1); + const count = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + }); + + test('can accept delete credential library 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 = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count - 1); + assert.ok(confirmService.confirm.calledOnce); + }); + + test('cannot cancel delete credential library 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 = getCredentialLibraryCount(); + await visit(urls.credentialLibrary); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(getCredentialLibraryCount(), count); + assert.ok(confirmService.confirm.calledOnce); + }); +});