Merge pull request #146 from hashicorp/feature-add-principals
Roles: Add Principals
This commit is contained in:
20 files changed
+347
-23
No files matched your search
@@ -0,0 +1,56 @@
|
||||
{{#if this.hasAvailablePrincipals}}
|
||||
<Rose::Form
|
||||
class="full-width"
|
||||
@onSubmit={{fn this.submit @submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
as |form|
|
||||
>
|
||||
|
||||
<form.actions
|
||||
@submitText={{t "actions.add-principals"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
|
||||
<Rose::Table as |table|>
|
||||
<table.header as |header|>
|
||||
<header.row as |row|>
|
||||
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
|
||||
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
|
||||
<row.headerCell>{{t 'form.label.type'}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
{{#each this.filteredPrincipals as |principal|}}
|
||||
<body.row as |row|>
|
||||
<row.cell>
|
||||
<form.checkbox
|
||||
@label={{principal.id}}
|
||||
@description={{principal.description}}
|
||||
onChange={{fn this.togglePrincipal principal}} />
|
||||
</row.cell>
|
||||
<row.cell>{{principal.name}}</row.cell>
|
||||
<row.cell>
|
||||
<Rose::Badge>{{t (concat 'resources.' principal.constructor.modelName)}}</Rose::Badge>
|
||||
</row.cell>
|
||||
</body.row>
|
||||
{{/each}}
|
||||
</table.body>
|
||||
</Rose::Table>
|
||||
|
||||
</Rose::Form>
|
||||
{{/if}}
|
||||
|
||||
{{#unless this.hasAvailablePrincipals}}
|
||||
<Rose::Layout::Centered>
|
||||
<Rose::Message @title={{t "titles.no-principals-available"}} as |message|>
|
||||
<message.description>
|
||||
{{t "descriptions.no-principals-available"}}
|
||||
</message.description>
|
||||
<message.link @route="scopes.scope.roles.role.principals">
|
||||
<Rose::Icon @name="chevron-left" />
|
||||
{{t "actions.back"}}
|
||||
</message.link>
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
{{/unless}}
|
||||
@@ -0,0 +1,57 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { computed, action } from '@ember/object';
|
||||
import { A } from '@ember/array';
|
||||
|
||||
export default class FormRoleAddPrincipalsIndexComponent extends Component {
|
||||
|
||||
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* Array of selected principal IDs.
|
||||
* @type {EmberArray}
|
||||
*/
|
||||
selectedPrincipalIDs = A();
|
||||
|
||||
/**
|
||||
* Checks for unassigned principals.
|
||||
* True if there are users or groups not yet added to this role.
|
||||
* @param {[UserModel, GroupModel]} filteredPrincipals
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('filteredPrincipals')
|
||||
get hasAvailablePrincipals() {
|
||||
return this.filteredPrincipals.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Principals not currently assigned to a role.
|
||||
* @type {[UserModel, GroupModel]}
|
||||
*/
|
||||
@computed('args.{model,users,groups}')
|
||||
get filteredPrincipals() {
|
||||
// Retrieve principal IDs assigned to current role
|
||||
const currentPrincipalIDs = this.args.model.principals.map(principal => principal.principal_id);
|
||||
// Retrieve principal IDs not assigned to current role
|
||||
const unassignedUsers = this.args.users.filter(({ id }) => !currentPrincipalIDs.includes(id));
|
||||
const unassignedGroups = this.args.groups.filter(({ id }) => !currentPrincipalIDs.includes(id));
|
||||
return [...unassignedUsers, ...unassignedGroups];
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@action
|
||||
togglePrincipal(principal) {
|
||||
if (!this.selectedPrincipalIDs.includes(principal.id)) {
|
||||
this.selectedPrincipalIDs.addObject(principal.id);
|
||||
} else {
|
||||
this.selectedPrincipalIDs.removeObject(principal.id);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
submit(fn) {
|
||||
fn(this.selectedPrincipalIDs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeRolesRoleAddPrincipalsController extends Controller {
|
||||
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Translated roles breadcrumb
|
||||
* @type {string}
|
||||
*/
|
||||
get breadCrumb() {
|
||||
return this.intl.t('actions.add-principals');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,6 +65,7 @@ Router.map(function () {
|
||||
this.route('role', { path: ':role_id' }, function () {
|
||||
this.route('grants');
|
||||
this.route('principals');
|
||||
this.route('add-principals');
|
||||
});
|
||||
this.route('new');
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute ext
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Emtpy out any previously loaded host catalogs and host sets.
|
||||
* Empty out any previously loaded host catalogs and host sets.
|
||||
*/
|
||||
beforeModel() {
|
||||
this.store.unloadAll('host-catalog');
|
||||
|
||||
@@ -9,10 +9,34 @@ export default class ScopesScopeRolesRoleRoute extends Route {
|
||||
* @param {string} params.role_id
|
||||
* @return {RoleModel}
|
||||
*/
|
||||
async model({ role_id }) {
|
||||
model({ role_id }) {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope');
|
||||
return this.store.findRecord('role', role_id, {
|
||||
adapterOptions: { scopeID },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the role specific templates for header, navigation,
|
||||
* and actions page sections.
|
||||
* @override
|
||||
*/
|
||||
renderTemplate() {
|
||||
super.renderTemplate(...arguments);
|
||||
|
||||
this.render('scopes/scope/roles/role/-header', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'header',
|
||||
});
|
||||
|
||||
this.render('scopes/scope/roles/role/-navigation', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'navigation',
|
||||
});
|
||||
|
||||
this.render('scopes/scope/roles/role/-actions', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'actions',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { hash } from 'rsvp';
|
||||
|
||||
export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
|
||||
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Empty out any previously loaded users and groups.
|
||||
* (collectively, principals).
|
||||
*/
|
||||
beforeModel() {
|
||||
this.store.unloadAll('user');
|
||||
this.store.unloadAll('group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current role, all users, and all groups
|
||||
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
|
||||
*/
|
||||
model() {
|
||||
const role = this.modelFor('scopes.scope.roles.role');
|
||||
const { scopeID } = role;
|
||||
const options = { adapterOptions: { scopeID } };
|
||||
return hash({
|
||||
role,
|
||||
users: this.store.findAll('user', options),
|
||||
groups: this.store.findAll('group', options)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the add-principals-specific header template.
|
||||
* Empties the actions and navigation outlets and renders a custom empty header.
|
||||
* @override
|
||||
*/
|
||||
renderTemplate() {
|
||||
super.renderTemplate(...arguments);
|
||||
|
||||
this.render('scopes/scope/roles/role/add-principals/-header', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'header',
|
||||
});
|
||||
|
||||
this.render('-empty', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'navigation',
|
||||
});
|
||||
|
||||
this.render('-empty', {
|
||||
into: 'scopes/scope/roles/role',
|
||||
outlet: 'actions',
|
||||
});
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Save principal IDs to current role via the API.
|
||||
* @param {RoleModel} role
|
||||
* @param {[string]} principalIDs
|
||||
*/
|
||||
@action
|
||||
async addPrincipals(role, principalIDs) {
|
||||
try {
|
||||
await role.addPrincipals(principalIDs);
|
||||
this.replaceWith('scopes.scope.roles.role.principals');
|
||||
this.notify.success(this.intl.t('notify.save-success'));
|
||||
} catch (error) {
|
||||
// TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to role principals as if nothing ever happened.
|
||||
*/
|
||||
@action
|
||||
cancel() {
|
||||
this.replaceWith('scopes.scope.roles.role.principals');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,10 @@
|
||||
<message.description>
|
||||
{{t "descriptions.no-host-sets-for-target"}}
|
||||
</message.description>
|
||||
<message.link @route="scopes.scope.projects.project.targets.target.host-sets">
|
||||
<Rose::Icon @name="chevron-left" />
|
||||
{{t "actions.back"}}
|
||||
</message.link>
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
{{/unless}}
|
||||
@@ -7,33 +7,15 @@
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>{{t "resources.role"}}</h2>
|
||||
{{outlet "header"}}
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
|
||||
<dropdown.button
|
||||
@style="danger"
|
||||
@disabled={{@model.canSave}}
|
||||
{{on "click" (route-action "delete" @model)}}
|
||||
>
|
||||
{{t 'actions.delete-role'}}
|
||||
</dropdown.button>
|
||||
</Rose::Dropdown>
|
||||
{{outlet "actions"}}
|
||||
</page.actions>
|
||||
|
||||
<page.navigation>
|
||||
<Rose::Nav::Tabs as |nav|>
|
||||
<nav.link @route='scopes.scope.roles.role.index'>
|
||||
{{t 'titles.settings'}}
|
||||
</nav.link>
|
||||
<nav.link @route='scopes.scope.roles.role.principals'>
|
||||
{{t 'titles.principals'}}
|
||||
</nav.link>
|
||||
<nav.link @route='scopes.scope.roles.role.grants'>
|
||||
{{t 'titles.grants'}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Tabs>
|
||||
{{outlet "navigation"}}
|
||||
</page.navigation>
|
||||
|
||||
<page.body>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
|
||||
<dropdown.link @route="scopes.scope.roles.role.add-principals">
|
||||
{{t 'actions.add-principals'}}
|
||||
</dropdown.link>
|
||||
<dropdown.button
|
||||
@style="danger"
|
||||
@disabled={{@model.canSave}}
|
||||
{{on "click" (route-action "delete" @model)}}
|
||||
>
|
||||
{{t 'actions.delete-role'}}
|
||||
</dropdown.button>
|
||||
</Rose::Dropdown>
|
||||
@@ -0,0 +1 @@
|
||||
<h2>{{t "resources.role"}}</h2>
|
||||
@@ -0,0 +1,11 @@
|
||||
<Rose::Nav::Tabs as |nav|>
|
||||
<nav.link @route='scopes.scope.roles.role.index'>
|
||||
{{t 'titles.settings'}}
|
||||
</nav.link>
|
||||
<nav.link @route='scopes.scope.roles.role.principals'>
|
||||
{{t 'titles.principals'}}
|
||||
</nav.link>
|
||||
<nav.link @route='scopes.scope.roles.role.grants'>
|
||||
{{t 'titles.grants'}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Tabs>
|
||||
@@ -0,0 +1,9 @@
|
||||
{{title (t "actions.add-principals")}}
|
||||
|
||||
<Form::Role::AddPrincipals
|
||||
@model={{@model.role}}
|
||||
@users={{@model.users}}
|
||||
@groups={{@model.groups}}
|
||||
@submit={{route-action "addPrincipals" @model.role}}
|
||||
@cancel={{route-action "cancel"}}
|
||||
/>
|
||||
@@ -0,0 +1 @@
|
||||
<h2>{{t "actions.add-principals"}}</h2>
|
||||
@@ -12,5 +12,6 @@ export default Factory.extend({
|
||||
created_time: () => date.recent(),
|
||||
updated_time: () => date.recent(),
|
||||
disabled: () => random.boolean(),
|
||||
version: () => random.number(),
|
||||
|
||||
});
|
||||
@@ -237,4 +237,20 @@ module('Acceptance | roles', function (hooks) {
|
||||
test('new grants can be added and saved or canceled', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('viewing role principals', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('can delete a principal', async function(assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('select and save principals to add', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
|
||||
test('select and cancel principals to add', async function (assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
// import { render } from '@ember/test-helpers';
|
||||
// import { hbs } from 'ember-cli-htmlbars';
|
||||
|
||||
module('Integration | Component | form/role/add-principals', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
assert.expect(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | scopes/scope/roles/role/add-principals', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/roles/role/add-principals');
|
||||
assert.ok(controller);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/roles/role/add-principals', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/roles/role/add-principals');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ actions:
|
||||
save: Save
|
||||
manage: Manage
|
||||
help: Need help?
|
||||
back: Back
|
||||
authenticate: Authenticate
|
||||
deauthenticate: Deauthenticate
|
||||
choose-org: Choose Scope
|
||||
@@ -23,6 +24,7 @@ actions:
|
||||
add-host-set: Create Host Set
|
||||
add-host: Create Host
|
||||
add-host-sets: Add Host Sets
|
||||
add-principals: Add Principals
|
||||
add-members: Add Members
|
||||
auth:
|
||||
titles:
|
||||
@@ -94,6 +96,7 @@ titles:
|
||||
no-host-set-hosts: No Hosts Available
|
||||
no-host-sets-for-target: No Host Sets Available
|
||||
role-principals-welcome: No Principals Associated
|
||||
no-principals-available: No Principals Available
|
||||
members: Members
|
||||
group-members-welcome: Welcome to Members
|
||||
no-available-users: No Users Available
|
||||
@@ -113,6 +116,7 @@ descriptions:
|
||||
no-host-set-hosts: Before associating hosts with this host set, create hosts within the host catalog.
|
||||
no-host-sets-for-target: No host sets are available to add to this target.
|
||||
role-principals-welcome: No principals are available in this role.
|
||||
no-principals-available: Principals are not available for assignment.
|
||||
group-members-welcome: Users belonging to this group appear here.
|
||||
no-available-users: No users are available to add to this group.
|
||||
states:
|
||||
|
||||
Reference in new issue
Block a user