Merge pull request #244 from hashicorp/feature-user-accounts-ui

Feature user accounts ui
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2020-09-30 13:04:07 -04:00
commit 2efaeea779
30 files changed
+680 -59

No files matched your search

@@ -55,7 +55,6 @@
@value={{@model.attributes.login_name}}
@label={{t "form.login_name.label"}}
@error={{@model.errors.login_name}}
@helperText={{t "form.login_name.help"}}
readonly={{false}}
as |field|>
{{#if @model.errors.login_name}}
@@ -74,7 +73,6 @@
@value={{this.password}}
@label={{t "form.password.label"}}
@error={{@model.errors.password}}
@helperText={{t "form.password.help"}}
readonly={{false}}
autocomplete="new-password"
as |field|>
@@ -18,7 +18,7 @@
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
<row.headerCell>{{t 'resources.host-catalog.title_plural'}}</row.headerCell>
<row.headerCell>{{t 'resources.host-catalog.title'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
@@ -57,4 +57,4 @@
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
{{/unless}}
@@ -0,0 +1,56 @@
{{#if this.hasAvailableAccounts}}
<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 "resources.user.actions.add-accounts"}}
@cancelText={{t "actions.cancel"}} />
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t 'form.username.label'}}</row.headerCell>
<row.headerCell>{{t 'resources.auth-method.title'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each this.filteredAccounts as |account|}}
<body.row as |row|>
<row.cell>
<form.checkbox
@label={{account.id}}
@description={{account.description}}
onChange={{fn this.toggleAccount account}} />
</row.cell>
<row.cell>{{account.username}}</row.cell>
<row.cell>
<code>{{account.auth_method_id}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
</Rose::Form>
{{/if}}
{{#unless this.hasAvailableAccounts}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "resources.user.messages.no-accounts.title"}} as |message|>
<message.description>
{{t "resources.user.messages.no-accounts.description"}}
</message.description>
<message.link @route="scopes.scope.users.user.accounts">
<Rose::Icon @name="chevron-left" />
{{t "actions.back"}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -0,0 +1,53 @@
import Component from '@glimmer/component';
import { computed, action } from '@ember/object';
import { A } from '@ember/array';
export default class FormUserAddAccountsComponent extends Component {
// =properties
/**
* Array of selected account IDs.
* @type {EmberArray}
*/
selectedAccountIDs = A();
/**
* Checks for unassigned accounts.
* @param {[AccountModel]} filteredAccounts
* @type {boolean}
*/
@computed('filteredAccounts')
get hasAvailableAccounts() {
return this.filteredAccounts.length > 0;
}
/**
* Accounts not already added to the user.
* @type {[AccountModel]}
*/
@computed('args.{accounts.[],model.account_ids.[]}')
get filteredAccounts() {
// Get IDs for accounts already added to the current user
const alreadyAddedAccountIDs = this.args.model.account_ids;
const notAddedAccounts = this.args.accounts.filter(
({ id }) => !alreadyAddedAccountIDs.includes(id)
);
return notAddedAccounts;
}
// =actions
@action
toggleAccount(account) {
if (!this.selectedAccountIDs.includes(account.id)) {
this.selectedAccountIDs.addObject(account.id);
} else {
this.selectedAccountIDs.removeObject(account.id);
}
}
@action
submit(fn) {
fn(this.selectedAccountIDs);
}
}
@@ -0,0 +1,17 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeUsersUserAddAccountsController extends Controller {
// =services
@service intl;
// =attributes
/**
* @type {string}
*/
get breadCrumb() {
return this.intl.t('resources.user.messages.add-accounts.title');
}
}
+4 -1
View File
@@ -58,7 +58,10 @@ Router.map(function () {
});
this.route('users', function () {
this.route('user', { path: ':user_id' }, function () {});
this.route('user', { path: ':user_id' }, function () {
this.route('accounts');
this.route('add-accounts');
});
this.route('new');
});
@@ -12,4 +12,27 @@ export default class ScopesScopeUsersUserRoute extends Route {
async model({ user_id }) {
return this.store.findRecord('user', user_id);
}
/**
* Renders the route-set specific page sections
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/users/user/-header', {
into: 'scopes/scope/users/user',
outlet: 'header',
});
this.render('scopes/scope/users/user/-actions', {
into: 'scopes/scope/users/user',
outlet: 'actions',
});
this.render('scopes/scope/users/user/-navigation', {
into: 'scopes/scope/users/user',
outlet: 'navigation',
});
}
}
@@ -0,0 +1,51 @@
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { hash, all } from 'rsvp';
import loading from 'ember-loading/decorator';
export default class ScopesScopeUsersUserAccountsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Returns users associated with this user.
* @return {Promise{user: UserModel, accounts: Promise{[AccountModel]}}}
*/
model() {
const { id: scopeID } = this.modelFor('scopes.scope');
const user = this.modelFor('scopes.scope.users.user');
return hash({
user,
accounts: all(
user.account_ids.map((id) =>
this.store.findRecord('account', id, { adapterOptions: { scopeID } })
)
),
});
}
// =actions
/**
* Remove a account from the current role and redirect to accounts index.
* @param {UserModel} user
* @param {AccountModel} account
*/
@action
@loading
async removeAccount(user, account) {
try {
await user.removeAccount(account.id);
await this.refresh();
this.notify.success(this.intl.t('notifications.remove-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -0,0 +1,90 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { all } from 'rsvp';
import loading from 'ember-loading/decorator';
export default class ScopesScopeUsersUserAddAccountsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Emtpy out any previously loaded acconuts.
*/
beforeModel() {
this.store.unloadAll('account');
}
/**
* Returns the current target, all host catalogs, and all host sets.
* @return {{target: TargetModel, hostCatalogs: [HostCatalogModel], hostSets: [HostSetModel]}}
*/
async model() {
const user = this.modelFor('scopes.scope.users.user');
const { id: scope_id } = this.modelFor('scopes.scope');
const authMethods = await this.store.query('auth-method', { scope_id });
await all(
authMethods.map(({ id: auth_method_id }) =>
this.store.query('account', { auth_method_id })
)
);
const accounts = this.store.peekAll('account');
return { user, authMethods, accounts };
}
/**
* Renders the route-set specific page sections
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/users/user/add-accounts/-header', {
into: 'scopes/scope/users/user',
outlet: 'header',
});
this.render('-empty', {
into: 'scopes/scope/users/user',
outlet: 'actions',
});
this.render('-empty', {
into: 'scopes/scope/users/user',
outlet: 'navigation',
});
}
// =actions
/**
* Adds accounts to the user and saves, replaces with the accounts index
* route, and notifies the user of success or error.
* @param {UserModel} user
* @param {[string]} accountIDs
*/
@action
@loading
async addAccounts(user, accountIDs) {
try {
await user.addAccounts(accountIDs);
await this.replaceWith('scopes.scope.users.user.accounts');
this.notify.success(this.intl.t('notifications.add-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
/**
* Redirect to user accounts as if nothing ever happened.
*/
@action
cancel() {
this.replaceWith('scopes.scope.users.user.accounts');
}
}
@@ -4,7 +4,7 @@
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.login_name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.username.label'}}</row.headerCell>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
</header.row>
</table.header>
@@ -1,3 +1,25 @@
{{title @model.displayName}}
{{outlet}}
<Rose::Layout::Page as |page|>
<page.breadcrumbs>
<BreadCrumbs />
</page.breadcrumbs>
<page.header>
{{outlet "header"}}
</page.header>
<page.navigation>
{{outlet "navigation"}}
</page.navigation>
<page.actions>
{{outlet "actions"}}
</page.actions>
<page.body>
{{outlet}}
</page.body>
</Rose::Layout::Page>
@@ -0,0 +1,12 @@
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
<dropdown.link @route="scopes.scope.users.user.add-accounts">
{{t "resources.user.actions.add-accounts"}}
</dropdown.link>
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
>
{{t 'actions.delete-user'}}
</dropdown.button>
</Rose::Dropdown>
@@ -0,0 +1,3 @@
<h2>{{t "resources.user.title"}}</h2>
<p>{{t "resources.user.description"}}</p>
<p><code>{{@model.id}}</code></p>
@@ -0,0 +1,8 @@
<Rose::Nav::Tabs as |nav|>
<nav.link @route='scopes.scope.users.user.index'>
{{t 'titles.details'}}
</nav.link>
<nav.link @route='scopes.scope.users.user.accounts'>
{{t 'resources.user.messages.accounts.title'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,53 @@
{{title (t 'resources.user.messages.accounts.title')}}
{{#if @model.accounts}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.username.label'}}</row.headerCell>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model.accounts as |account|}}
<body.row as |row|>
<row.headerCell>
{{account.username}}
</row.headerCell>
<row.cell>
<code>{{account.id}}</code>
</row.cell>
<row.cell>
<Rose::Dropdown
@icon="more-horizontal"
@iconOnly={{true}}
@showCaret={{false}}
@dropdownRight={{true}}
@text="{{t "actions.manage"}}" as |dropdown|
>
<dropdown.button
@style="danger"
{{on "click" (route-action "removeAccount" @model.user account)}}
>
{{t "actions.remove"}}
</dropdown.button>
</Rose::Dropdown>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "resources.user.messages.accounts.title"}} as |message|>
<message.description>
{{t "resources.user.messages.accounts.description"}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
@@ -0,0 +1,25 @@
{{title (t 'resources.user.actions.add-accounts')}}
{{#if @model.accounts}}
<Form::User::AddAccounts
@model={{@model.user}}
@authMethods={{@model.authMethods}}
@accounts={{@model.accounts}}
@submit={{route-action "addAccounts" @model.user}}
@cancel={{route-action "cancel"}}
/>
{{/if}}
{{#unless @model.accounts}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "resources.user.messages.no-accounts.title"}} as |message|>
<message.description>
{{t "resources.user.messages.no-accounts.description"}}
</message.description>
<message.link @route="scopes.scope.users.user.accounts">
<Rose::Icon @name="chevron-left" />
{{t "actions.back"}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -0,0 +1,2 @@
<h2>{{t "resources.user.messages.add-accounts.title"}}</h2>
<p>{{t "resources.user.messages.add-accounts.description"}}</p>
@@ -1,41 +1,5 @@
<Rose::Layout::Page as |page|>
<page.breadcrumbs>
<BreadCrumbs />
</page.breadcrumbs>
<page.header>
<h2>{{t "resources.user.title"}}</h2>
<p>{{t "resources.user.description"}}</p>
<p><code>{{@model.id}}</code></p>
</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-user'}}
</dropdown.button>
</Rose::Dropdown>
</page.actions>
<page.navigation>
<Rose::Nav::Tabs as |nav|>
<nav.link @route='scopes.scope.users.user'>
{{t 'titles.details'}}
</nav.link>
</Rose::Nav::Tabs>
</page.navigation>
<page.body>
<Form::User
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
</page.body>
</Rose::Layout::Page>
<Form::User
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>