Merge pull request #197 from hashicorp/ICU-617-add-username-to-account-list

Display password account's loginname in accounts list
This commit is contained in:
Randall Morey authored and GitHub committed 2020-09-21 13:40:06 -04:00
commit acdb108b2f
4 files changed
+46 -3

No files matched your search

+24 -1
View File
@@ -1,13 +1,32 @@
import GeneratedAccountModel from '../generated/models/account';
import { fragment } from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
export default class AccountModel extends GeneratedAccountModel {
// =attributes
/**
* Attributes of this resource, if any, represented as a JSON fragment.
* @type {FragmentAccountAttributesModel}
*/
@fragment('fragment-account-attributes', { defaultValue: {} }) attributes;
/**
* Convenience for getting username in account.
* @type {string}
*/
@computed('type', 'attributes.{login_name}')
get username() {
let username = '';
switch (this.type) {
case 'password':
username = this.attributes.login_name;
break;
}
return username;
}
// =methods
/**
@@ -41,7 +60,11 @@ export default class AccountModel extends GeneratedAccountModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
changePassword(currentPassword, newPassword, options = { adapterOptions: {} }) {
changePassword(
currentPassword,
newPassword,
options = { adapterOptions: {} }
) {
const defaultAdapterOptions = {
method: 'change-password',
currentPassword,
+5 -2
View File
@@ -22,8 +22,11 @@ export default class AccountSerializer extends ApplicationSerializer {
}
if (snapshot?.adapterOptions?.method === 'change-password') {
const { currentPassword, newPassword } = snapshot?.adapterOptions;
serialized =
this.serializeForChangePassword(snapshot, currentPassword, newPassword);
serialized = this.serializeForChangePassword(
snapshot,
currentPassword,
newPassword
);
}
return serialized;
}
@@ -9,4 +9,17 @@ module('Unit | Model | account', function (hooks) {
let model = store.createRecord('account', {});
assert.ok(model);
});
test('it has an username attribute for password account', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
let model = store.createRecord('account', {
name: 'name',
type: 'password',
});
assert.notOk(model.username);
model.attributes.login_name = 'username';
assert.equal(model.username, 'username');
});
});
@@ -4,6 +4,7 @@
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.identification'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
</header.row>
</table.header>
@@ -19,6 +20,9 @@
</LinkTo>
<p>{{account.description}}</p>
</row.headerCell>
<row.cell>
{{account.username}}
</row.cell>
<row.cell>
<code>{{account.id}}</code>
</row.cell>