Merge branch 'main' into feat-host-catalog-integration

This commit is contained in:
dharini committed 2022-01-31 11:27:50 -08:00
commit 99cb449ff7
57 files changed
+457 -343

No files matched your search

-37
View File
@@ -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);
}
}
@@ -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');
}
}
+27
View File
@@ -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);
}
}
@@ -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;
}
+24 -8
View File
@@ -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') {
+54
View File
@@ -7,4 +7,58 @@ export default class HostModel extends GeneratedHostModel {
* @type {FragmentHostAttributesModel}
*/
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
/**
* True if the host is static.
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
/**
* True if the host is plugin.
* @type {boolean}
*/
get isPlugin() {
return this.type === 'plugin';
}
/**
* True if the host plugin type is AWS.
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
}
/**
* True if the host plugin type is Azure.
* @type {boolean}
*/
get isAzure() {
return this.compositeType === 'azure';
}
/**
* If host is a plugin return `plugin.name`,
* otherwise return the host type.
* @type {string}
*/
get compositeType() {
return this.isPlugin ? this.plugin.name : this.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') {
this.type = 'static';
} else {
this.type = 'plugin';
this.plugin = { name: type };
}
}
}
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/abilities/collection';
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/abilities/host-catalog';
+24 -1
View File
@@ -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':
+8
View File
@@ -10,4 +10,12 @@ 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;
}
},
});
@@ -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(),
};
}
},
});
+1 -1
View File
@@ -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.
@@ -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' })
);
});
});
@@ -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' }));
});
});
@@ -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');
+80
View File
@@ -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');
});
});
@@ -85,6 +85,9 @@ host-catalog:
delete: Delete Host Catalog
types:
static: Static
unknown: Unknown
aws: AWS
azure: Azure
host-set:
title: Host Set
title_plural: Host Sets
@@ -111,6 +114,9 @@ host-set:
description: No hosts available for selection.
types:
static: Static
unknown: Unknown
aws: AWS
azure: Azure
host:
title: Host
title_plural: Hosts
@@ -130,6 +136,9 @@ host:
delete: Delete Host
types:
static: Static
unknown: Unknown
aws: AWS
azure: Azure
session:
title: Session
title_plural: Sessions
-30
View File
@@ -1,30 +0,0 @@
import CollectionAbility from 'api/abilities/collection';
import { inject as service } from '@ember/service';
export default class OverrideCollectionAbility extends CollectionAbility {
// =services
@service features;
// =permissions
/**
* Navigating to a resource is allowed if either list or create grants
* are present.
* @type {boolean}
*/
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);
}
}
+5 -12
View File
@@ -1,19 +1,12 @@
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.
* Navigating to a resource is allowed if either list or create grants
* are present.
* @type {boolean}
*/
hasAuthorizedAction() {
if (!this.features.isEnabled('capabilities')) return true;
return super.hasAuthorizedAction(...arguments);
get canNavigate() {
return this.canList || this.canCreate;
}
}
@@ -57,7 +57,7 @@
</dropdown.button>
{{/if}}
{{/if}}
{{#if (can 'create collection' @model collection='accounts')}}
{{#if (can 'create model' @model collection='accounts')}}
<dropdown.link
@route='scopes.scope.auth-methods.auth-method.accounts.new'
@@ -68,7 +68,7 @@
{{/if}}
{{#if (feature-flag 'managed-groups')}}
{{#if (can 'create collection' @model collection='managed-groups')}}
{{#if (can 'create model' @model collection='managed-groups')}}
{{#if @model.isOIDC}}
<dropdown.link
@route='scopes.scope.auth-methods.auth-method.managed-groups.new'
@@ -2,7 +2,7 @@
<nav.link @route='scopes.scope.auth-methods.auth-method.index'>
{{t 'titles.details'}}
</nav.link>
{{#if (can 'navigate collection' @model collection='accounts')}}
{{#if (can 'navigate model' @model collection='accounts')}}
<nav.link @route='scopes.scope.auth-methods.auth-method.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}}
<nav.link @route='scopes.scope.auth-methods.auth-method.managed-groups'>
{{t 'resources.managed-group.title_plural'}}
@@ -3,7 +3,7 @@
@dropdownRight={{true}}
as |dropdown|
>
{{#if (can 'create collection' @model collection='credential-libraries')}}
{{#if (can 'create model' @model collection='credential-libraries')}}
<dropdown.link
@route='scopes.scope.credential-stores.credential-store.credential-libraries.new'
@@ -2,7 +2,7 @@
<nav.link @route='scopes.scope.credential-stores.credential-store.index'>
{{t 'titles.details'}}
</nav.link>
{{#if (can 'navigate collection' @model collection='credential-libraries')}}
{{#if (can 'navigate model' @model collection='credential-libraries')}}
<nav.link
@route='scopes.scope.credential-stores.credential-store.credential-libraries'
@@ -36,9 +36,7 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (
this.can.can('list collection', scope, { collection: 'auth-methods' })
) {
if (this.can.can('list model', scope, { collection: 'auth-methods' })) {
const { type } = this;
return this.resourceFilterStore.queryBy(
'auth-method',
@@ -25,7 +25,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
let accounts;
if (
this.can.can('list collection', authMethod, {
this.can.can('list model', authMethod, {
collection: 'accounts',
})
) {
@@ -22,7 +22,7 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends
async model() {
const authMethod = this.modelFor('scopes.scope.auth-methods.auth-method');
const { id: auth_method_id } = authMethod;
const canListManagedGroups = this.can.can('list collection', authMethod, {
const canListManagedGroups = this.can.can('list model', authMethod, {
collection: 'managed-groups',
});
let managedGroups;
@@ -21,7 +21,7 @@ export default class ScopesScopeCredentialStoresRoute extends Route {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (
this.can.can('list collection', scope, {
this.can.can('list model', scope, {
collection: 'credential-stores',
})
) {
@@ -23,7 +23,7 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
);
const { id: credential_store_id } = credentialStore;
if (
this.can.can('list collection', credentialStore, {
this.can.can('list model', credentialStore, {
collection: 'credential-libraries',
})
) {
+1 -1
View File
@@ -30,7 +30,7 @@ export default class ScopesScopeGroupsRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (this.can.can('list collection', scope, { collection: 'groups' })) {
if (this.can.can('list model', scope, { collection: 'groups' })) {
return this.store.query('group', { scope_id });
}
}
@@ -30,9 +30,7 @@ export default class ScopesScopeHostCatalogsRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (
this.can.can('list collection', scope, { collection: 'host-catalogs' })
) {
if (this.can.can('list model', scope, { collection: 'host-catalogs' })) {
return this.store.query('host-catalog', { scope_id });
}
}
@@ -26,7 +26,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsRoute extends Rou
const { id: host_catalog_id } = hostCatalog;
if (
this.can.can('list collection', hostCatalog, {
this.can.can('list model', hostCatalog, {
collection: 'host-sets',
})
) {
@@ -25,7 +25,7 @@ export default class ScopesScopeHostCatalogsHostCatalogHostsRoute extends Route
);
const { id: host_catalog_id } = hostCatalog;
if (
this.can.can('list collection', hostCatalog, {
this.can.can('list model', hostCatalog, {
collection: 'hosts',
})
) {
+1 -1
View File
@@ -30,7 +30,7 @@ export default class ScopesScopeRolesRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (this.can.can('list collection', scope, { collection: 'roles' })) {
if (this.can.can('list model', scope, { collection: 'roles' })) {
return this.store.query('role', { scope_id });
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ export default class ScopesScopeTargetsRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (this.can.can('list collection', scope, { collection: 'targets' })) {
if (this.can.can('list model', scope, { collection: 'targets' })) {
return this.store.query('target', { scope_id });
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ export default class ScopesScopeUsersRoute extends Route {
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (this.can.can('list collection', scope, { collection: 'users' })) {
if (this.can.can('list model', scope, { collection: 'users' })) {
return this.store.query('user', { scope_id });
}
}
+8 -10
View File
@@ -71,7 +71,7 @@
</Rose::Nav::Sidebar>
--}}
<Rose::Nav::Sidebar @title={{t 'titles.resources'}} as |nav|>
{{#if (can 'navigate collection' @model collection='sessions')}}
{{#if (can 'navigate model' @model collection='sessions')}}
<nav.link @route='scopes.scope.sessions'>
<Rose::Icon
@name='flight-icons/svg/entry-point-16'
@@ -80,7 +80,7 @@
{{t 'resources.session.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='targets')}}
{{#if (can 'navigate model' @model collection='targets')}}
<nav.link @route='scopes.scope.targets'>
<Rose::Icon
@name='flight-icons/svg/crosshair-16'
@@ -89,7 +89,7 @@
{{t 'resources.target.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='host-catalogs')}}
{{#if (can 'navigate model' @model collection='host-catalogs')}}
<nav.link @route='scopes.scope.host-catalogs'>
<Rose::Icon
@name='flight-icons/svg/collections-16'
@@ -98,9 +98,7 @@
{{t 'resources.host-catalog.title_plural'}}
</nav.link>
{{/if}}
{{#if
(can 'navigate collection' @model collection='credential-stores')
}}
{{#if (can 'navigate model' @model collection='credential-stores')}}
{{#if (feature-flag 'credential-store')}}
<nav.link @route='scopes.scope.credential-stores'>
<Rose::Icon @name='flight-icons/svg/key-16' @size='medium' />
@@ -113,13 +111,13 @@
{{#unless @model.isProject}}
<Rose::Nav::Sidebar @title={{t 'titles.iam'}} as |nav|>
{{#if (can 'navigate collection' @model collection='users')}}
{{#if (can 'navigate model' @model collection='users')}}
<nav.link @route='scopes.scope.users'>
<Rose::Icon @name='flight-icons/svg/users-16' @size='medium' />
{{t 'resources.user.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='groups')}}
{{#if (can 'navigate model' @model collection='groups')}}
<nav.link @route='scopes.scope.groups'>
<Rose::Icon
@name='flight-icons/svg/folder-users-16'
@@ -128,7 +126,7 @@
{{t 'resources.group.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='roles')}}
{{#if (can 'navigate model' @model collection='roles')}}
<nav.link @route='scopes.scope.roles'>
<Rose::Icon
@name='flight-icons/svg/identity-user-16'
@@ -137,7 +135,7 @@
{{t 'resources.role.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='auth-methods')}}
{{#if (can 'navigate model' @model collection='auth-methods')}}
<nav.link @route='scopes.scope.auth-methods'>
<Rose::Icon @name='flight-icons/svg/lock-16' @size='medium' />
{{t 'resources.auth-method.title_plural'}}
@@ -131,14 +131,12 @@
>
<message.description>
{{#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 @@
</message.description>
{{#if
(can 'create collection' this.authMethod collection='accounts')
}}
{{#if (can 'create model' this.authMethod collection='accounts')}}
<message.link
@route='scopes.scope.auth-methods.auth-method.accounts.new'
@@ -69,14 +69,12 @@
<message.description>
{{#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 @@
</message.description>
{{#if
(can
'create collection' this.authMethod collection='managed-groups'
)
(can 'create model' this.authMethod collection='managed-groups')
}}
<message.link
@route='scopes.scope.auth-methods.auth-method.managed-groups.new'
@@ -12,7 +12,7 @@
</page.breadcrumbs>
<page.actions>
{{#if (can 'create collection' this.scopeModel collection='auth-methods')}}
{{#if (can 'create model' this.scopeModel collection='auth-methods')}}
<Rose::Dropdown
@text={{t 'titles.new'}}
@dropdownRight={{true}}
@@ -227,13 +227,11 @@
as |message|
>
<message.description>
{{#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
@@ -79,7 +79,7 @@
<message.description>
{{#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 @@
</message.description>
{{#if
(can
'create collection'
'create model'
this.credentialStore
collection='credential-libraries'
)
@@ -15,7 +15,7 @@
<page.actions>
{{#if (can 'create collection' this.scope collection='credential-stores')}}
{{#if (can 'create model' this.scope collection='credential-stores')}}
{{#if @model}}
<Rose::LinkButton
@route='scopes.scope.credential-stores.new'
@@ -82,13 +82,11 @@
as |message|
>
<message.description>
{{#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}}
</message.description>
{{#if
(can 'create collection' this.scope collection='credential-stores')
}}
{{#if (can 'create model' this.scope collection='credential-stores')}}
<message.link @route='scopes.scope.credential-stores.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -13,7 +13,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' this.scope collection='groups')}}
{{#if (can 'create model' this.scope collection='groups')}}
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.groups.new' @style='primary'>{{t
'titles.new'
@@ -71,10 +71,10 @@
as |message|
>
<message.description>
{{#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}}
</message.description>
{{#if (can 'create collection' this.scope collection='groups')}}
{{#if (can 'create model' this.scope collection='groups')}}
<message.link @route='scopes.scope.groups.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -3,7 +3,7 @@
@dropdownRight={{true}}
as |dropdown|
>
{{#if (can 'create collection' @model collection='hosts')}}
{{#if (can 'create model' @model collection='hosts')}}
<dropdown.link
@route='scopes.scope.host-catalogs.host-catalog.hosts.new'
@model={{@model}}
@@ -11,7 +11,7 @@
{{t 'resources.host.actions.create'}}
</dropdown.link>
{{/if}}
{{#if (can 'create collection' @model collection='host-sets')}}
{{#if (can 'create model' @model collection='host-sets')}}
<dropdown.link
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
@model={{@model}}
@@ -2,12 +2,12 @@
<nav.link @route='scopes.scope.host-catalogs.host-catalog.index'>
{{t 'titles.details'}}
</nav.link>
{{#if (can 'navigate collection' @model collection='hosts')}}
{{#if (can 'navigate model' @model collection='hosts')}}
<nav.link @route='scopes.scope.host-catalogs.host-catalog.hosts'>
{{t 'resources.host.title_plural'}}
</nav.link>
{{/if}}
{{#if (can 'navigate collection' @model collection='host-sets')}}
{{#if (can 'navigate model' @model collection='host-sets')}}
<nav.link @route='scopes.scope.host-catalogs.host-catalog.host-sets'>
{{t 'resources.host-set.title_plural'}}
</nav.link>
@@ -64,13 +64,11 @@
>
<message.description>
{{#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}}
</message.description>
{{#if (can 'create collection' this.hostCatalog collection='host-sets')}}
{{#if (can 'create model' this.hostCatalog collection='host-sets')}}
<message.link
@route='scopes.scope.host-catalogs.host-catalog.host-sets.new'
>
@@ -27,9 +27,21 @@
<p>{{host.description}}</p>
</row.headerCell>
<row.cell>
<Rose::Badge>
{{t (concat 'resources.host.types.' host.type)}}
</Rose::Badge>
{{#if host.isStatic}}
<Rose::Badge>
{{t (concat 'resources.host.types.' host.type)}}
</Rose::Badge>
{{else}}
<Rose::Badge
@icon={{concat
'flight-icons/svg/'
host.compositeType
'-color-16'
}}
>
{{host.compositeType}}
</Rose::Badge>
{{/if}}
</row.cell>
<row.cell>
<Copyable
@@ -57,13 +69,11 @@
>
<message.description>
{{#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'
@@ -78,7 +88,7 @@
{{/if}}
</message.description>
{{#if (can 'create collection' this.hostCatalog collection='hosts')}}
{{#if (can 'create model' this.hostCatalog collection='hosts')}}
<message.link
@route='scopes.scope.host-catalogs.host-catalog.hosts.new'
@@ -15,7 +15,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' this.scope collection='host-catalogs')}}
{{#if (can 'create model' this.scope collection='host-catalogs')}}
{{#if @model}}
<Rose::LinkButton
@route='scopes.scope.host-catalogs.new'
@@ -43,7 +43,7 @@
{{#each @model as |hostCatalog|}}
<body.row as |row|>
<row.headerCell>
{{#if (can 'read model' hostCatalog)}}
{{#if (can 'read host-catalog' hostCatalog)}}
<LinkTo
@route='scopes.scope.host-catalogs.host-catalog'
@model={{hostCatalog.id}}
@@ -59,7 +59,19 @@
{{#if hostCatalog.isStatic}}
<Rose::Badge>
{{t
(concat 'resources.host-catalog.types.' hostCatalog.type)
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
)
}}
</Rose::Badge>
{{else if hostCatalog.isUnknown}}
<Rose::Badge>
{{t
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
)
}}
</Rose::Badge>
{{else}}
@@ -70,7 +82,12 @@
'-color-16'
}}
>
{{hostCatalog.compositeType}}
{{t
(concat
'resources.host-catalog.types.'
hostCatalog.compositeType
)
}}
</Rose::Badge>
{{/if}}
</row.cell>
@@ -96,13 +113,11 @@
as |message|
>
<message.description>
{{#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
@@ -117,9 +132,7 @@
}}
{{/if}}
</message.description>
{{#if
(can 'create collection' this.scope collection='host-catalogs')
}}
{{#if (can 'create model' this.scope collection='host-catalogs')}}
<message.link @route='scopes.scope.host-catalogs.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -15,7 +15,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' this.scope collection='roles')}}
{{#if (can 'create model' this.scope collection='roles')}}
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.roles.new' @style='primary'>{{t
'titles.new'
@@ -70,10 +70,10 @@
as |message|
>
<message.description>
{{#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}}
</message.description>
{{#if (can 'create collection' this.scope collection='roles')}}
{{#if (can 'create model' this.scope collection='roles')}}
<message.link @route='scopes.scope.roles.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -26,7 +26,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' @model.currentScope collection='scopes')}}
{{#if (can 'create model' @model.currentScope collection='scopes')}}
{{#if @model.subScopes}}
<Rose::LinkButton @route='scopes.scope.new' @style='primary'>
{{t 'titles.new'}}
@@ -67,9 +67,7 @@
<message.description>
{{t 'resources.org.description'}}
</message.description>
{{#if
(can 'create collection' @model.currentScope collection='scopes')
}}
{{#if (can 'create model' @model.currentScope collection='scopes')}}
<message.link @route='scopes.scope.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -88,9 +86,7 @@
<message.description>
{{t 'resources.project.description'}}
</message.description>
{{#if
(can 'create collection' @model.currentScope collection='scopes')
}}
{{#if (can 'create model' @model.currentScope collection='scopes')}}
<message.link @route='scopes.scope.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -15,7 +15,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' this.scope collection='targets')}}
{{#if (can 'create model' this.scope collection='targets')}}
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.targets.new' @style='primary'>{{t
'titles.new'
@@ -81,12 +81,10 @@
>
<message.description>
{{#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}}
</message.description>
{{#if (can 'create collection' this.scope collection='targets')}}
{{#if (can 'create model' this.scope collection='targets')}}
<message.link @route='scopes.scope.targets.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
@@ -15,7 +15,7 @@
</page.header>
<page.actions>
{{#if (can 'create collection' this.scope collection='users')}}
{{#if (can 'create model' this.scope collection='users')}}
{{#if @model}}
<Rose::LinkButton @route='scopes.scope.users.new' @style='primary'>{{t
'titles.new'
@@ -73,10 +73,10 @@
as |message|
>
<message.description>
{{#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}}
</message.description>
{{#if (can 'create collection' this.scope collection='users')}}
{{#if (can 'create model' this.scope collection='users')}}
<message.link @route='scopes.scope.users.new'>
<Rose::Icon @name='flight-icons/svg/plus-circle-16' />
{{t 'titles.new'}}
-1
View File
@@ -95,7 +95,6 @@ module.exports = function (environment) {
'oidc-account-crud': true,
search: false,
filter: true,
capabilities: true,
'credential-store': true,
'managed-groups': true,
},
@@ -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' }));
});
});
-30
View File
@@ -1,30 +0,0 @@
import CollectionAbility from 'api/abilities/collection';
import { inject as service } from '@ember/service';
export default class OverrideCollectionAbility extends CollectionAbility {
// =services
@service features;
// =permissions
/**
* Navigating to a resource is allowed if either list or create grants
* are present.
* @type {boolean}
*/
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);
}
}
+5 -12
View File
@@ -1,19 +1,12 @@
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.
* Navigating to a resource is allowed if either list or create grants
* are present.
* @type {boolean}
*/
hasAuthorizedAction() {
if (!this.features.isEnabled('capabilities')) return true;
return super.hasAuthorizedAction(...arguments);
get canNavigate() {
return this.canList || this.canCreate;
}
}
-1
View File
@@ -58,7 +58,6 @@ module.exports = function (environment) {
oidc: true,
search: false,
filter: true,
capabilities: true,
'credential-store': false,
},
};
@@ -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' }));
});
});