Reapply ember-can upgrade (#3111)
* chore: 🤖 reapply previous ember-can upgrade from #3093 * chore: 🤖 add missing ember-inflector dependency * chore: 🤖 move @ember/string to be a dependency in desktop * chore: 🤖 re-run pnpm install to resolve lockfile dupe key error * chore: 🤖 remove unused abilities service injections Co-Authored-By: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> --------- Co-authored-by: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com>
This commit is contained in:
1 parent
772857dbad
commit
3a847605ed
108 files changed
+533
-454
No files matched your search
@@ -16,7 +16,7 @@ class InvalidRolePrincipalTypeError extends Error {
|
||||
export default class RoleAbility extends ModelAbility {
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service abilities;
|
||||
|
||||
// =permissions
|
||||
|
||||
@@ -64,6 +64,6 @@ export default class RoleAbility extends ModelAbility {
|
||||
`Expected a role principal of type 'user', 'group', or 'managed-group'. Got '${type}'.`,
|
||||
);
|
||||
}
|
||||
return this.can.can(`read ${type}`, this.model);
|
||||
return this.abilities.can(`read ${type}`, this.model);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
"broccoli-plugin": "^4.0.7",
|
||||
"broccoli-source": "^3.0.1",
|
||||
"ember-auto-import": "^2.10.0",
|
||||
"ember-can": "^4.2.0",
|
||||
"ember-can": "^8.0.0",
|
||||
"ember-cli-babel": "^8.2.0",
|
||||
"ember-cli-htmlbars": "^6.3.0",
|
||||
"ember-data": "~5.3.12",
|
||||
|
||||
@@ -7,11 +7,12 @@ import Application from '@ember/application';
|
||||
import Resolver from 'ember-resolver';
|
||||
import loadInitializers from 'ember-load-initializers';
|
||||
import config from 'dummy/config/environment';
|
||||
import { extendResolver } from 'ember-can';
|
||||
|
||||
export default class App extends Application {
|
||||
modulePrefix = config.modulePrefix;
|
||||
podModulePrefix = config.podModulePrefix;
|
||||
Resolver = Resolver;
|
||||
Resolver = extendResolver(Resolver);
|
||||
}
|
||||
|
||||
loadInitializers(App, config.modulePrefix);
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
module('Unit | Abilities | Account', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
@@ -26,9 +26,9 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
const account = store.createRecord('auth-method', {
|
||||
authorized_actions: ['set-password'],
|
||||
});
|
||||
assert.true(canService.can('setPassword account', account));
|
||||
assert.true(abilitiesService.can('setPassword account', account));
|
||||
account.authorized_actions = [];
|
||||
assert.false(canService.can('setPassword account', account));
|
||||
assert.false(abilitiesService.can('setPassword account', account));
|
||||
});
|
||||
|
||||
test('can read known account types when authorized', function (assert) {
|
||||
@@ -36,13 +36,13 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: ['read'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('read account', account));
|
||||
assert.true(abilitiesService.can('read account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('read account', account));
|
||||
assert.true(abilitiesService.can('read account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('read account', account));
|
||||
assert.true(abilitiesService.can('read account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('read account', account));
|
||||
assert.false(abilitiesService.can('read account', account));
|
||||
});
|
||||
|
||||
test('cannot read accounts when unauthorized', function (assert) {
|
||||
@@ -50,13 +50,13 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: [],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.false(canService.can('read account', account));
|
||||
assert.false(abilitiesService.can('read account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(canService.can('read account', account));
|
||||
assert.false(abilitiesService.can('read account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(canService.can('read account', account));
|
||||
assert.false(abilitiesService.can('read account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('read account', account));
|
||||
assert.false(abilitiesService.can('read account', account));
|
||||
});
|
||||
|
||||
test('can delete known account types when authorized', function (assert) {
|
||||
@@ -64,13 +64,13 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('delete account', account));
|
||||
assert.false(abilitiesService.can('delete account', account));
|
||||
});
|
||||
|
||||
test('cannot delete accounts when unauthorized', function (assert) {
|
||||
@@ -78,13 +78,13 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('delete account', account));
|
||||
assert.true(abilitiesService.can('delete account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('delete account', account));
|
||||
assert.false(abilitiesService.can('delete account', account));
|
||||
});
|
||||
|
||||
test('can update known account types when authorized', function (assert) {
|
||||
@@ -92,13 +92,13 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: ['update'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('update account', account));
|
||||
assert.true(abilitiesService.can('update account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('update account', account));
|
||||
assert.true(abilitiesService.can('update account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('update account', account));
|
||||
assert.true(abilitiesService.can('update account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('update account', account));
|
||||
assert.false(abilitiesService.can('update account', account));
|
||||
});
|
||||
|
||||
test('cannot update accounts when unauthorized', function (assert) {
|
||||
@@ -106,12 +106,12 @@ module('Unit | Abilities | Account', function (hooks) {
|
||||
authorized_actions: [],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.false(canService.can('update account', account));
|
||||
assert.false(abilitiesService.can('update account', account));
|
||||
account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(canService.can('update account', account));
|
||||
assert.false(abilitiesService.can('update account', account));
|
||||
account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(canService.can('update account', account));
|
||||
assert.false(abilitiesService.can('update account', account));
|
||||
account.type = 'no-such-type';
|
||||
assert.false(canService.can('update account', account));
|
||||
assert.false(abilitiesService.can('update account', account));
|
||||
});
|
||||
});
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
@@ -27,13 +27,13 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: ['read'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('read auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('read auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('read auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('read auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('read auth-method', authMethod));
|
||||
});
|
||||
|
||||
test('cannot read auth methods when unauthorized', function (assert) {
|
||||
@@ -41,13 +41,13 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: [],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.false(canService.can('read auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(canService.can('read auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(canService.can('read auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('read auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('read auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('read auth-method', authMethod));
|
||||
});
|
||||
|
||||
test('can delete known auth method types when authorized', function (assert) {
|
||||
@@ -55,13 +55,13 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('delete auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('delete auth-method', authMethod));
|
||||
});
|
||||
|
||||
test('cannot delete auth methods when unauthorized', function (assert) {
|
||||
@@ -69,13 +69,13 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: ['delete'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('delete auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('delete auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('delete auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('delete auth-method', authMethod));
|
||||
});
|
||||
|
||||
test('can update known auth method types when authorized', function (assert) {
|
||||
@@ -83,13 +83,13 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: ['update'],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.true(canService.can('update auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(canService.can('update auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(canService.can('update auth-method', authMethod));
|
||||
assert.true(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('update auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('update auth-method', authMethod));
|
||||
});
|
||||
|
||||
test('cannot update auth methods when unauthorized', function (assert) {
|
||||
@@ -97,12 +97,12 @@ module('Unit | Abilities | Auth Method', function (hooks) {
|
||||
authorized_actions: [],
|
||||
type: TYPE_AUTH_METHOD_OIDC,
|
||||
});
|
||||
assert.false(canService.can('update auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(canService.can('update auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(canService.can('update auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('update auth-method', authMethod));
|
||||
authMethod.type = 'no-such-type';
|
||||
assert.false(canService.can('update auth-method', authMethod));
|
||||
assert.false(abilitiesService.can('update auth-method', authMethod));
|
||||
});
|
||||
});
|
||||
@@ -11,11 +11,11 @@ import { TYPE_SESSION_RECORDING_SSH } from 'api/models/session-recording';
|
||||
module('Unit | Ability | channel-recording', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
@@ -41,7 +41,10 @@ module('Unit | Ability | channel-recording', function (hooks) {
|
||||
});
|
||||
|
||||
assert.true(
|
||||
canService.can('getAsciicast channel-recording', channelRecordingModel),
|
||||
abilitiesService.can(
|
||||
'getAsciicast channel-recording',
|
||||
channelRecordingModel,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -62,7 +65,10 @@ module('Unit | Ability | channel-recording', function (hooks) {
|
||||
});
|
||||
|
||||
assert.false(
|
||||
canService.can('getAsciicast channel-recording', channelRecordingModel),
|
||||
abilitiesService.can(
|
||||
'getAsciicast channel-recording',
|
||||
channelRecordingModel,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@ module('Unit | Abilities | Group', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it reflects when a given group resource may add members based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['add-members'],
|
||||
};
|
||||
@@ -20,7 +20,7 @@ module('Unit | Abilities | Group', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given group resource may remove members based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['remove-members'],
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ module('Unit | Abilities | Host Set', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it reflects when a given host set resource may add hosts based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['add-hosts'],
|
||||
};
|
||||
@@ -20,7 +20,7 @@ module('Unit | Abilities | Host Set', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given hostSet resource may remove hosts based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['remove-hosts'],
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it reflects when a given model may be read based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['read'],
|
||||
};
|
||||
@@ -20,7 +20,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given model may be updated based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['update'],
|
||||
};
|
||||
@@ -30,7 +30,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given model may be saved based on isNew and authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
let model = {
|
||||
isNew: false,
|
||||
authorized_actions: ['update'],
|
||||
@@ -58,7 +58,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given model may be deleted based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['delete'],
|
||||
};
|
||||
@@ -70,7 +70,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
// =collections
|
||||
|
||||
test('it reflects when a resource may be listed based on authorized_collection_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_collection_actions: {
|
||||
foobars: ['list'],
|
||||
@@ -82,7 +82,7 @@ module('Unit | Abilities | Model', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a resource may be created based on authorized_collection_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_collection_actions: {
|
||||
foobars: ['create'],
|
||||
|
||||
@@ -10,7 +10,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it reflects when a given role may set grants based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['set-grants'],
|
||||
};
|
||||
@@ -20,7 +20,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given role may add principals based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['add-principals'],
|
||||
};
|
||||
@@ -30,7 +30,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
});
|
||||
|
||||
test('it reflects when a given role may remove principals based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['remove-principals'],
|
||||
};
|
||||
@@ -40,7 +40,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
});
|
||||
|
||||
test('it proxies role principal read ability to the appropriate ability type', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const user = {
|
||||
constructor: { modelName: 'user' },
|
||||
authorized_actions: [],
|
||||
@@ -65,7 +65,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
});
|
||||
|
||||
test('it throws an error for unknown principal types on principal read check', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const account = {
|
||||
constructor: { modelName: 'account' },
|
||||
authorized_actions: ['read'],
|
||||
@@ -77,7 +77,7 @@ module('Unit | Abilities | Role', function (hooks) {
|
||||
});
|
||||
|
||||
test('can set grant scopes based on authorized_actions', function (assert) {
|
||||
const service = this.owner.lookup('service:can');
|
||||
const service = this.owner.lookup('service:abilities');
|
||||
const model = {
|
||||
authorized_actions: ['set-grant-scopes'],
|
||||
};
|
||||
|
||||
@@ -9,10 +9,10 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Abilities | Scope', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
});
|
||||
test('it exists', function (assert) {
|
||||
const ability = this.owner.lookup('ability:scope');
|
||||
@@ -23,9 +23,9 @@ module('Unit | Abilities | Scope', function (hooks) {
|
||||
const model = {
|
||||
authorized_actions: ['attach-storage-policy'],
|
||||
};
|
||||
assert.true(canService.can('attachStoragePolicy scope', model));
|
||||
assert.true(abilitiesService.can('attachStoragePolicy scope', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('attachStoragePolicy scope', model));
|
||||
assert.false(abilitiesService.can('attachStoragePolicy scope', model));
|
||||
});
|
||||
|
||||
test('it reflects when a given scope may remove a policy in org scope', function (assert) {
|
||||
@@ -33,8 +33,8 @@ module('Unit | Abilities | Scope', function (hooks) {
|
||||
authorized_actions: ['detach-storage-policy'],
|
||||
};
|
||||
|
||||
assert.true(canService.can('detachStoragePolicy scope', model));
|
||||
assert.true(abilitiesService.can('detachStoragePolicy scope', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('detachStoragePolicy scope', model));
|
||||
assert.false(abilitiesService.can('detachStoragePolicy scope', model));
|
||||
});
|
||||
});
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
module('Unit | Ability | session-recording', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
@@ -42,13 +42,13 @@ module('Unit | Ability | session-recording', function (hooks) {
|
||||
);
|
||||
|
||||
assert.true(
|
||||
canService.can(
|
||||
abilitiesService.can(
|
||||
'download session-recording',
|
||||
recordingWithAuthorizedAction,
|
||||
),
|
||||
);
|
||||
assert.false(
|
||||
canService.can(
|
||||
abilitiesService.can(
|
||||
'download session-recording',
|
||||
recordingWithoutAuthorizedAction,
|
||||
),
|
||||
@@ -70,10 +70,16 @@ module('Unit | Ability | session-recording', function (hooks) {
|
||||
state: STATE_SESSION_RECORDING_AVAILABLE,
|
||||
});
|
||||
assert.false(
|
||||
canService.can('delete session-recording', recordingNotinAvaialableState),
|
||||
abilitiesService.can(
|
||||
'delete session-recording',
|
||||
recordingNotinAvaialableState,
|
||||
),
|
||||
);
|
||||
assert.true(
|
||||
canService.can('delete session-recording', recordingInAvailableState),
|
||||
abilitiesService.can(
|
||||
'delete session-recording',
|
||||
recordingInAvailableState,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -83,7 +89,7 @@ module('Unit | Ability | session-recording', function (hooks) {
|
||||
});
|
||||
|
||||
assert.true(
|
||||
canService.can('reapplyStoragePolicy session-recording', recording),
|
||||
abilitiesService.can('reapplyStoragePolicy session-recording', recording),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -15,11 +15,11 @@ import {
|
||||
module('Unit | Ability | session', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_ACTIVE,
|
||||
});
|
||||
|
||||
assert.true(canService.can('read session', session));
|
||||
assert.true(abilitiesService.can('read session', session));
|
||||
});
|
||||
|
||||
test('can read a session that is pending', function (assert) {
|
||||
@@ -43,7 +43,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_PENDING,
|
||||
});
|
||||
|
||||
assert.true(canService.can('read session', session));
|
||||
assert.true(abilitiesService.can('read session', session));
|
||||
});
|
||||
|
||||
test('cannot read a session that is not authorized', function (assert) {
|
||||
@@ -64,10 +64,10 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_TERMINATED,
|
||||
});
|
||||
|
||||
assert.false(canService.can('read session', activeSession));
|
||||
assert.false(canService.can('read session', pendingSession));
|
||||
assert.false(canService.can('read session', cancelingSession));
|
||||
assert.false(canService.can('read session', terminatedSession));
|
||||
assert.false(abilitiesService.can('read session', activeSession));
|
||||
assert.false(abilitiesService.can('read session', pendingSession));
|
||||
assert.false(abilitiesService.can('read session', cancelingSession));
|
||||
assert.false(abilitiesService.can('read session', terminatedSession));
|
||||
});
|
||||
|
||||
test('cannot read a session that is canceling', function (assert) {
|
||||
@@ -76,7 +76,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_CANCELING,
|
||||
});
|
||||
|
||||
assert.false(canService.can('read session', session));
|
||||
assert.false(abilitiesService.can('read session', session));
|
||||
});
|
||||
|
||||
test('cannot read a session that is terminated', function (assert) {
|
||||
@@ -85,7 +85,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_TERMINATED,
|
||||
});
|
||||
|
||||
assert.false(canService.can('read session', session));
|
||||
assert.false(abilitiesService.can('read session', session));
|
||||
});
|
||||
|
||||
test('can read a session that has read:self', function (assert) {
|
||||
@@ -94,7 +94,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_ACTIVE,
|
||||
});
|
||||
|
||||
assert.true(canService.can('read session', session));
|
||||
assert.true(abilitiesService.can('read session', session));
|
||||
});
|
||||
|
||||
test('can cancel a session that is active', function (assert) {
|
||||
@@ -103,7 +103,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_ACTIVE,
|
||||
});
|
||||
|
||||
assert.true(canService.can('cancel session', session));
|
||||
assert.true(abilitiesService.can('cancel session', session));
|
||||
});
|
||||
|
||||
test('can cancel a session that has cancel:self', function (assert) {
|
||||
@@ -112,7 +112,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_ACTIVE,
|
||||
});
|
||||
|
||||
assert.true(canService.can('cancel session', session));
|
||||
assert.true(abilitiesService.can('cancel session', session));
|
||||
});
|
||||
|
||||
test('can cancel a session that is pending', function (assert) {
|
||||
@@ -121,7 +121,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_PENDING,
|
||||
});
|
||||
|
||||
assert.true(canService.can('cancel session', session));
|
||||
assert.true(abilitiesService.can('cancel session', session));
|
||||
});
|
||||
|
||||
test('cannot cancel a session that is canceling', function (assert) {
|
||||
@@ -130,7 +130,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_CANCELING,
|
||||
});
|
||||
|
||||
assert.false(canService.can('cancel session', session));
|
||||
assert.false(abilitiesService.can('cancel session', session));
|
||||
});
|
||||
|
||||
test('cannot cancel a session that is terminated', function (assert) {
|
||||
@@ -139,7 +139,7 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_TERMINATED,
|
||||
});
|
||||
|
||||
assert.false(canService.can('cancel session', session));
|
||||
assert.false(abilitiesService.can('cancel session', session));
|
||||
});
|
||||
|
||||
test('cannot cancel a session that is not authorized', function (assert) {
|
||||
@@ -160,9 +160,9 @@ module('Unit | Ability | session', function (hooks) {
|
||||
status: STATUS_SESSION_TERMINATED,
|
||||
});
|
||||
|
||||
assert.false(canService.can('cancel session', activeSession));
|
||||
assert.false(canService.can('cancel session', pendingSession));
|
||||
assert.false(canService.can('cancel session', cancelingSession));
|
||||
assert.false(canService.can('cancel session', terminatedSession));
|
||||
assert.false(abilitiesService.can('cancel session', activeSession));
|
||||
assert.false(abilitiesService.can('cancel session', pendingSession));
|
||||
assert.false(abilitiesService.can('cancel session', cancelingSession));
|
||||
assert.false(abilitiesService.can('cancel session', terminatedSession));
|
||||
});
|
||||
});
|
||||
@@ -9,55 +9,59 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Abilities | Target', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
});
|
||||
|
||||
test('it reflects when a given target may connect based on authorized_actions', function (assert) {
|
||||
const model = {
|
||||
authorized_actions: ['authorize-session'],
|
||||
};
|
||||
assert.true(canService.can('connect target', model));
|
||||
assert.true(abilitiesService.can('connect target', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('connect target', model));
|
||||
assert.false(abilitiesService.can('connect target', model));
|
||||
});
|
||||
|
||||
test('it reflects when a given target may add host sources', function (assert) {
|
||||
const model = {
|
||||
authorized_actions: ['add-host-sources'],
|
||||
};
|
||||
assert.true(canService.can('addHostSources target', model));
|
||||
assert.true(abilitiesService.can('addHostSources target', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('addHostSources target', model));
|
||||
assert.false(abilitiesService.can('addHostSources target', model));
|
||||
});
|
||||
|
||||
test('it reflects when a given target may remove host sources', function (assert) {
|
||||
const model = {
|
||||
authorized_actions: ['remove-host-sources'],
|
||||
};
|
||||
assert.true(canService.can('removeHostSources target', model));
|
||||
assert.true(abilitiesService.can('removeHostSources target', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('removeHostSources target', model));
|
||||
assert.false(abilitiesService.can('removeHostSources target', model));
|
||||
});
|
||||
|
||||
test('it reflects when a given target may add brokered credential sources', function (assert) {
|
||||
const model = {
|
||||
authorized_actions: ['add-credential-sources'],
|
||||
};
|
||||
assert.true(canService.can('addBrokeredCredentialSources target', model));
|
||||
assert.true(
|
||||
abilitiesService.can('addBrokeredCredentialSources target', model),
|
||||
);
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('addBrokeredCredentialSources target', model));
|
||||
assert.false(
|
||||
abilitiesService.can('addBrokeredCredentialSources target', model),
|
||||
);
|
||||
});
|
||||
|
||||
test('it reflects when a given target may remove credential sources', function (assert) {
|
||||
const model = {
|
||||
authorized_actions: ['remove-credential-sources'],
|
||||
};
|
||||
assert.true(canService.can('removeCredentialSources target', model));
|
||||
assert.true(abilitiesService.can('removeCredentialSources target', model));
|
||||
model.authorized_actions = [];
|
||||
assert.false(canService.can('removeCredentialSources target', model));
|
||||
assert.false(abilitiesService.can('removeCredentialSources target', model));
|
||||
});
|
||||
|
||||
test('it reflects when a given ssh target may add injected application credential sources', function (assert) {
|
||||
@@ -74,16 +78,19 @@ module('Unit | Abilities | Target', function (hooks) {
|
||||
};
|
||||
|
||||
assert.true(
|
||||
canService.can('addInjectedApplicationCredentialSources target', model),
|
||||
abilitiesService.can(
|
||||
'addInjectedApplicationCredentialSources target',
|
||||
model,
|
||||
),
|
||||
);
|
||||
assert.false(
|
||||
canService.can(
|
||||
abilitiesService.can(
|
||||
'addInjectedApplicationCredentialSources target',
|
||||
modelWithoutAuthorizedActions,
|
||||
),
|
||||
);
|
||||
assert.false(
|
||||
canService.can(
|
||||
abilitiesService.can(
|
||||
'addInjectedApplicationCredentialSources target',
|
||||
modelWithoutSSHType,
|
||||
),
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
module('Unit | Abilities | User', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
const instances = {
|
||||
@@ -23,7 +23,7 @@ module('Unit | Abilities | User', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
instances.user = store.createRecord('user');
|
||||
instances.account = store.createRecord('account');
|
||||
@@ -31,28 +31,28 @@ module('Unit | Abilities | User', function (hooks) {
|
||||
|
||||
test('can add accounts to user when authorized and given a known account type', function (assert) {
|
||||
instances.user.authorized_actions = ['add-accounts'];
|
||||
assert.true(canService.can('addAccounts user', instances.user));
|
||||
assert.true(abilitiesService.can('addAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
@@ -60,28 +60,28 @@ module('Unit | Abilities | User', function (hooks) {
|
||||
|
||||
test('cannot add accounts to user when unauthorized', function (assert) {
|
||||
instances.user.authorized_actions = [];
|
||||
assert.false(canService.can('addAccounts user', instances.user));
|
||||
assert.false(abilitiesService.can('addAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
@@ -89,28 +89,28 @@ module('Unit | Abilities | User', function (hooks) {
|
||||
|
||||
test('can remove accounts from user when authorized and given a known account type', function (assert) {
|
||||
instances.user.authorized_actions = ['remove-accounts'];
|
||||
assert.true(canService.can('removeAccounts user', instances.user));
|
||||
assert.true(abilitiesService.can('removeAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.true(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
@@ -118,28 +118,28 @@ module('Unit | Abilities | User', function (hooks) {
|
||||
|
||||
test('cannot remove accounts from user when unauthorized', function (assert) {
|
||||
instances.user.authorized_actions = [];
|
||||
assert.false(canService.can('removeAccounts user', instances.user));
|
||||
assert.false(abilitiesService.can('removeAccounts user', instances.user));
|
||||
instances.account.type = TYPE_AUTH_METHOD_OIDC;
|
||||
assert.false(
|
||||
canService.can('addAccount user', instances.user, {
|
||||
abilitiesService.can('addAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_PASSWORD;
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = TYPE_AUTH_METHOD_LDAP;
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
instances.account.type = 'no-such-type';
|
||||
assert.false(
|
||||
canService.can('removeAccount user', instances.user, {
|
||||
abilitiesService.can('removeAccount user', instances.user, {
|
||||
account: instances.account,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Abilities | Worker', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let abilitiesService;
|
||||
let store;
|
||||
|
||||
const instances = {
|
||||
@@ -17,7 +17,7 @@ module('Unit | Abilities | Worker', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
abilitiesService = this.owner.lookup('service:abilities');
|
||||
store = this.owner.lookup('service:store');
|
||||
instances.worker = store.createRecord('worker');
|
||||
});
|
||||
@@ -27,7 +27,7 @@ module('Unit | Abilities | Worker', function (hooks) {
|
||||
authorized_collection_actions: { workers: ['create:worker-led'] },
|
||||
};
|
||||
assert.true(
|
||||
canService.can('createWorkerLed worker', model, {
|
||||
abilitiesService.can('createWorkerLed worker', model, {
|
||||
collection: 'workers',
|
||||
}),
|
||||
);
|
||||
@@ -38,7 +38,7 @@ module('Unit | Abilities | Worker', function (hooks) {
|
||||
authorized_collection_actions: { workers: [] },
|
||||
};
|
||||
assert.true(
|
||||
canService.cannot('createWorkerLed worker', model, {
|
||||
abilitiesService.cannot('createWorkerLed worker', model, {
|
||||
collection: 'workers',
|
||||
}),
|
||||
);
|
||||
@@ -46,11 +46,13 @@ module('Unit | Abilities | Worker', function (hooks) {
|
||||
|
||||
test('can set worker tags', function (assert) {
|
||||
instances.worker.authorized_actions = ['set-worker-tags'];
|
||||
assert.true(canService.can('setWorkerTags worker', instances.worker));
|
||||
assert.true(abilitiesService.can('setWorkerTags worker', instances.worker));
|
||||
});
|
||||
|
||||
test('cannot set worker tags', function (assert) {
|
||||
instances.worker.authorized_actions = [];
|
||||
assert.true(canService.cannot('setWorkerTags worker', instances.worker));
|
||||
assert.true(
|
||||
abilitiesService.cannot('setWorkerTags worker', instances.worker),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user