From e6d68c2e4a515dc6a497e30ad7eb6c7cd5e88021 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Wed, 21 Sep 2022 15:10:28 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20fix=20routing=20for?= =?UTF-8?q?=20static=20credentials=20from=20targets=20(#1347)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 fix routing for static credentials from targets ✅ Closes: ICU-6155 * chore: 🤖 Add comment to isStatic credential helper method --- addons/api/addon/models/credential.js | 9 ++++++-- .../api/tests/unit/models/credential-test.js | 22 ++++++++++++------- .../target/brokered-credential-sources.hbs | 2 +- ...njected-application-credential-sources.hbs | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/addons/api/addon/models/credential.js b/addons/api/addon/models/credential.js index 3fee8cf9d..f7b81a6cb 100644 --- a/addons/api/addon/models/credential.js +++ b/addons/api/addon/models/credential.js @@ -1,5 +1,4 @@ import GeneratedCredentialModel from '../generated/models/credential'; -import { equal } from '@ember/object/computed'; /** * Supported Credential types. @@ -9,9 +8,15 @@ export const types = ['username_password', 'ssh_private_key']; export default class CredentialModel extends GeneratedCredentialModel { // =attributes /** + * All Credentials are prefixed with "cred" and are considered + * static due to their relation with Static Credential Stores. + * + * True if credential starts with the "cred" prefix. * @type {boolean} */ - @equal('type', 'username_password') isUsernamePassword; + get isStatic() { + return this.id.startsWith('cred'); + } /** * True if credential is an unknown type. diff --git a/addons/api/tests/unit/models/credential-test.js b/addons/api/tests/unit/models/credential-test.js index 1a091665a..21b5b98ce 100644 --- a/addons/api/tests/unit/models/credential-test.js +++ b/addons/api/tests/unit/models/credential-test.js @@ -10,21 +10,27 @@ module('Unit | Model | credential', function (hooks) { assert.ok(model); }); - test('it has isUsernamePassword property and returns the expected values', async function (assert) { - assert.expect(2); + test('it has isStatic property and returns the expected values', async function (assert) { + assert.expect(3); const store = this.owner.lookup('service:store'); - const modelA = store.createRecord('credential', { type: 'username_password' }); - const modelB = store.createRecord('credential', { type: 'ssh_private_key' }); + const modelA = store.createRecord('credential', { id: 'credup_123' }); + const modelB = store.createRecord('credential', { id: 'credspk_123' }); + const modelC = store.createRecord('credential', { id: 'notstatic_123' }); - assert.true(modelA.isUsernamePassword); - assert.false(modelB.isUsernamePassword); + assert.true(modelA.isStatic); + assert.true(modelB.isStatic); + assert.false(modelC.isStatic); }); test('it has isUnknown property and returns the expected values', async function (assert) { assert.expect(3); const store = this.owner.lookup('service:store'); - const modelA = store.createRecord('credential', { type: 'username_password' }); - const modelB = store.createRecord('credential', { type: 'ssh_private_key' }); + const modelA = store.createRecord('credential', { + type: 'username_password', + }); + const modelB = store.createRecord('credential', { + type: 'ssh_private_key', + }); const modelC = store.createRecord('credential', { type: 'unknown' }); assert.false(modelA.isUnknown); diff --git a/ui/admin/app/templates/scopes/scope/targets/target/brokered-credential-sources.hbs b/ui/admin/app/templates/scopes/scope/targets/target/brokered-credential-sources.hbs index 30cf574fd..f36044696 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/brokered-credential-sources.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/brokered-credential-sources.hbs @@ -40,7 +40,7 @@ {{#if brokeredCredentialSource.isUnknown}} {{brokeredCredentialSource.displayName}} {{else}} - {{#if brokeredCredentialSource.isUsernamePassword}} + {{#if brokeredCredentialSource.isStatic}}