From af7e539f3d0f960bf2b753ae7832793d07ef7bab Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Fri, 23 Jul 2021 16:33:45 -0400 Subject: [PATCH 1/8] feat: List credential libraries for a target --- addons/core/translations/resources/en-us.yaml | 5 ++ .../targets/target/credential-libraries.js | 18 +++++++ ui/admin/app/router.js | 1 + .../targets/target/credential-libraries.js | 35 ++++++++++++ .../scope/targets/target/-navigation.hbs | 3 ++ .../targets/target/credential-libraries.hbs | 54 +++++++++++++++++++ .../target/credential-libraries-test.js | 17 ++++++ .../target/credential-libraries-test.js | 16 ++++++ 8 files changed, 149 insertions(+) create mode 100644 ui/admin/app/controllers/scopes/scope/targets/target/credential-libraries.js create mode 100644 ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js create mode 100644 ui/admin/app/templates/scopes/scope/targets/target/credential-libraries.hbs create mode 100644 ui/admin/tests/unit/controllers/scopes/scope/targets/target/credential-libraries-test.js create mode 100644 ui/admin/tests/unit/routes/scopes/scope/targets/target/credential-libraries-test.js diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 8094abf9e..259824292 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -267,6 +267,11 @@ target: add: title: Add Host Sets description: Select host sets to assign to this target. + credential-library: + messages: + welcome: + title: Welcome to Credential Libraries + description: No credential libraries in this target. credential-store: title: Credential Store title_plural: Credential Stores diff --git a/ui/admin/app/controllers/scopes/scope/targets/target/credential-libraries.js b/ui/admin/app/controllers/scopes/scope/targets/target/credential-libraries.js new file mode 100644 index 000000000..ff0f8c558 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/targets/target/credential-libraries.js @@ -0,0 +1,18 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeTargetsTargetCredentialLibrariesController extends Controller { + // =services + + @service intl; + + // =attributes + + /** + * Translated credential library breadcrumb + * @type {string} + */ + get breadCrumb() { + return this.intl.t('resources.credential-library.title_plural'); + } +} diff --git a/ui/admin/app/router.js b/ui/admin/app/router.js index a1bfa1e18..8638e4e48 100644 --- a/ui/admin/app/router.js +++ b/ui/admin/app/router.js @@ -65,6 +65,7 @@ Router.map(function () { this.route('target', { path: ':target_id' }, function () { this.route('host-sets', function () {}); this.route('add-host-sets'); + this.route('credential-libraries'); }); this.route('new'); }); diff --git a/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js new file mode 100644 index 000000000..792cc2aa8 --- /dev/null +++ b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js @@ -0,0 +1,35 @@ +import Route from '@ember/routing/route'; +import { hash, all } from 'rsvp'; + +export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Route { + // =methods + + /** + * Loads all credential libraries under the current target + * and it's parent scope. + * @return {Promise{[CredentialLibraryModel]}} + */ + beforeModel() { + const { application_credential_library_ids: credential_library_ids } = + this.modelFor('scopes.scope.targets.target'); + return hash({ + credentialLibraries: all( + credential_library_ids.map((credential_library) => + this.store.findRecord( + 'credential-library', + credential_library.value, + { reload: true } + ) + ) + ), + }); + } + + /** + * Returns the previously loaded target instance. + * @return {TargetModel} + */ + model() { + return this.modelFor('scopes.scope.targets.target'); + } +} diff --git a/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs b/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs index adbeded12..be112a45a 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs @@ -5,4 +5,7 @@ {{t 'resources.host-set.title_plural'}} + + {{t 'resources.credential-library.title_plural'}} + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/targets/target/credential-libraries.hbs b/ui/admin/app/templates/scopes/scope/targets/target/credential-libraries.hbs new file mode 100644 index 000000000..ebba89bff --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/targets/target/credential-libraries.hbs @@ -0,0 +1,54 @@ +{{page-title (t 'resources.credential-library.title_plural')}} + +{{#if @model.credentialLibraries}} + + + + + {{t 'form.name.label'}} + {{t 'form.id.label'}} + + + + {{#each @model.credentialLibraries as |credentialLibrary|}} + + + + {{credentialLibrary.displayName}} + +

{{credentialLibrary.description}}

+
+ + + {{credentialLibrary.id}} + + +
+ {{/each}} +
+
+ +{{else}} + + + + + {{t 'resources.target.credential-library.messages.welcome.description'}} + + + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/tests/unit/controllers/scopes/scope/targets/target/credential-libraries-test.js b/ui/admin/tests/unit/controllers/scopes/scope/targets/target/credential-libraries-test.js new file mode 100644 index 000000000..76a26ff69 --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/targets/target/credential-libraries-test.js @@ -0,0 +1,17 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module( + 'Unit | Controller | scopes/scope/targets/target/credential-libraries', + function (hooks) { + setupTest(hooks); + + // TODO: Replace this with your real tests. + test('it exists', function (assert) { + let controller = this.owner.lookup( + 'controller:scopes/scope/targets/target/credential-libraries' + ); + assert.ok(controller); + }); + } +); diff --git a/ui/admin/tests/unit/routes/scopes/scope/targets/target/credential-libraries-test.js b/ui/admin/tests/unit/routes/scopes/scope/targets/target/credential-libraries-test.js new file mode 100644 index 000000000..894e3add0 --- /dev/null +++ b/ui/admin/tests/unit/routes/scopes/scope/targets/target/credential-libraries-test.js @@ -0,0 +1,16 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module( + 'Unit | Route | scopes/scope/targets/target/credential-libraries', + function (hooks) { + setupTest(hooks); + + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/targets/target/credential-libraries' + ); + assert.ok(route); + }); + } +); From 0dedbfb4116e9bb4e40ee51697c5988dab791af3 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Fri, 23 Jul 2021 17:04:39 -0400 Subject: [PATCH 2/8] docs: Fix comment for listing target credential libraries --- .../routes/scopes/scope/targets/target/credential-libraries.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js index 792cc2aa8..cb3570645 100644 --- a/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js +++ b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js @@ -5,8 +5,7 @@ export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Ro // =methods /** - * Loads all credential libraries under the current target - * and it's parent scope. + * Loads all credential libraries under the current target. * @return {Promise{[CredentialLibraryModel]}} */ beforeModel() { From 1e5d52410ef931418b6f131c8feb2c9025f8ec8c Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Fri, 23 Jul 2021 17:34:31 -0400 Subject: [PATCH 3/8] refactor: Cleanup credential library parameter name --- .../scopes/scope/targets/target/credential-libraries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js index cb3570645..17e3e2692 100644 --- a/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js +++ b/ui/admin/app/routes/scopes/scope/targets/target/credential-libraries.js @@ -9,11 +9,11 @@ export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Ro * @return {Promise{[CredentialLibraryModel]}} */ beforeModel() { - const { application_credential_library_ids: credential_library_ids } = + const { application_credential_library_ids: credential_libraries } = this.modelFor('scopes.scope.targets.target'); return hash({ credentialLibraries: all( - credential_library_ids.map((credential_library) => + credential_libraries.map((credential_library) => this.store.findRecord( 'credential-library', credential_library.value, From 7fd89bb946a251f763cc98ff71f56257fdfc7ee9 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Date: Fri, 23 Jul 2021 15:15:24 -0700 Subject: [PATCH 4/8] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Update=20ember-fetc?= =?UTF-8?q?h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/api/package.json b/addons/api/package.json index 2dfeaf358..d45cb03aa 100644 --- a/addons/api/package.json +++ b/addons/api/package.json @@ -29,7 +29,7 @@ "ember-cli-mirage": "^1.1.8", "ember-data": "^3.20.0", "ember-data-model-fragments": "5.0.0-beta.2", - "ember-fetch": "^8.0.1" + "ember-fetch": "^8.1.0" }, "devDependencies": { "@ember/optional-features": "^2.0.0", diff --git a/yarn.lock b/yarn.lock index 15234911f..dc51f4422 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9248,10 +9248,10 @@ ember-feature-flags@^6.0.0: dependencies: ember-cli-babel "^7.11.1" -ember-fetch@^8.0.1: - version "8.0.5" - resolved "https://registry.yarnpkg.com/ember-fetch/-/ember-fetch-8.0.5.tgz#0ed6257b3158473f662e72831cab223010c5ec50" - integrity sha512-tKwSWZ2l4jKynqUuF8qgwiCfzmnRWDDO2j5l0Lrn4TgZo8YXbdM3DfgheLSZd+aybBFEAtXBgKH0qaTox28LFg== +ember-fetch@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/ember-fetch/-/ember-fetch-8.1.0.tgz#6228f49baaf6f435af1e5c767e19ef638ff28883" + integrity sha512-797IPPuXrWGAecsAuCPH6+2pJCcawy7+CiRrtoe1qLhXJ6Ue0Lxu4loXxHHQNCxRvvUvx8tTDuP63sOKfi3xug== dependencies: abortcontroller-polyfill "^1.7.1" broccoli-concat "^4.2.5" From a7a84d64b96d9545701566148bab62f5e866fd78 Mon Sep 17 00:00:00 2001 From: dharini Date: Fri, 23 Jul 2021 15:33:29 -0700 Subject: [PATCH 5/8] =?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 6/8] 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 89b7d0345aa61c2514480cd14a07dd2e9367f869 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Sun, 25 Jul 2021 09:26:03 -0400 Subject: [PATCH 7/8] fix: Add feature flag to target credential libraries list --- .../templates/scopes/scope/targets/target/-navigation.hbs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs b/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs index be112a45a..c337646f9 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/-navigation.hbs @@ -5,7 +5,9 @@ {{t 'resources.host-set.title_plural'}} - - {{t 'resources.credential-library.title_plural'}} - + {{#if (feature-flag 'credential-store')}} + + {{t 'resources.credential-library.title_plural'}} + + {{/if}} \ No newline at end of file From 1d71e3bec8120d66e9b34f7409e9424a4a799884 Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 26 Jul 2021 12:37:37 -0700 Subject: [PATCH 8/8] =?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); + }); +});