From 6e77ea655f4df1c403520cc16d9740856026e226 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 26 Jan 2022 13:03:21 -0500 Subject: [PATCH 01/10] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20support=20f?= =?UTF-8?q?or=20"unknown"=20dynamic=20host=20catalogs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/models/host-catalog.js | 32 ++++++--- addons/api/mirage/factories/host-catalog.js | 25 ++++++- .../generated/factories/host-catalog.js | 11 +-- addons/api/mirage/scenarios/default.js | 2 +- .../tests/unit/models/host-catalog-test.js | 72 ++++++++++++------- addons/core/translations/resources/en-us.yaml | 3 + .../scopes/scope/host-catalogs/index.hbs | 14 +++- 7 files changed, 114 insertions(+), 45 deletions(-) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index 8a0a64bd5..ec34b50e3 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -1,8 +1,12 @@ import GeneratedHostCatalogModel from '../generated/models/host-catalog'; +export const types = ['aws', 'azure']; + export default class HostCatalogModel extends GeneratedHostCatalogModel { + // =attributes + /** - * Returns if the host-catalog is static type or not. + * True if the host catalog is static. * @type {boolean} */ get isStatic() { @@ -10,7 +14,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { } /** - * Returns if the host-catalog is a plugin or not. + * True if the host catalog is a plugin. * @type {boolean} */ get isPlugin() { @@ -18,7 +22,15 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { } /** - * Returns if host-catalog plugin is AWS or not + * True if the host catalog is an unknown type. + * @type {boolean} + */ + get isUnknown() { + return this.isPlugin && !types.includes(this.plugin.name); + } + + /** + * True if host catalog plugin type is AWS. * @type {boolean} */ get isAWS() { @@ -26,23 +38,27 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { } /** - * Return if host-catalog plugin is Azure or not. + * True if host catalog plugin type is Azure. * @type {boolean} */ get isAzure() { return this.compositeType === 'azure'; } - /** If host-catalog is a plugins returns its name, - * otherwise returns the host-catalog type + /** + * If host catalog is a plugin return `plugin.name`, + * otherwise return the host catalog type. * @type {string} */ get compositeType() { - return this.isPlugin ? this.plugin.name : this.type; + if (this.isUnknown) return 'unknown'; + if (this.isPlugin) return this.plugin.name; + return 'static'; } /** - * Sets type, if type is different than static, sets plugin name to type + * Sets `type`. If type is different than `static`, sets `type` to `plugin` + * and `plugin.name` to the specified type. */ set compositeType(type) { if (type === 'static') { diff --git a/addons/api/mirage/factories/host-catalog.js b/addons/api/mirage/factories/host-catalog.js index 3179f2c99..4cd7423ae 100644 --- a/addons/api/mirage/factories/host-catalog.js +++ b/addons/api/mirage/factories/host-catalog.js @@ -1,7 +1,14 @@ import factory from '../generated/factories/host-catalog'; import { trait } from 'ember-cli-mirage'; import permissions from '../helpers/permissions'; -import { datatype, address } from 'faker'; +import { datatype, address, random } from 'faker'; + +const types = ['static', 'plugin']; +// Represents known plugin types, except "foobar" which models the possibility +// of receiving an _unknown_ type, which the UI must handle gracefully. +const pluginTypes = ['aws', 'azure', 'foobar']; + +let pluginTypeCounter = 1; export default factory.extend({ authorized_actions: () => @@ -17,6 +24,22 @@ export default factory.extend({ 'host-sets': ['create', 'list'], }; }, + + id: (i) => `host-catalog-id-${i}`, + + // Cycle through available types + type: (i) => types[i % types.length], + + plugin: function (i) { + if (this.type === 'plugin') { + return { + id: `plugin-id-${i}`, + name: pluginTypes[pluginTypeCounter++ % pluginTypes.length], + description: random.words(), + }; + } + }, + attributes() { switch (this.plugin?.name) { case 'aws': diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index fa8135226..36d5e64c6 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -5,19 +5,10 @@ import { random, date, datatype } from 'faker'; * GeneratedHostCatalogModelFactory */ export default Factory.extend({ - type: () => random.arrayElement(['static', 'plugin']), + type: 'static', name: () => random.words(), description: () => random.words(), created_time: () => date.recent(), updated_time: () => date.recent(), disabled: () => datatype.boolean(), - plugin: function (i) { - if (this.type == 'plugin') { - return { - id: `pl_${datatype.hexaDecimal(5)}`, - name: i % 2 ? 'aws' : 'azure', - description: random.words(), - }; - } - }, }); diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js index 51175f672..ceb61b566 100644 --- a/addons/api/mirage/scenarios/default.js +++ b/addons/api/mirage/scenarios/default.js @@ -46,7 +46,7 @@ export default function (server) { // Other resources server.schema.scopes.where({ type: 'project' }).models.forEach((scope) => { - server.createList('host-catalog', 4, { scope }, 'withChildren'); + server.createList('host-catalog', 8, { scope }, 'withChildren'); server.createList('credential-store', 3, { scope }, 'withAssociations'); server.createList('target', 2, { scope }, 'withAssociations'); // Sessions have target data. Create it after targets. diff --git a/addons/api/tests/unit/models/host-catalog-test.js b/addons/api/tests/unit/models/host-catalog-test.js index 7a8a77147..fb2c2cf51 100644 --- a/addons/api/tests/unit/models/host-catalog-test.js +++ b/addons/api/tests/unit/models/host-catalog-test.js @@ -10,29 +10,52 @@ module('Unit | Model | host catalog', function (hooks) { assert.ok(model); }); - test('it has isStatic function and returns the expected values', async function (assert) { + 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('host-catalog', { type: 'static' }); - const modelB = store.createRecord('host-catalog', { type: 'plugin' }); - assert.equal(typeof modelA.isStatic, 'boolean'); - assert.true(modelA.isStatic); + const modelA = store.createRecord('host-catalog', { compositeType: 'aws' }); + const modelB = store.createRecord('host-catalog', { + compositeType: 'foobar', + }); + const modelC = store.createRecord('host-catalog', { + compositeType: 'static', + }); + assert.false(modelA.isStatic); assert.false(modelB.isStatic); + assert.true(modelC.isStatic); }); - test('it has isPlugin function and returns the expected values', async function (assert) { - assert.expect(3); + test('it has isPlugin property and returns the expected values', async function (assert) { + assert.expect(2); const store = this.owner.lookup('service:store'); - const modelPlugin = store.createRecord('host-catalog', { type: 'plugin' }); - const modelStatic = store.createRecord('host-catalog', { type: 'static' }); - assert.equal(typeof modelPlugin.isPlugin, 'boolean'); + const modelPlugin = store.createRecord('host-catalog', { + compositeType: 'aws', + }); + const modelStatic = store.createRecord('host-catalog', { + compositeType: 'static', + }); assert.true(modelPlugin.isPlugin); assert.false(modelStatic.isPlugin); }); - test('it has isAWS function and returns the expected values', async function (assert) { + 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('host-catalog', { + compositeType: 'static', + }); + const modelB = store.createRecord('host-catalog', { compositeType: 'aws' }); + const modelC = store.createRecord('host-catalog', { + compositeType: 'no-such-type', + }); + assert.false(modelA.isUnknown); + assert.false(modelB.isUnknown); + assert.true(modelC.isUnknown); + }); + + test('it has isAWS property and returns the expected values', async function (assert) { + assert.expect(2); + const store = this.owner.lookup('service:store'); const modelAws = store.createRecord('host-catalog', { type: 'plugin', plugin: { name: 'aws' }, @@ -40,13 +63,12 @@ module('Unit | Model | host catalog', function (hooks) { const modelRandom = store.createRecord('host-catalog', { plugin: { name: 'random' }, }); - assert.equal(typeof modelAws.isAWS, 'boolean'); assert.true(modelAws.isAWS); assert.false(modelRandom.isAWS); }); - test('it has isAzure function and return the expected values', async function (assert) { - assert.expect(3); + test('it has isAzure property and return the expected values', async function (assert) { + assert.expect(2); const store = this.owner.lookup('service:store'); const modelAzure = store.createRecord('host-catalog', { type: 'plugin', @@ -55,7 +77,6 @@ module('Unit | Model | host catalog', function (hooks) { const modelRandom = store.createRecord('host-catalog', { plugin: { name: 'random' }, }); - assert.equal(typeof modelAzure.isAzure, 'boolean'); assert.true(modelAzure.isAzure); assert.false(modelRandom.isAzure); }); @@ -63,16 +84,20 @@ module('Unit | Model | host catalog', function (hooks) { test('get compositeType returns expected values', async function (assert) { assert.expect(3); const store = this.owner.lookup('service:store'); - const modelPlugin = store.createRecord('host-catalog', { - type: 'plugin', - plugin: { name: 'Test name' }, - }); - const modelStatic = store.createRecord('host-catalog', { + const modelA = store.createRecord('host-catalog', { type: 'static', }); - assert.equal(typeof modelPlugin.compositeType, 'string'); - assert.equal(modelPlugin.compositeType, 'Test name'); - assert.equal(modelStatic.compositeType, 'static'); + const modelB = store.createRecord('host-catalog', { + type: 'plugin', + plugin: { name: 'aws' }, + }); + const modelC = store.createRecord('host-catalog', { + type: 'plugin', + plugin: { name: 'no-such-type' }, + }); + assert.equal(modelA.compositeType, 'static'); + assert.equal(modelB.compositeType, 'aws'); + assert.equal(modelC.compositeType, 'unknown'); }); test('set compositeType sets expected values', async function (assert) { @@ -84,7 +109,6 @@ module('Unit | Model | host catalog', function (hooks) { const modelStatic = store.createRecord('host-catalog', { compositeType: 'static', }); - assert.equal(modelPlugin.type, 'plugin'); assert.equal(modelPlugin.plugin.name, 'aws'); assert.equal(modelStatic.type, 'static'); diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index f787cf133..d1de853d6 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -85,6 +85,7 @@ host-catalog: delete: Delete Host Catalog types: static: Static + unknown: Unknown host-set: title: Host Set title_plural: Host Sets @@ -111,6 +112,7 @@ host-set: description: No hosts available for selection. types: static: Static + unknown: Unknown host: title: Host title_plural: Hosts @@ -130,6 +132,7 @@ host: delete: Delete Host types: static: Static + unknown: Unknown session: title: Session title_plural: Sessions diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs index 7765915cd..b2280bc1a 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs @@ -59,7 +59,19 @@ {{#if hostCatalog.isStatic}} {{t - (concat 'resources.host-catalog.types.' hostCatalog.type) + (concat + 'resources.host-catalog.types.' + hostCatalog.compositeType + ) + }} + + {{else if hostCatalog.isUnknown}} + + {{t + (concat + 'resources.host-catalog.types.' + hostCatalog.compositeType + ) }} {{else}} From 6f0d5fd3389de668feb39566f311b5798faa7063 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 26 Jan 2022 13:27:25 -0500 Subject: [PATCH 02/10] =?UTF-8?q?chore:=20=F0=9F=A4=96=20disallow=20read?= =?UTF-8?q?=20on=20unknown=20catalogs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/abilities/host-catalog.js | 16 ++++++++++++++++ addons/api/app/abilities/host-catalog.js | 1 + addons/core/translations/resources/en-us.yaml | 6 ++++++ .../scopes/scope/host-catalogs/index.hbs | 9 +++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 addons/api/addon/abilities/host-catalog.js create mode 100644 addons/api/app/abilities/host-catalog.js diff --git a/addons/api/addon/abilities/host-catalog.js b/addons/api/addon/abilities/host-catalog.js new file mode 100644 index 000000000..6a6da85d0 --- /dev/null +++ b/addons/api/addon/abilities/host-catalog.js @@ -0,0 +1,16 @@ +import ModelAbility from './model'; + +/** + * Provides abilities for host catalogs. + */ +export default class HostCatalogAbility extends ModelAbility { + // =permissions + + /** + * Only "known" host catalog types may be read. + * @type {boolean} + */ + get canRead() { + return !this.model.isUnknown && this.hasAuthorizedAction('read'); + } +} diff --git a/addons/api/app/abilities/host-catalog.js b/addons/api/app/abilities/host-catalog.js new file mode 100644 index 000000000..a79d57652 --- /dev/null +++ b/addons/api/app/abilities/host-catalog.js @@ -0,0 +1 @@ +export { default } from 'api/abilities/host-catalog'; diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index d1de853d6..4ac6c4023 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -86,6 +86,8 @@ host-catalog: types: static: Static unknown: Unknown + aws: AWS + azure: Azure host-set: title: Host Set title_plural: Host Sets @@ -113,6 +115,8 @@ host-set: types: static: Static unknown: Unknown + aws: AWS + azure: Azure host: title: Host title_plural: Hosts @@ -133,6 +137,8 @@ host: types: static: Static unknown: Unknown + aws: AWS + azure: Azure session: title: Session title_plural: Sessions diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs index b2280bc1a..3b21dcb30 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/index.hbs @@ -43,7 +43,7 @@ {{#each @model as |hostCatalog|}} - {{#if (can 'read model' hostCatalog)}} + {{#if (can 'read host-catalog' hostCatalog)}} - {{hostCatalog.compositeType}} + {{t + (concat + 'resources.host-catalog.types.' + hostCatalog.compositeType + ) + }} {{/if}} From 929b020cf7aeb390cb032e4024745dc72b556876 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 26 Jan 2022 08:52:14 -0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20host=20type?= =?UTF-8?q?=20basic=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/generated/models/host.js | 6 ++ addons/api/addon/models/host.js | 53 +++++++++++++++ addons/api/tests/unit/models/host-test.js | 80 +++++++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/addons/api/addon/generated/models/host.js b/addons/api/addon/generated/models/host.js index 10486fe1d..08efa6397 100644 --- a/addons/api/addon/generated/models/host.js +++ b/addons/api/addon/generated/models/host.js @@ -43,4 +43,10 @@ export default class GeneratedHostModel extends BaseModel { description: 'Current version number of this resource.', }) version; + + @attr({ + description: 'Plugin information for this resource.', + readOnly: true, + }) + plugin; } diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 7748e023b..7bd65be52 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -7,4 +7,57 @@ export default class HostModel extends GeneratedHostModel { * @type {FragmentHostAttributesModel} */ @fragment('fragment-host-attributes', { defaultValue: {} }) attributes; + + /** + * Returns if the host is static type or not. + * @type {boolean} + */ + get isStatic() { + return this.type === 'static'; + } + + /** + * Returns if the host is plugin or not. + * @type {boolean} + */ + get isPlugin() { + return this.type === 'plugin'; + } + + /** + * Returns if host plugin is AWS or not. + * @type {boolean} + */ + get isAWS() { + return this.compositeType === 'aws'; + } + + /** + * Returns if hist is Azure or not. + * @type {boolean} + */ + get isAzure() { + return this.compositeType === 'azure'; + } + + /** + * If host is a plugin return its name, + * otherwise returns the host type + * @type {string} + */ + get compositeType() { + return this.isPlugin ? this.plugin.name : this.type; + } + + /** + * Sets type, if type is different than static, sets plugin name to type + */ + set compositeType(type) { + if (type === 'static') { + this.type = 'static'; + } else { + this.type = 'plugin'; + this.plugin = { name: type }; + } + } } diff --git a/addons/api/tests/unit/models/host-test.js b/addons/api/tests/unit/models/host-test.js index 625774e71..e6a4141f0 100644 --- a/addons/api/tests/unit/models/host-test.js +++ b/addons/api/tests/unit/models/host-test.js @@ -22,4 +22,84 @@ module('Unit | Model | host', function (hooks) { }); assert.equal(model.attributes.address, '127.0.0.1'); }); + + test('it has isStatic and returns the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelA = store.createRecord('host', { type: 'static' }); + const modelB = store.createRecord('host', { type: 'plugin' }); + assert.equal(typeof modelA.isStatic, 'boolean'); + assert.true(modelA.isStatic); + assert.false(modelB.isStatic); + }); + + test('it has isPlugin and returns the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelPlugin = store.createRecord('host', { type: 'plugin' }); + const modelStatic = store.createRecord('host', { type: 'static' }); + assert.equal(typeof modelPlugin.isPlugin, 'boolean'); + assert.true(modelPlugin.isPlugin); + assert.false(modelStatic.isPlugin); + }); + + test('it has isAWS and returns the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelAws = store.createRecord('host', { + type: 'plugin', + plugin: { name: 'aws' }, + }); + const modelRandom = store.createRecord('host', { + plugin: { name: 'random' }, + }); + assert.equal(typeof modelAws.isAWS, 'boolean'); + assert.true(modelAws.isAWS); + assert.false(modelRandom.isAWS); + }); + + test('it has isAzure and returns the expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelAzure = store.createRecord('host', { + type: 'plugin', + plugin: { name: 'azure' }, + }); + const modelRandom = store.createRecord('host', { + plugin: { name: 'random' }, + }); + assert.equal(typeof modelAzure.isAzure, 'boolean'); + assert.true(modelAzure.isAzure); + assert.false(modelRandom.isAzure); + }); + + test('get compositeType returns expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelPlugin = store.createRecord('host', { + type: 'plugin', + plugin: { name: 'Test name' }, + }); + const modelStatic = store.createRecord('host', { + type: 'static', + }); + assert.equal(typeof modelPlugin.compositeType, 'string'); + assert.equal(modelPlugin.compositeType, 'Test name'); + assert.equal(modelStatic.compositeType, 'static'); + }); + + test('set compositeType sets expected values', async function (assert) { + assert.expect(3); + const store = this.owner.lookup('service:store'); + const modelPlugin = store.createRecord('host', { + compositeType: 'aws', + }); + const modelStatic = store.createRecord('host', { + compositeType: 'static', + }); + + assert.equal(modelPlugin.type, 'plugin'); + assert.equal(modelPlugin.plugin.name, 'aws'); + assert.equal(modelStatic.type, 'static'); + }); }); From bb9d99eefbb34ebdda95d1dfa98bc86b9aace53b Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 26 Jan 2022 11:19:20 -0800 Subject: [PATCH 04/10] Add mirage support --- addons/api/mirage/generated/factories/host.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index db9de3b56..58e679e7b 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -5,7 +5,6 @@ import { random, date, internet, datatype } from 'faker'; * GeneratedHostModelFactory */ export default Factory.extend({ - type: 'static', name: () => random.words(), description: () => random.words(), created_time: () => date.recent(), @@ -14,4 +13,9 @@ export default Factory.extend({ attributes: () => { return { address: internet.ipv6() }; }, + plugin: function () { + if (this.type === 'plugin') { + return this.hostCatalog.plugin; + } + }, }); From 6ad42a5eaa803bc1d277149f898743e8375aeb4e Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 26 Jan 2022 11:39:01 -0800 Subject: [PATCH 05/10] Move plugin field generation from generated to a factory --- addons/api/mirage/factories/host.js | 5 +++++ addons/api/mirage/generated/factories/host.js | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/api/mirage/factories/host.js b/addons/api/mirage/factories/host.js index 895b44468..60300cba4 100644 --- a/addons/api/mirage/factories/host.js +++ b/addons/api/mirage/factories/host.js @@ -10,4 +10,9 @@ export default factory.extend({ 'delete', ], id: (i) => `host-id-${i}`, + plugin() { + if (this.type === 'plugin') { + return this.hostCatalog.plugin; + } + }, }); diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index 58e679e7b..7c6e5a24d 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -13,9 +13,4 @@ export default Factory.extend({ attributes: () => { return { address: internet.ipv6() }; }, - plugin: function () { - if (this.type === 'plugin') { - return this.hostCatalog.plugin; - } - }, }); From da1056d22222dd7702bccedf46665566903a4ca6 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 26 Jan 2022 14:06:22 -0800 Subject: [PATCH 06/10] Refactor host model comments --- addons/api/addon/models/host.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 7bd65be52..14acc4d27 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -9,7 +9,7 @@ export default class HostModel extends GeneratedHostModel { @fragment('fragment-host-attributes', { defaultValue: {} }) attributes; /** - * Returns if the host is static type or not. + * True if the host is static. * @type {boolean} */ get isStatic() { @@ -17,7 +17,7 @@ export default class HostModel extends GeneratedHostModel { } /** - * Returns if the host is plugin or not. + * True if the host is plugin. * @type {boolean} */ get isPlugin() { @@ -25,7 +25,7 @@ export default class HostModel extends GeneratedHostModel { } /** - * Returns if host plugin is AWS or not. + * True if the host plugin type is AWS. * @type {boolean} */ get isAWS() { @@ -33,7 +33,7 @@ export default class HostModel extends GeneratedHostModel { } /** - * Returns if hist is Azure or not. + * True if the host plugin type is Azure. * @type {boolean} */ get isAzure() { @@ -41,8 +41,8 @@ export default class HostModel extends GeneratedHostModel { } /** - * If host is a plugin return its name, - * otherwise returns the host type + * If host is a plugin return `plugin.name`, + * otherwise return the host type. * @type {string} */ get compositeType() { @@ -50,7 +50,8 @@ export default class HostModel extends GeneratedHostModel { } /** - * Sets type, if type is different than static, sets plugin name to type + * Sets `type`. If type is different than `static`, sets `type` to `plugin` + * and `plugin.name` to the specified type. */ set compositeType(type) { if (type === 'static') { From e150b15f0035cfed1a40884501fbeede2c18f983 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 27 Jan 2022 11:36:29 -0800 Subject: [PATCH 07/10] Add default value for type in mirage --- addons/api/mirage/factories/host.js | 3 +++ addons/api/mirage/generated/factories/host.js | 1 + 2 files changed, 4 insertions(+) diff --git a/addons/api/mirage/factories/host.js b/addons/api/mirage/factories/host.js index 60300cba4..980a5b26d 100644 --- a/addons/api/mirage/factories/host.js +++ b/addons/api/mirage/factories/host.js @@ -10,6 +10,9 @@ export default factory.extend({ 'delete', ], id: (i) => `host-id-${i}`, + type() { + return this.hostCatalog?.type || factory.attrs.type; + }, plugin() { if (this.type === 'plugin') { return this.hostCatalog.plugin; diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index 7c6e5a24d..db9de3b56 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -5,6 +5,7 @@ import { random, date, internet, datatype } from 'faker'; * GeneratedHostModelFactory */ export default Factory.extend({ + type: 'static', name: () => random.words(), description: () => random.words(), created_time: () => date.recent(), From 8c47612977e54d0d4ad6b112a71df131fa48012e Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Thu, 27 Jan 2022 12:35:04 -0800 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20type=20badge?= =?UTF-8?q?s=20to=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add type badges to host --- .../host-catalogs/host-catalog/hosts/index.hbs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs index afd87cccc..c60732eea 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs @@ -27,9 +27,21 @@

{{host.description}}

- - {{t (concat 'resources.host.types.' host.type)}} - + {{#if host.isStatic}} + + {{t (concat 'resources.host.types.' host.type)}} + + {{else}} + + {{host.compositeType}} + + {{/if}} Date: Mon, 31 Jan 2022 10:40:16 -0500 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20remove=20capab?= =?UTF-8?q?ilities=20feature=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/abilities/collection.js | 16 ---------------- ui/admin/app/abilities/model.js | 18 +----------------- ui/admin/config/environment.js | 1 - ui/desktop/app/abilities/collection.js | 16 ---------------- ui/desktop/app/abilities/model.js | 18 +----------------- ui/desktop/config/environment.js | 1 - 6 files changed, 2 insertions(+), 68 deletions(-) diff --git a/ui/admin/app/abilities/collection.js b/ui/admin/app/abilities/collection.js index 1da414d43..820e43903 100644 --- a/ui/admin/app/abilities/collection.js +++ b/ui/admin/app/abilities/collection.js @@ -1,11 +1,6 @@ import CollectionAbility from 'api/abilities/collection'; -import { inject as service } from '@ember/service'; export default class OverrideCollectionAbility extends CollectionAbility { - // =services - - @service features; - // =permissions /** @@ -16,15 +11,4 @@ export default class OverrideCollectionAbility extends CollectionAbility { get canNavigate() { return this.canList || this.canCreate; } - - // =methods - - /** - * If the capabilities feature flag is disabled, actions are always - * authorized. This mimics pre-capabilities behavior. - */ - hasAuthorizedCollectionAction() { - if (!this.features.isEnabled('capabilities')) return true; - return super.hasAuthorizedCollectionAction(...arguments); - } } diff --git a/ui/admin/app/abilities/model.js b/ui/admin/app/abilities/model.js index 0081f7d57..041ccf792 100644 --- a/ui/admin/app/abilities/model.js +++ b/ui/admin/app/abilities/model.js @@ -1,19 +1,3 @@ import ModelAbility from 'api/abilities/model'; -import { inject as service } from '@ember/service'; -export default class OverrideModelAbility extends ModelAbility { - // =services - - @service features; - - // =methods - - /** - * If the capabilities feature flag is disabled, actions are always - * authorized. This mimics pre-capabilities behavior. - */ - hasAuthorizedAction() { - if (!this.features.isEnabled('capabilities')) return true; - return super.hasAuthorizedAction(...arguments); - } -} +export default class OverrideModelAbility extends ModelAbility {} diff --git a/ui/admin/config/environment.js b/ui/admin/config/environment.js index dc951f583..f5d8c53b9 100644 --- a/ui/admin/config/environment.js +++ b/ui/admin/config/environment.js @@ -95,7 +95,6 @@ module.exports = function (environment) { 'oidc-account-crud': true, search: false, filter: true, - capabilities: true, 'credential-store': true, 'managed-groups': true, }, diff --git a/ui/desktop/app/abilities/collection.js b/ui/desktop/app/abilities/collection.js index 1da414d43..820e43903 100644 --- a/ui/desktop/app/abilities/collection.js +++ b/ui/desktop/app/abilities/collection.js @@ -1,11 +1,6 @@ import CollectionAbility from 'api/abilities/collection'; -import { inject as service } from '@ember/service'; export default class OverrideCollectionAbility extends CollectionAbility { - // =services - - @service features; - // =permissions /** @@ -16,15 +11,4 @@ export default class OverrideCollectionAbility extends CollectionAbility { get canNavigate() { return this.canList || this.canCreate; } - - // =methods - - /** - * If the capabilities feature flag is disabled, actions are always - * authorized. This mimics pre-capabilities behavior. - */ - hasAuthorizedCollectionAction() { - if (!this.features.isEnabled('capabilities')) return true; - return super.hasAuthorizedCollectionAction(...arguments); - } } diff --git a/ui/desktop/app/abilities/model.js b/ui/desktop/app/abilities/model.js index 0081f7d57..041ccf792 100644 --- a/ui/desktop/app/abilities/model.js +++ b/ui/desktop/app/abilities/model.js @@ -1,19 +1,3 @@ import ModelAbility from 'api/abilities/model'; -import { inject as service } from '@ember/service'; -export default class OverrideModelAbility extends ModelAbility { - // =services - - @service features; - - // =methods - - /** - * If the capabilities feature flag is disabled, actions are always - * authorized. This mimics pre-capabilities behavior. - */ - hasAuthorizedAction() { - if (!this.features.isEnabled('capabilities')) return true; - return super.hasAuthorizedAction(...arguments); - } -} +export default class OverrideModelAbility extends ModelAbility {} diff --git a/ui/desktop/config/environment.js b/ui/desktop/config/environment.js index c2d5f9c19..ab199e29e 100644 --- a/ui/desktop/config/environment.js +++ b/ui/desktop/config/environment.js @@ -58,7 +58,6 @@ module.exports = function (environment) { oidc: true, search: false, filter: true, - capabilities: true, 'credential-store': false, }, }; From 2bb63c377570de0f23f0aa7a108f431eeaf637a6 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 31 Jan 2022 12:02:37 -0500 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20merge=20model?= =?UTF-8?q?=20and=20collection=20abilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/abilities/collection.js | 37 ------------------ addons/api/addon/abilities/model.js | 27 +++++++++++++ addons/api/app/abilities/collection.js | 1 - .../tests/unit/abilities/collection-test.js | 38 ------------------- addons/api/tests/unit/abilities/model-test.js | 28 ++++++++++++++ ui/admin/app/abilities/collection.js | 14 ------- ui/admin/app/abilities/model.js | 11 +++++- .../auth-method/actions/index.hbs | 4 +- .../auth-methods/auth-method/nav/index.hbs | 4 +- .../credential-store/actions/index.hbs | 2 +- .../credential-store/nav/index.hbs | 2 +- .../app/routes/scopes/scope/auth-methods.js | 4 +- .../auth-methods/auth-method/accounts.js | 2 +- .../auth-method/managed-groups.js | 2 +- .../routes/scopes/scope/credential-stores.js | 2 +- .../credential-store/credential-libraries.js | 2 +- ui/admin/app/routes/scopes/scope/groups.js | 2 +- .../app/routes/scopes/scope/host-catalogs.js | 4 +- .../host-catalogs/host-catalog/host-sets.js | 2 +- .../scope/host-catalogs/host-catalog/hosts.js | 2 +- ui/admin/app/routes/scopes/scope/roles.js | 2 +- ui/admin/app/routes/scopes/scope/targets.js | 2 +- ui/admin/app/routes/scopes/scope/users.js | 2 +- ui/admin/app/templates/scopes/scope.hbs | 18 ++++----- .../auth-method/accounts/index.hbs | 10 ++--- .../auth-method/managed-groups/index.hbs | 10 ++--- .../scopes/scope/auth-methods/index.hbs | 8 ++-- .../credential-libraries/index.hbs | 6 +-- .../scopes/scope/credential-stores/index.hbs | 12 ++---- .../templates/scopes/scope/groups/index.hbs | 8 ++-- .../host-catalogs/host-catalog/-actions.hbs | 4 +- .../host-catalog/-navigation.hbs | 4 +- .../host-catalog/host-sets/index.hbs | 8 ++-- .../host-catalog/hosts/index.hbs | 8 ++-- .../scopes/scope/host-catalogs/index.hbs | 12 ++---- .../templates/scopes/scope/roles/index.hbs | 8 ++-- .../templates/scopes/scope/scopes/index.hbs | 10 ++--- .../templates/scopes/scope/targets/index.hbs | 10 ++--- .../templates/scopes/scope/users/index.hbs | 8 ++-- .../tests/unit/abilities/collection-test.js | 16 +++----- ui/desktop/app/abilities/collection.js | 14 ------- ui/desktop/app/abilities/model.js | 11 +++++- .../tests/unit/abilities/collection-test.js | 16 +++----- 43 files changed, 160 insertions(+), 237 deletions(-) delete mode 100644 addons/api/addon/abilities/collection.js delete mode 100644 addons/api/app/abilities/collection.js delete mode 100644 addons/api/tests/unit/abilities/collection-test.js delete mode 100644 ui/admin/app/abilities/collection.js delete mode 100644 ui/desktop/app/abilities/collection.js diff --git a/addons/api/addon/abilities/collection.js b/addons/api/addon/abilities/collection.js deleted file mode 100644 index 92f0e4342..000000000 --- a/addons/api/addon/abilities/collection.js +++ /dev/null @@ -1,37 +0,0 @@ -import { Ability } from 'ember-can'; - -/** - * Generic ability provides abilities common to all models in the API. - */ -export default class CollectionAbility extends Ability { - // =permissions - - /** - * @type {boolean} - */ - get canList() { - return this.hasAuthorizedCollectionAction('list'); - } - - /** - * @type {boolean} - */ - get canCreate() { - return this.hasAuthorizedCollectionAction('create'); - } - - // =methods - - /** - * Returns true if the given action is contained in the ability model's - * `authorized_collection_actions` array. - * @param {string} action - * @return {boolean} - */ - hasAuthorizedCollectionAction(action) { - const authorized_collection_actions = - (this.model || {}).authorized_collection_actions || {}; - const collection = this.collection || {}; - return authorized_collection_actions[collection]?.includes(action); - } -} diff --git a/addons/api/addon/abilities/model.js b/addons/api/addon/abilities/model.js index d820a8e02..d85663b5f 100644 --- a/addons/api/addon/abilities/model.js +++ b/addons/api/addon/abilities/model.js @@ -45,6 +45,20 @@ export default class ModelAbility extends Ability { return false; } + /** + * @type {boolean} + */ + get canList() { + return this.hasAuthorizedCollectionAction('list'); + } + + /** + * @type {boolean} + */ + get canCreate() { + return this.hasAuthorizedCollectionAction('create'); + } + // =methods /** @@ -56,4 +70,17 @@ export default class ModelAbility extends Ability { hasAuthorizedAction(action) { return this.model.authorized_actions?.includes(action); } + + /** + * Returns true if the given action is contained in the ability model's + * `authorized_collection_actions` array. + * @param {string} action + * @return {boolean} + */ + hasAuthorizedCollectionAction(action) { + const authorized_collection_actions = + (this.model || {}).authorized_collection_actions || {}; + const collection = this.collection || {}; + return authorized_collection_actions[collection]?.includes(action); + } } diff --git a/addons/api/app/abilities/collection.js b/addons/api/app/abilities/collection.js deleted file mode 100644 index 041825d2d..000000000 --- a/addons/api/app/abilities/collection.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'api/abilities/collection'; diff --git a/addons/api/tests/unit/abilities/collection-test.js b/addons/api/tests/unit/abilities/collection-test.js deleted file mode 100644 index b810e6939..000000000 --- a/addons/api/tests/unit/abilities/collection-test.js +++ /dev/null @@ -1,38 +0,0 @@ -import { module, test } from 'qunit'; -import { setupTest } from 'ember-qunit'; - -module('Unit | Abilities | Collection', function (hooks) { - setupTest(hooks); - - test('it reflects when a resource may be listed based on authorized_collection_actions', function (assert) { - assert.expect(2); - const service = this.owner.lookup('service:can'); - const model = { - authorized_collection_actions: { - foobars: ['list'], - }, - }; - assert.ok(service.can('list collection', model, { collection: 'foobars' })); - model.authorized_collection_actions.foobars = []; - assert.notOk( - service.can('list collection', model, { collection: 'foobars' }) - ); - }); - - test('it reflects when a resource may be created based on authorized_collection_actions', function (assert) { - assert.expect(2); - const service = this.owner.lookup('service:can'); - const model = { - authorized_collection_actions: { - foobars: ['create'], - }, - }; - assert.ok( - service.can('create collection', model, { collection: 'foobars' }) - ); - model.authorized_collection_actions.foobars = []; - assert.notOk( - service.can('create collection', model, { collection: 'foobars' }) - ); - }); -}); diff --git a/addons/api/tests/unit/abilities/model-test.js b/addons/api/tests/unit/abilities/model-test.js index 8bff24680..f19472db1 100644 --- a/addons/api/tests/unit/abilities/model-test.js +++ b/addons/api/tests/unit/abilities/model-test.js @@ -65,4 +65,32 @@ module('Unit | Abilities | Model', function (hooks) { model.authorized_actions = []; assert.notOk(service.can('delete model', model)); }); + + // =collections + + test('it reflects when a resource may be listed based on authorized_collection_actions', function (assert) { + assert.expect(2); + const service = this.owner.lookup('service:can'); + const model = { + authorized_collection_actions: { + foobars: ['list'], + }, + }; + assert.ok(service.can('list model', model, { collection: 'foobars' })); + model.authorized_collection_actions.foobars = []; + assert.notOk(service.can('list model', model, { collection: 'foobars' })); + }); + + test('it reflects when a resource may be created based on authorized_collection_actions', function (assert) { + assert.expect(2); + const service = this.owner.lookup('service:can'); + const model = { + authorized_collection_actions: { + foobars: ['create'], + }, + }; + assert.ok(service.can('create model', model, { collection: 'foobars' })); + model.authorized_collection_actions.foobars = []; + assert.notOk(service.can('create model', model, { collection: 'foobars' })); + }); }); diff --git a/ui/admin/app/abilities/collection.js b/ui/admin/app/abilities/collection.js deleted file mode 100644 index 820e43903..000000000 --- a/ui/admin/app/abilities/collection.js +++ /dev/null @@ -1,14 +0,0 @@ -import CollectionAbility from 'api/abilities/collection'; - -export default class OverrideCollectionAbility extends CollectionAbility { - // =permissions - - /** - * Navigating to a resource is allowed if either list or create grants - * are present. - * @type {boolean} - */ - get canNavigate() { - return this.canList || this.canCreate; - } -} diff --git a/ui/admin/app/abilities/model.js b/ui/admin/app/abilities/model.js index 041ccf792..d7e2b4c70 100644 --- a/ui/admin/app/abilities/model.js +++ b/ui/admin/app/abilities/model.js @@ -1,3 +1,12 @@ import ModelAbility from 'api/abilities/model'; -export default class OverrideModelAbility extends ModelAbility {} +export default class OverrideModelAbility extends ModelAbility { + /** + * Navigating to a resource is allowed if either list or create grants + * are present. + * @type {boolean} + */ + get canNavigate() { + return this.canList || this.canCreate; + } +} diff --git a/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs b/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs index 39c4a1d96..ec4111027 100644 --- a/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs +++ b/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs @@ -57,7 +57,7 @@ {{/if}} {{/if}} - {{#if (can 'create collection' @model collection='accounts')}} + {{#if (can 'create model' @model collection='accounts')}} {{t 'titles.details'}} - {{#if (can 'navigate collection' @model collection='accounts')}} + {{#if (can 'navigate model' @model collection='accounts')}} {{t 'resources.account.title_plural'}} @@ -10,7 +10,7 @@ {{/if}} {{#if (feature-flag 'managed-groups')}} - {{#if (can 'navigate collection' @model collection='managed-groups')}} + {{#if (can 'navigate model' @model collection='managed-groups')}} {{#if @model.isOIDC}} {{t 'resources.managed-group.title_plural'}} diff --git a/ui/admin/app/components/credential-stores/credential-store/actions/index.hbs b/ui/admin/app/components/credential-stores/credential-store/actions/index.hbs index b264a425a..4ba98f07d 100644 --- a/ui/admin/app/components/credential-stores/credential-store/actions/index.hbs +++ b/ui/admin/app/components/credential-stores/credential-store/actions/index.hbs @@ -3,7 +3,7 @@ @dropdownRight={{true}} as |dropdown| > - {{#if (can 'create collection' @model collection='credential-libraries')}} + {{#if (can 'create model' @model collection='credential-libraries')}} {{t 'titles.details'}} - {{#if (can 'navigate collection' @model collection='credential-libraries')}} + {{#if (can 'navigate model' @model collection='credential-libraries')}} --}} - {{#if (can 'navigate collection' @model collection='sessions')}} + {{#if (can 'navigate model' @model collection='sessions')}} {{/if}} - {{#if (can 'navigate collection' @model collection='targets')}} + {{#if (can 'navigate model' @model collection='targets')}} {{/if}} - {{#if (can 'navigate collection' @model collection='host-catalogs')}} + {{#if (can 'navigate model' @model collection='host-catalogs')}} {{/if}} - {{#if - (can 'navigate collection' @model collection='credential-stores') - }} + {{#if (can 'navigate model' @model collection='credential-stores')}} {{#if (feature-flag 'credential-store')}} @@ -113,13 +111,13 @@ {{#unless @model.isProject}} - {{#if (can 'navigate collection' @model collection='users')}} + {{#if (can 'navigate model' @model collection='users')}} {{t 'resources.user.title_plural'}} {{/if}} - {{#if (can 'navigate collection' @model collection='groups')}} + {{#if (can 'navigate model' @model collection='groups')}} {{/if}} - {{#if (can 'navigate collection' @model collection='roles')}} + {{#if (can 'navigate model' @model collection='roles')}} {{/if}} - {{#if (can 'navigate collection' @model collection='auth-methods')}} + {{#if (can 'navigate model' @model collection='auth-methods')}} {{t 'resources.auth-method.title_plural'}} diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs index 23568129e..b82aca3cb 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs @@ -131,14 +131,12 @@ > - {{#if - (can 'list collection' this.authMethod collection='accounts') - }} + {{#if (can 'list model' this.authMethod collection='accounts')}} {{! can list (at least): show default welcome message}} {{t 'resources.account.description'}} {{else if (can - 'create collection' this.authMethod collection='accounts' + 'create model' this.authMethod collection='accounts' )}} {{! can create (only): show create-but-not-list welcome message}} {{t @@ -155,9 +153,7 @@ - {{#if - (can 'create collection' this.authMethod collection='accounts') - }} + {{#if (can 'create model' this.authMethod collection='accounts')}} {{#if - (can - 'list collection' this.authMethod collection='managed-groups' - ) + (can 'list model' this.authMethod collection='managed-groups') }} {{! Can list (at least): show default welcome message }} {{t 'resources.managed-group.description'}} {{else if (can - 'create collection' this.authMethod collection='managed-groups' + 'create model' this.authMethod collection='managed-groups' )}} {{! Can create only: show create but not list welcome message }} {{t @@ -93,9 +91,7 @@ {{#if - (can - 'create collection' this.authMethod collection='managed-groups' - ) + (can 'create model' this.authMethod collection='managed-groups') }} - {{#if (can 'create collection' this.scopeModel collection='auth-methods')}} + {{#if (can 'create model' this.scopeModel collection='auth-methods')}} - {{#if - (can 'list collection' this.scopeModel collection='auth-methods') - }} + {{#if (can 'list model' this.scopeModel collection='auth-methods')}} {{! can list (at least): show default welcome message}} {{t 'resources.auth-method.messages.welcome.description'}} {{else if (can - 'create collection' this.scopeModel collection='auth-methods' + 'create model' this.scopeModel collection='auth-methods' )}} {{! can create (only): show create-but-not-list welcome message}} {{t diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs index d231ca381..3c3b603c5 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/credential-store/credential-libraries/index.hbs @@ -79,7 +79,7 @@ {{#if (can - 'list collection' + 'list model' this.credentialStore collection='credential-libraries' ) @@ -88,7 +88,7 @@ {{t 'resources.credential-library.description'}} {{else if (can - 'create collection' + 'create model' this.credentialStore collection='credential-libraries' )}} @@ -108,7 +108,7 @@ {{#if (can - 'create collection' + 'create model' this.credentialStore collection='credential-libraries' ) diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs index 299fa5844..49e297ebd 100644 --- a/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs +++ b/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs @@ -15,7 +15,7 @@ - {{#if (can 'create collection' this.scope collection='credential-stores')}} + {{#if (can 'create model' this.scope collection='credential-stores')}} {{#if @model}} - {{#if - (can 'list collection' this.scope collection='credential-stores') - }} + {{#if (can 'list model' this.scope collection='credential-stores')}} {{! can list (at least): show default welcome message}} {{t 'resources.credential-store.description'}} {{else if (can - 'create collection' this.scope collection='credential-stores' + 'create model' this.scope collection='credential-stores' )}} {{! can create (only): show create-but-not-list welcome message}} {{t @@ -103,9 +101,7 @@ }} {{/if}} - {{#if - (can 'create collection' this.scope collection='credential-stores') - }} + {{#if (can 'create model' this.scope collection='credential-stores')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/groups/index.hbs b/ui/admin/app/templates/scopes/scope/groups/index.hbs index 67bacc5f8..bbab758dc 100644 --- a/ui/admin/app/templates/scopes/scope/groups/index.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/index.hbs @@ -13,7 +13,7 @@ - {{#if (can 'create collection' this.scope collection='groups')}} + {{#if (can 'create model' this.scope collection='groups')}} {{#if @model}} {{t 'titles.new' @@ -71,10 +71,10 @@ as |message| > - {{#if (can 'list collection' this.scope collection='groups')}} + {{#if (can 'list model' this.scope collection='groups')}} {{! can list (at least): show default welcome message}} {{t 'resources.group.description'}} - {{else if (can 'create collection' this.scope collection='groups')}} + {{else if (can 'create model' this.scope collection='groups')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -88,7 +88,7 @@ }} {{/if}} - {{#if (can 'create collection' this.scope collection='groups')}} + {{#if (can 'create model' this.scope collection='groups')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs index 696c9e35e..e4166f25a 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/-actions.hbs @@ -3,7 +3,7 @@ @dropdownRight={{true}} as |dropdown| > - {{#if (can 'create collection' @model collection='hosts')}} + {{#if (can 'create model' @model collection='hosts')}} {{/if}} - {{#if (can 'create collection' @model collection='host-sets')}} + {{#if (can 'create model' @model collection='host-sets')}} {{t 'titles.details'}} - {{#if (can 'navigate collection' @model collection='hosts')}} + {{#if (can 'navigate model' @model collection='hosts')}} {{t 'resources.host.title_plural'}} {{/if}} - {{#if (can 'navigate collection' @model collection='host-sets')}} + {{#if (can 'navigate model' @model collection='host-sets')}} {{t 'resources.host-set.title_plural'}} diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs index b13cf374d..8e60985ca 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/host-sets/index.hbs @@ -64,13 +64,11 @@ > - {{#if (can 'list collection' this.hostCatalog collection='host-sets')}} + {{#if (can 'list model' this.hostCatalog collection='host-sets')}} {{! can list (at least): show default welcome message}} {{t 'resources.host-set.description'}} - {{else if (can - 'create collection' this.hostCatalog collection='host-sets' - )}} + {{else if (can 'create model' this.hostCatalog collection='host-sets')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -85,7 +83,7 @@ {{/if}} - {{#if (can 'create collection' this.hostCatalog collection='host-sets')}} + {{#if (can 'create model' this.hostCatalog collection='host-sets')}} diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs index c60732eea..c86594f02 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/host-catalog/hosts/index.hbs @@ -69,13 +69,11 @@ > - {{#if (can 'list collection' this.hostCatalog collection='hosts')}} + {{#if (can 'list model' this.hostCatalog collection='hosts')}} {{! can list (at least): show default welcome message}} {{t 'resources.host.description'}} - {{else if (can - 'create collection' this.hostCatalog collection='hosts' - )}} + {{else if (can 'create model' this.hostCatalog collection='hosts')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -90,7 +88,7 @@ {{/if}} - {{#if (can 'create collection' this.hostCatalog collection='hosts')}} + {{#if (can 'create model' this.hostCatalog collection='hosts')}} - {{#if (can 'create collection' this.scope collection='host-catalogs')}} + {{#if (can 'create model' this.scope collection='host-catalogs')}} {{#if @model}} - {{#if - (can 'list collection' this.scope collection='host-catalogs') - }} + {{#if (can 'list model' this.scope collection='host-catalogs')}} {{! can list (at least): show default welcome message}} {{t 'resources.host-catalog.description'}} {{else if (can - 'create collection' this.scope collection='host-catalogs' + 'create model' this.scope collection='host-catalogs' )}} {{! can create (only): show create-but-not-list welcome message}} {{t @@ -134,9 +132,7 @@ }} {{/if}} - {{#if - (can 'create collection' this.scope collection='host-catalogs') - }} + {{#if (can 'create model' this.scope collection='host-catalogs')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/roles/index.hbs b/ui/admin/app/templates/scopes/scope/roles/index.hbs index 64b1dd0a9..19fd914dc 100644 --- a/ui/admin/app/templates/scopes/scope/roles/index.hbs +++ b/ui/admin/app/templates/scopes/scope/roles/index.hbs @@ -15,7 +15,7 @@ - {{#if (can 'create collection' this.scope collection='roles')}} + {{#if (can 'create model' this.scope collection='roles')}} {{#if @model}} {{t 'titles.new' @@ -70,10 +70,10 @@ as |message| > - {{#if (can 'list collection' this.scope collection='roles')}} + {{#if (can 'list model' this.scope collection='roles')}} {{! can list (at least): show default welcome message}} {{t 'resources.roles.description'}} - {{else if (can 'create collection' this.scope collection='roles')}} + {{else if (can 'create model' this.scope collection='roles')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -87,7 +87,7 @@ }} {{/if}} - {{#if (can 'create collection' this.scope collection='roles')}} + {{#if (can 'create model' this.scope collection='roles')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/scopes/index.hbs b/ui/admin/app/templates/scopes/scope/scopes/index.hbs index 93ad6668a..5c2546baf 100644 --- a/ui/admin/app/templates/scopes/scope/scopes/index.hbs +++ b/ui/admin/app/templates/scopes/scope/scopes/index.hbs @@ -26,7 +26,7 @@ - {{#if (can 'create collection' @model.currentScope collection='scopes')}} + {{#if (can 'create model' @model.currentScope collection='scopes')}} {{#if @model.subScopes}} {{t 'titles.new'}} @@ -67,9 +67,7 @@ {{t 'resources.org.description'}} - {{#if - (can 'create collection' @model.currentScope collection='scopes') - }} + {{#if (can 'create model' @model.currentScope collection='scopes')}} {{t 'titles.new'}} @@ -88,9 +86,7 @@ {{t 'resources.project.description'}} - {{#if - (can 'create collection' @model.currentScope collection='scopes') - }} + {{#if (can 'create model' @model.currentScope collection='scopes')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/targets/index.hbs b/ui/admin/app/templates/scopes/scope/targets/index.hbs index 866e674a0..4705b4a2f 100644 --- a/ui/admin/app/templates/scopes/scope/targets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/index.hbs @@ -15,7 +15,7 @@ - {{#if (can 'create collection' this.scope collection='targets')}} + {{#if (can 'create model' this.scope collection='targets')}} {{#if @model}} {{t 'titles.new' @@ -81,12 +81,10 @@ > - {{#if (can 'list collection' this.scope collection='targets')}} + {{#if (can 'list model' this.scope collection='targets')}} {{! can list (at least): show default welcome message}} {{t 'resources.target.description'}} - {{else if (can - 'create collection' this.scope collection='targets' - )}} + {{else if (can 'create model' this.scope collection='targets')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -102,7 +100,7 @@ {{/if}} - {{#if (can 'create collection' this.scope collection='targets')}} + {{#if (can 'create model' this.scope collection='targets')}} {{t 'titles.new'}} diff --git a/ui/admin/app/templates/scopes/scope/users/index.hbs b/ui/admin/app/templates/scopes/scope/users/index.hbs index 2c78ceb2d..3b6259879 100644 --- a/ui/admin/app/templates/scopes/scope/users/index.hbs +++ b/ui/admin/app/templates/scopes/scope/users/index.hbs @@ -15,7 +15,7 @@ - {{#if (can 'create collection' this.scope collection='users')}} + {{#if (can 'create model' this.scope collection='users')}} {{#if @model}} {{t 'titles.new' @@ -73,10 +73,10 @@ as |message| > - {{#if (can 'list collection' this.scope collection='users')}} + {{#if (can 'list model' this.scope collection='users')}} {{! can list (at least): show default welcome message}} {{t 'resources.user.description'}} - {{else if (can 'create collection' this.scope collection='users')}} + {{else if (can 'create model' this.scope collection='users')}} {{! can create (only): show create-but-not-list welcome message}} {{t 'descriptions.create-but-not-list' @@ -90,7 +90,7 @@ }} {{/if}} - {{#if (can 'create collection' this.scope collection='users')}} + {{#if (can 'create model' this.scope collection='users')}} {{t 'titles.new'}} diff --git a/ui/admin/tests/unit/abilities/collection-test.js b/ui/admin/tests/unit/abilities/collection-test.js index 586eb52b4..889716e36 100644 --- a/ui/admin/tests/unit/abilities/collection-test.js +++ b/ui/admin/tests/unit/abilities/collection-test.js @@ -1,7 +1,7 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -module('Unit | Abilities | Collection', function (hooks) { +module('Unit | Abilities | model', function (hooks) { setupTest(hooks); test('it reflects when a resource may be navigated to based on list and create actions', function (assert) { @@ -11,19 +11,13 @@ module('Unit | Abilities | Collection', function (hooks) { authorized_collection_actions: { foobars: [] }, }; assert.notOk( - service.can('navigate collection', model, { collection: 'foobars' }) + service.can('navigate model', model, { collection: 'foobars' }) ); model.authorized_collection_actions.foobars = ['list']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); model.authorized_collection_actions.foobars = ['create']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); model.authorized_collection_actions.foobars = ['list', 'create']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); }); }); diff --git a/ui/desktop/app/abilities/collection.js b/ui/desktop/app/abilities/collection.js deleted file mode 100644 index 820e43903..000000000 --- a/ui/desktop/app/abilities/collection.js +++ /dev/null @@ -1,14 +0,0 @@ -import CollectionAbility from 'api/abilities/collection'; - -export default class OverrideCollectionAbility extends CollectionAbility { - // =permissions - - /** - * Navigating to a resource is allowed if either list or create grants - * are present. - * @type {boolean} - */ - get canNavigate() { - return this.canList || this.canCreate; - } -} diff --git a/ui/desktop/app/abilities/model.js b/ui/desktop/app/abilities/model.js index 041ccf792..d7e2b4c70 100644 --- a/ui/desktop/app/abilities/model.js +++ b/ui/desktop/app/abilities/model.js @@ -1,3 +1,12 @@ import ModelAbility from 'api/abilities/model'; -export default class OverrideModelAbility extends ModelAbility {} +export default class OverrideModelAbility extends ModelAbility { + /** + * Navigating to a resource is allowed if either list or create grants + * are present. + * @type {boolean} + */ + get canNavigate() { + return this.canList || this.canCreate; + } +} diff --git a/ui/desktop/tests/unit/abilities/collection-test.js b/ui/desktop/tests/unit/abilities/collection-test.js index 586eb52b4..889716e36 100644 --- a/ui/desktop/tests/unit/abilities/collection-test.js +++ b/ui/desktop/tests/unit/abilities/collection-test.js @@ -1,7 +1,7 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -module('Unit | Abilities | Collection', function (hooks) { +module('Unit | Abilities | model', function (hooks) { setupTest(hooks); test('it reflects when a resource may be navigated to based on list and create actions', function (assert) { @@ -11,19 +11,13 @@ module('Unit | Abilities | Collection', function (hooks) { authorized_collection_actions: { foobars: [] }, }; assert.notOk( - service.can('navigate collection', model, { collection: 'foobars' }) + service.can('navigate model', model, { collection: 'foobars' }) ); model.authorized_collection_actions.foobars = ['list']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); model.authorized_collection_actions.foobars = ['create']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); model.authorized_collection_actions.foobars = ['list', 'create']; - assert.ok( - service.can('navigate collection', model, { collection: 'foobars' }) - ); + assert.ok(service.can('navigate model', model, { collection: 'foobars' })); }); });