feat: 🎸 implement add- and remove-principals abilities

This commit is contained in:
Randall Morey committed 2021-09-30 16:04:02 -04:00
1 parent 3022ca5a53
commit 8da8fddf29
6 files changed
+82 -17

No files matched your search

@@ -3,9 +3,11 @@
@dropdownRight={{true}}
as |dropdown|
>
<dropdown.link @route='scopes.scope.roles.role.add-principals'>
{{t 'resources.role.principal.actions.add-principals'}}
</dropdown.link>
{{#if (can 'addPrincipals role' @model)}}
<dropdown.link @route='scopes.scope.roles.role.add-principals'>
{{t 'resources.role.principal.actions.add-principals'}}
</dropdown.link>
{{/if}}
{{#if (can 'delete model' @model)}}
<dropdown.separator />
<dropdown.button
@@ -30,21 +30,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 'removePrincipal' principal.model)}}
{{#if (can 'removePrincipals role' @model.role)}}
<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 'removePrincipal' principal.model)
}}
>
{{t 'actions.remove'}}
</dropdown.button>
</Rose::Dropdown>
{{/if}}
</row.cell>
</body.row>
{{/each}}
@@ -69,6 +69,16 @@ module('Acceptance | roles | principals', function (hooks) {
assert.equal(findAll('tbody tr').length, principalsCount - 1);
});
test('principal cannot be removed from a role without proper authorization', async function (assert) {
assert.expect(1);
const authorized_actions = instances.role.authorized_actions.filter(
(item) => item !== 'remove-principals'
);
instances.role.update({ authorized_actions });
await visit(urls.rolePrincipals);
assert.notOk(find('tbody tr .rose-dropdown-button-danger'));
});
test('shows error message on principal remove', async function (assert) {
assert.expect(2);
this.server.post('/roles/:idMethod', () => {
@@ -89,6 +99,16 @@ module('Acceptance | roles | principals', function (hooks) {
assert.ok(find('[role="alert"]'));
});
test('cannot navigate to add principals without proper authorization', async function (assert) {
assert.expect(1);
const authorized_actions = instances.role.authorized_actions.filter(
(item) => item !== 'add-principals'
);
instances.role.update({ authorized_actions });
await visit(urls.rolePrincipals);
assert.notOk(find('.rose-layout-page-actions a'));
});
test('select and save principals to add', async function (assert) {
assert.expect(3);
instances.role.update({ userIds: [], groupIds: [] });