feat: Remove a principal from a role

This commit is contained in:
Susmitha Girumala committed 2020-08-31 12:47:34 -04:00
1 parent 4ba113aad3
commit d3e7a263eb
5 files changed
+94 -25

No files matched your search

@@ -1,8 +1,15 @@
import Route from '@ember/routing/route';
import { all } from 'rsvp';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
@@ -34,4 +41,23 @@ export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
return all(users.concat(groups));
}
// =actions
/**
* Remove a principal from the current role and redirect to principals index.
* @param {UserModel, GroupModel} principal
*/
@action
async removePrincipal(principal) {
try {
const role = this.modelFor('scopes.scope.roles.role');
await role.removePrincipal(principal.id);
this.refresh();
this.notify.success(this.intl.t('notify.delete-success'));
this.transitionTo('scopes.scope.roles.role.principals');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -25,8 +25,14 @@
<code>{{hostSet.model.id}}</code>
</row.cell>
<row.cell>
<Rose::Dropdown @icon="more-horizontal" @iconOnly={{true}} @dropdownRight={{true}} @text="{{t "actions.manage"}}" as |dropdown|>
<Rose::Dropdown
@icon="more-horizontal"
@iconOnly={{true}}
@dropdownRight={{true}}
@text="{{t "actions.manage"}}" as |dropdown|
>
<dropdown.button
name="{{t "actions.remove"}}"
@style="danger"
{{on "click" (route-action "removeHostSet" @model hostSet.model)}}
>
@@ -1,26 +1,57 @@
{{title (t 'titles.principals')}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.type'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model as |principal|}}
<body.row as |row|>
<row.headerCell>
{{principal.model.displayName}}
</row.headerCell>
<row.cell>
{{t (concat 'resources.' principal.type)}}
</row.cell>
<row.cell>
<code>{{principal.model.id}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{#if @model}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.type'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
<row.headerCell>{{t "form.label.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model as |principal|}}
<body.row as |row|>
<row.headerCell>
{{principal.model.displayName}}
</row.headerCell>
<row.cell>
{{t (concat 'resources.' principal.type)}}
</row.cell>
<row.cell>
<code>{{principal.model.id}}</code>
</row.cell>
<row.cell>
<Rose::Dropdown
@icon="more-horizontal"
@iconOnly={{true}}
@dropdownRight={{true}}
@text="{{t "actions.manage"}}" as |dropdown|
>
<dropdown.button
name="{{t "actions.remove"}}"
@style="danger"
{{on "click" (route-action "removePrincipal" principal.model)}}
>
{{t "actions.remove"}}
</dropdown.button>
</Rose::Dropdown>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "titles.role-principals-welcome"}} as |message|>
<message.description>
{{t "descriptions.role-principals-welcome"}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}