Merge pull request #786 from hashicorp/feature-group-member-capabilities

feat: 🎸 implement group members abilities
This commit is contained in:
Randall Morey authored and GitHub committed 2021-10-05 12:37:04 -04:00
commit 3386c3bba2
10 files changed
+106 -20

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import ModelAbility from './model';
/**
* Provides abilities for groups.
*/
export default class GroupAbility extends ModelAbility {
// =permissions
/**
* @type {boolean}
*/
get canAddMembers() {
return this.hasAuthorizedAction('add-members');
}
/**
* @type {boolean}
*/
get canRemoveMembers() {
return this.hasAuthorizedAction('remove-members');
}
}
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/abilities/group';
+2
View File
@@ -9,6 +9,8 @@ export default factory.extend({
'read',
'update',
'delete',
'add-members',
'remove-members',
],
id: (i) => `group-${i}`,
@@ -0,0 +1,28 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
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) {
assert.expect(2);
const service = this.owner.lookup('service:can');
const model = {
authorized_actions: ['add-members'],
};
assert.ok(service.can('addMembers group', model));
model.authorized_actions = [];
assert.notOk(service.can('addMembers group', model));
});
test('it reflects when a given group resource may remove members based on authorized_actions', function (assert) {
assert.expect(2);
const service = this.owner.lookup('service:can');
const model = {
authorized_actions: ['remove-members'],
};
assert.ok(service.can('removeMembers group', model));
model.authorized_actions = [];
assert.notOk(service.can('removeMembers group', model));
});
});
+1 -1
View File
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Abilities | Account', function (hooks) {
module('Unit | Abilities | Role', function (hooks) {
setupTest(hooks);
test('it reflects when a given role may set grants based on authorized_actions', function (assert) {
+1 -1
View File
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Abilities | Account', function (hooks) {
module('Unit | Abilities | User', function (hooks) {
setupTest(hooks);
test('it reflects when a given user resource may add accounts based on authorized_actions', function (assert) {
@@ -3,9 +3,11 @@
@dropdownRight={{true}}
as |dropdown|
>
<dropdown.link @route='scopes.scope.groups.group.add-members'>
{{t 'resources.group.actions.add-members'}}
</dropdown.link>
{{#if (can 'addMembers group' @model)}}
<dropdown.link @route='scopes.scope.groups.group.add-members'>
{{t 'resources.group.actions.add-members'}}
</dropdown.link>
{{/if}}
{{#if (can 'delete model' @model)}}
<dropdown.separator />
<dropdown.button
@@ -26,21 +26,26 @@
</Copyable>
</row.cell>
<row.cell>
<Rose::Dropdown
@icon='flight-icons/svg/more-horizontal-16'
@iconOnly={{true}}
@showCaret={{false}}
@dropdownRight={{true}}
@text='{{t 'actions.manage'}}'
as |dropdown|
>
<dropdown.button
@style='danger'
{{on 'click' (route-action 'removeMember' @model.group member)}}
{{#if (can 'removeMembers group' @model.group)}}
<Rose::Dropdown
@icon='flight-icons/svg/more-horizontal-16'
@iconOnly={{true}}
@showCaret={{false}}
@dropdownRight={{true}}
@text='{{t 'actions.manage'}}'
as |dropdown|
>
{{t 'actions.remove'}}
</dropdown.button>
</Rose::Dropdown>
<dropdown.button
@style='danger'
{{on
'click'
(route-action 'removeMember' @model.group member)
}}
>
{{t 'actions.remove'}}
</dropdown.button>
</Rose::Dropdown>
{{/if}}
</row.cell>
</body.row>
{{/each}}
@@ -68,6 +68,16 @@ module('Acceptance | groups | members', function (hooks) {
assert.equal(findAll('tbody tr').length, membersCount - 1);
});
test('cannot remove a member without proper authorization', async function (assert) {
assert.expect(1);
const authorized_actions = instances.group.authorized_actions.filter(
(item) => item !== 'remove-members'
);
instances.group.update({ authorized_actions });
await visit(urls.members);
assert.notOk(find('tbody tr .rose-dropdown-button-danger'));
});
test('shows error message on member remove', async function (assert) {
assert.expect(2);
this.server.post('/groups/:idMethod', () => {
@@ -95,6 +105,22 @@ module('Acceptance | groups | members', function (hooks) {
assert.equal(currentURL(), urls.addMembers);
});
test('can navigate to add members with proper authorization', async function (assert) {
assert.expect(1);
await visit(urls.group);
assert.ok(find(`[href="${urls.addMembers}"]`));
});
test('cannot navigate to add members without proper authorization', async function (assert) {
assert.expect(1);
const authorized_actions = instances.group.authorized_actions.filter(
(item) => item !== 'add-members'
);
instances.group.update({ authorized_actions });
await visit(urls.group);
assert.notOk(find(`[href="${urls.addMembers}"]`));
});
test('select and save members to add', async function (assert) {
assert.expect(3);
instances.group.update({ memberIds: [] });
@@ -107,7 +107,7 @@ module('Acceptance | users | accounts', function (hooks) {
assert.equal(currentURL(), urls.addAccounts);
});
test('can navigate to add accounts without proper authorization', async function (assert) {
test('can navigate to add accounts with proper authorization', async function (assert) {
assert.expect(1);
await visit(urls.accounts);
assert.ok(find(`[href="${urls.addAccounts}"]`));