From 905ee8785898eef16075fa0232b1b9e59b52174c Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 17 Sep 2020 14:39:15 -0400 Subject: [PATCH] feat: Display password account's loginname in list --- addons/api/addon/models/account.js | 19 ++++++++++++++++++- addons/api/addon/serializers/account.js | 7 +++++-- addons/api/tests/unit/models/account-test.js | 12 ++++++++++++ .../auth-method/accounts/index.hbs | 4 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/addons/api/addon/models/account.js b/addons/api/addon/models/account.js index b28558732..4a6ee08c2 100644 --- a/addons/api/addon/models/account.js +++ b/addons/api/addon/models/account.js @@ -1,13 +1,26 @@ 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 login_name attribute. + * @type {string} + */ + @computed('attributes.login_name') + get username() { + return this.attributes.login_name; + } + // =methods /** @@ -41,7 +54,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, diff --git a/addons/api/addon/serializers/account.js b/addons/api/addon/serializers/account.js index 416bc488e..01618a081 100644 --- a/addons/api/addon/serializers/account.js +++ b/addons/api/addon/serializers/account.js @@ -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; } diff --git a/addons/api/tests/unit/models/account-test.js b/addons/api/tests/unit/models/account-test.js index 554a72be5..b8ce36b45 100644 --- a/addons/api/tests/unit/models/account-test.js +++ b/addons/api/tests/unit/models/account-test.js @@ -9,4 +9,16 @@ module('Unit | Model | account', function (hooks) { let model = store.createRecord('account', {}); assert.ok(model); }); + + test('it has an username attribute', function (assert) { + assert.expect(2); + const store = this.owner.lookup('service:store'); + let model = store.createRecord('account', { + name: 'name', + type: 'password', + }); + assert.equal(model.username, null); + model.attributes.login_name = 'username'; + assert.equal(model.username, 'username'); + }); }); diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs index 8586ac7c0..83ed4fa1a 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/index.hbs @@ -4,6 +4,7 @@ {{t 'form.label.name'}} + {{t 'form.label.identification'}} {{t 'form.label.id'}} @@ -19,6 +20,9 @@

{{account.description}}

+ + {{account.username}} + {{account.id}}