From b96e998fc90ca1704e66f4f799e2237155db2260 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 28 Jan 2022 14:45:41 -0800 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Add=20translations?= =?UTF-8?q?=20to=20host=20set=20and=20host=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scope/host-catalogs/host-catalog/host-sets/index.hbs | 4 ++-- .../scopes/scope/host-catalogs/host-catalog/hosts/index.hbs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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..7e6bcbd9d 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 @@ -27,7 +27,7 @@ {{#if hostSet.isStatic}} - {{t (concat 'resources.host-set.types.' hostSet.type)}} + {{t (concat 'resources.host-set.types.' hostSet.compositeType)}} {{else}} - {{hostSet.compositeType}} + {{t (concat 'resources.host-set.types.' hostSet.compositeType)}} {{/if}} 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..1cc9dfcae 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 @@ -29,7 +29,7 @@ {{#if host.isStatic}} - {{t (concat 'resources.host.types.' host.type)}} + {{t (concat 'resources.host.types.' host.compositeType)}} {{else}} - {{host.compositeType}} + {{t (concat 'resources.host.types.' host.compositeType)}} {{/if}} From 2bf38b12573fdd45a4e2b962f29fd64c85f97db2 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 28 Jan 2022 15:16:02 -0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20babel=20plugin?= =?UTF-8?q?=20unmet=20peer=20dependency=20in=20Rose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix babel plugin unmet peer dependency in Rose --- addons/rose/package.json | 1 + yarn.lock | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/addons/rose/package.json b/addons/rose/package.json index ac6d6bed3..292c1f3ca 100644 --- a/addons/rose/package.json +++ b/addons/rose/package.json @@ -59,6 +59,7 @@ "@storybook/theming": "^6.3.0", "babel-eslint": "^10.1.0", "babel-loader": "^8.2.2", + "babel-plugin-ember-modules-api-polyfill": "^2.12.0", "broccoli-asset-rev": "^3.0.0", "doctoc": "^2.0.1", "ember-auto-import": "^1.12.0", diff --git a/yarn.lock b/yarn.lock index 71c3884be..4d7607f29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6932,6 +6932,13 @@ babel-plugin-ember-data-packages-polyfill@^0.1.2: dependencies: "@ember-data/rfc395-data" "^0.0.4" +babel-plugin-ember-modules-api-polyfill@^2.12.0: + version "2.13.4" + resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-2.13.4.tgz#cf62bc9bfd808c48d810d5194f4329e9453bd603" + integrity sha512-uxQPkEQAzCYdwhZk16O9m1R4xtCRNy4oEUTBrccOPfzlIahRZJic/JeP/ZEL0BC6Mfq6r55eOg6gMF/zdFoCvA== + dependencies: + ember-rfc176-data "^0.3.13" + babel-plugin-ember-modules-api-polyfill@^3.5.0: version "3.5.0" resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-3.5.0.tgz#27b6087fac75661f779f32e60f94b14d0e9f6965" @@ -8530,9 +8537,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001157, caniuse-lite@^1.0.30001286: - version "1.0.30001300" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001300.tgz#11ab6c57d3eb6f964cba950401fd00a146786468" - integrity sha512-cVjiJHWGcNlJi8TZVKNMnvMid3Z3TTdDHmLDzlOdIiZq138Exvo0G+G0wTdVYolxKb4AYwC+38pxodiInVtJSA== + version "1.0.30001303" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001303.tgz#9b168e4f43ccfc372b86f4bc5a551d9b909c95c9" + integrity sha512-/Mqc1oESndUNszJP0kx0UaQU9kEv9nNtJ7Kn8AdA0mNnH8eR1cj0kG+NbNuC1Wq/b21eA8prhKRA3bbkjONegQ== capture-exit@^2.0.0: version "2.0.0" @@ -11468,7 +11475,7 @@ ember-resolver@^8.0.3: ember-cli-version-checker "^5.1.2" resolve "^1.20.0" -ember-rfc176-data@^0.3.15, ember-rfc176-data@^0.3.17: +ember-rfc176-data@^0.3.13, ember-rfc176-data@^0.3.15, ember-rfc176-data@^0.3.17: version "0.3.17" resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.17.tgz#d4fc6c33abd6ef7b3440c107a28e04417b49860a" integrity sha512-EVzTTKqxv9FZbEh6Ktw56YyWRAA0MijKvl7H8C06wVF+8f/cRRz3dXxa4nkwjzyVwx4rzKGuIGq77hxJAQhWWw== @@ -18735,9 +18742,9 @@ npm-user-validate@^1.0.1: integrity sha512-uQwcd/tY+h1jnEaze6cdX/LrhWhoBxfSknxentoqmIuStxUExxjWd3ULMLFPiFUrZKbOVMowH6Jq2FRWfmhcEw== npm@~6.14.6: - version "6.14.15" - resolved "https://registry.yarnpkg.com/npm/-/npm-6.14.15.tgz#97dd51af5b5d6225b611b40c5cb4d31da1d467fe" - integrity sha512-dkcQc4n+DiJAMYG2haNAMyJbmuvevjXz+WC9dCUzodw8EovwTIc6CATSsTEplCY6c0jG4OshxFGFJsrnKJguWA== + version "6.14.16" + resolved "https://registry.yarnpkg.com/npm/-/npm-6.14.16.tgz#a882d6b0b32d5212461f0c58719152add1a7b99a" + integrity sha512-LMiLGYsVNJfVPlQg7v2NYjG7iRIapcLv+oMunlq7fkXVx0BATCjRu7XyWl0G+iuZzHy4CjtM32QB8ox8juTgaw== dependencies: JSONStream "^1.3.5" abbrev "~1.1.1" From 9e74c137b7018e7928f43bcc79701786bf629a3e Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 31 Jan 2022 10:40:16 -0500 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20remove=20capabil?= =?UTF-8?q?ities=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 4/4] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20merge=20model=20?= =?UTF-8?q?and=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' })); }); });