From dc68dfad85ee9bdc4ac18a93b43d52b385b53397 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 11:00:00 -0400 Subject: [PATCH 01/19] test: Add missing account serializer test Delete account password attribute in mirage to mimic API exactly --- addons/api/tests/unit/models/account-test.js | 11 ------ .../tests/unit/serializers/account-test.js | 38 +++++++++++++++++++ ui/core/mirage/serializers/account.js | 1 + 3 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 addons/api/tests/unit/serializers/account-test.js diff --git a/addons/api/tests/unit/models/account-test.js b/addons/api/tests/unit/models/account-test.js index 4237ae6b6..dcd3fe8bb 100644 --- a/addons/api/tests/unit/models/account-test.js +++ b/addons/api/tests/unit/models/account-test.js @@ -4,21 +4,10 @@ import { setupTest } from 'ember-qunit'; module('Unit | Model | account', function(hooks) { setupTest(hooks); - // Replace this with your real tests. test('it exists', function(assert) { let store = this.owner.lookup('service:store'); let model = store.createRecord('account', {}); assert.ok(model); }); - test('it contains attributes', function(assert) { - let store = this.owner.lookup('service:store'); - let model = store.createRecord('account', { - type: 'password', - attributes: { - login_name: 'loginname' - } - }); - assert.equal(model.attributes.login_name, 'loginname'); - }); }); diff --git a/addons/api/tests/unit/serializers/account-test.js b/addons/api/tests/unit/serializers/account-test.js new file mode 100644 index 000000000..9ab5b521c --- /dev/null +++ b/addons/api/tests/unit/serializers/account-test.js @@ -0,0 +1,38 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Serializer | account', function(hooks) { + setupTest(hooks); + + test('it serializes account', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('account'); + const record = store.createRecord('account', { + type: 'password', + name: 'Name', + description: 'Description', + attributes: { + login_name: 'Login Name', + password: 'Password', + }, + auth_method_id: '1', + version: 1 + }); + const snapshot = record._createSnapshot(); + snapshot.adapterOptions = {}; + const serializedRecord = serializer.serialize(snapshot); + assert.deepEqual(serializedRecord, { + type: 'password', + name: 'Name', + description: 'Description', + attributes: { + login_name: 'Login Name', + password: 'Password', + }, + auth_method_id: '1', + version: 1 + }); + }); + +}); diff --git a/ui/core/mirage/serializers/account.js b/ui/core/mirage/serializers/account.js index 7c6186756..85d38851b 100644 --- a/ui/core/mirage/serializers/account.js +++ b/ui/core/mirage/serializers/account.js @@ -6,6 +6,7 @@ export default ApplicationSerializer.extend({ _hashForModel(model) { const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments); json.auth_method_id = model.authMethodId; + delete json.attributes?.password; return json; } }); From 62b4e71687ef171b4863c12883575ee070865ad6 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 11:13:17 -0400 Subject: [PATCH 02/19] test: Update account serializer test for 'serializePassword' --- .../tests/unit/serializers/account-test.js | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/addons/api/tests/unit/serializers/account-test.js b/addons/api/tests/unit/serializers/account-test.js index 6906c458d..77b6d19d3 100644 --- a/addons/api/tests/unit/serializers/account-test.js +++ b/addons/api/tests/unit/serializers/account-test.js @@ -4,14 +4,6 @@ import { setupTest } from 'ember-qunit'; module('Unit | Serializer | account', function(hooks) { setupTest(hooks); - // Replace this with your real tests. - test('it exists', function(assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('account'); - - assert.ok(serializer); - }); - test('it serializes records', function(assert) { let store = this.owner.lookup('service:store'); let record = store.createRecord('account', {}); @@ -20,4 +12,29 @@ module('Unit | Serializer | account', function(hooks) { assert.ok(serializedRecord); }); + + test('it serializes only password when `adapterOptions.serializePassword` is true', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('account'); + const record = store.createRecord('account', { + type: 'password', + name: 'Name', + description: 'Description', + attributes: { + login_name: 'Login Name', + password: 'Password' + }, + version: 1 + }); + const snapshot = record._createSnapshot(); + snapshot.adapterOptions = { + serializePassword: true + }; + const serializedRecord = serializer.serialize(snapshot); + assert.deepEqual(serializedRecord, { + password: 'Password', + version: 1 + }); + }); }); From 64fb123b73be6d3951bc04fe4b657c809d950411 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 11:16:27 -0400 Subject: [PATCH 03/19] refactor: Conver password's setting form into set-password --- .../{settings.hbs => set-password.hbs} | 0 .../auth-method/accounts/account/settings.hbs | 2 +- .../account/password/set-password-test.js | 26 +++++++++++++++++++ .../form/account/password/settings-test.js | 23 ---------------- 4 files changed, 27 insertions(+), 24 deletions(-) rename ui/core/app/components/form/account/password/{settings.hbs => set-password.hbs} (100%) create mode 100644 ui/core/tests/integration/components/form/account/password/set-password-test.js delete mode 100644 ui/core/tests/integration/components/form/account/password/settings-test.js diff --git a/ui/core/app/components/form/account/password/settings.hbs b/ui/core/app/components/form/account/password/set-password.hbs similarity index 100% rename from ui/core/app/components/form/account/password/settings.hbs rename to ui/core/app/components/form/account/password/set-password.hbs diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs index 348503f1b..98fe07606 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs @@ -1,6 +1,6 @@

{{t 'descriptions.account-settings-overview'}}

-`); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +}); diff --git a/ui/core/tests/integration/components/form/account/password/settings-test.js b/ui/core/tests/integration/components/form/account/password/settings-test.js deleted file mode 100644 index c905dd76d..000000000 --- a/ui/core/tests/integration/components/form/account/password/settings-test.js +++ /dev/null @@ -1,23 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'ember-qunit'; -import { render, find } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Component | form/account/password/settings', function(hooks) { - setupRenderingTest(hooks); - - test('it renders', async function(assert) { - this.submit = () => {}; - this.cancel = () => {}; - this.model = { type: 'password' }; - - await render(hbs` - `); - - assert.ok(find('form')); - }); -}); From 2f8a5b96076464aeb6b96d38369ef5d2cf25df95 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 11:20:29 -0400 Subject: [PATCH 04/19] refactor: Wait for page transition before a notification --- .../routes/scopes/scope/auth-methods/auth-method/accounts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js index 2de991ee2..d5fbc41ef 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js @@ -38,11 +38,11 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route async save(account) { try { await account.save(); + await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account); this.refresh(); this.notify.success( this.intl.t('notify.save-success') ); - this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account); } catch (error) { // TODO: replace with translated strings this.notify.error(error.message, { closeAfter: null }); @@ -57,9 +57,9 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route async delete(account) { try { await account.destroyRecord(); + await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts'); this.refresh(); this.notify.success(this.intl.t('notify.delete-success')); - this.transitionTo('scopes.scope.auth-methods.auth-method.accounts'); } catch (error) { //TODO: replace with translated strings this.notify.error(error.message, { closeAfter: null }); From 5643db1eabe61a5738c25c35db156bd0af59fcc2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 12:25:13 -0400 Subject: [PATCH 05/19] fix: Mirage set-password should use attributes for update --- ui/core/mirage/config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 62cb242b7..f3a7cda5f 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -63,11 +63,12 @@ export default function() { const method = idMethod.split(':')[1]; const account = accounts.find(id); const updatedAttrs = { - version: attrs.version + version: attrs.version, + attributes: {} }; // Set new password if (method === 'set-password') { - updatedAttrs.password = accounts.attributes.password; + updatedAttrs.attributes.password = attrs.password; } return account.update(updatedAttrs); }); From 40d1e0ea7a1c6ea583299e1a8ded81f355f0a6f2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 14:18:48 -0400 Subject: [PATCH 06/19] test: Update set password form test --- .../account/password/set-password-test.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ui/core/tests/integration/components/form/account/password/set-password-test.js b/ui/core/tests/integration/components/form/account/password/set-password-test.js index 8aacee5e1..a5904574b 100644 --- a/ui/core/tests/integration/components/form/account/password/set-password-test.js +++ b/ui/core/tests/integration/components/form/account/password/set-password-test.js @@ -1,26 +1,24 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; +import { render, find } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | form/account/password/set-password', function(hooks) { setupRenderingTest(hooks); test('it renders', async function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); + this.submit = () => {}; + this.cancel = () => {}; + this.model = { type: 'password' }; - await render(hbs``); - - assert.equal(this.element.textContent.trim(), ''); - - // Template block usage: await render(hbs` - - template block text - - `); + `); - assert.equal(this.element.textContent.trim(), 'template block text'); + assert.ok(find('form')); }); + }); From 3a22fa2f1b7641c303bdfa7f64aaa056183b3a8d Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 16:33:15 -0400 Subject: [PATCH 07/19] feat: Remove password attribute dependency in account model --- ui/core/app/components/form/account/index.hbs | 70 ------------------- .../form/account/password/index.hbs | 38 +++++----- .../components/form/account/password/index.js | 24 +++++++ .../index.hbs} | 8 +-- .../account/password/set-password/index.js | 49 +++++++++++++ .../auth-methods/auth-method/accounts.js | 6 +- .../auth-method/accounts/account/settings.js | 7 +- .../auth-method/accounts/account/index.hbs | 2 +- .../auth-methods/auth-method/accounts/new.hbs | 1 + .../account/password/set-password-test.js | 1 - 10 files changed, 107 insertions(+), 99 deletions(-) delete mode 100644 ui/core/app/components/form/account/index.hbs create mode 100644 ui/core/app/components/form/account/password/index.js rename ui/core/app/components/form/account/password/{set-password.hbs => set-password/index.hbs} (81%) create mode 100644 ui/core/app/components/form/account/password/set-password/index.js diff --git a/ui/core/app/components/form/account/index.hbs b/ui/core/app/components/form/account/index.hbs deleted file mode 100644 index b7f418d63..000000000 --- a/ui/core/app/components/form/account/index.hbs +++ /dev/null @@ -1,70 +0,0 @@ - - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - {{#if @model.errors.description}} - - {{#each @model.errors.description as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - \ No newline at end of file diff --git a/ui/core/app/components/form/account/password/index.hbs b/ui/core/app/components/form/account/password/index.hbs index 4f167188f..33574e3eb 100644 --- a/ui/core/app/components/form/account/password/index.hbs +++ b/ui/core/app/components/form/account/password/index.hbs @@ -1,5 +1,5 @@ - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - + {{#if @allowPassword}} + + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + {{/if}} diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js new file mode 100644 index 000000000..2ddd5e563 --- /dev/null +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -0,0 +1,49 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { computed } from '@ember/object'; +import { set } from '@ember/object'; + +export default class FormAccountPasswordSetPasswordIndexComponent extends Component { + + // =properties + + /** + * New password property + * @type {string} + */ + password; + + /** + * Submit with password value when it is allowed. + * Callback with no arguments otherwise. + * @param {function} fn + */ + @action + submit(fn) { + fn(`${this.password}`); + this.resetPassword(); + } + + /** + * Unset password value before callback. + * @param {function} fn + */ + @action + cancel(fn) { + fn(); + this.resetPassword(); + } + + /** + * @type {boolean} + */ + @computed('password') + get cannotSave() { + return !(this.password?.length > 0); + } + + resetPassword() { + set(this, 'password', ''); + } + +} diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js index a33f74879..870984efa 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js @@ -37,10 +37,12 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route * @param {AccountModel} account */ @action - async save(account) { + async save(account, password) { const { isNew } = account; + const adapterOptions = {}; + if(isNew) { adapterOptions.password = password; } try { - await account.save(); + await account.save({ adapterOptions }); this.refresh(); this.notify.success( this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success') diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js index 115becc12..54a700a86 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js @@ -14,11 +14,12 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout /** * Save password for current account. * @param {AccountModel} account + * @param {string} password */ @action - async savePassword(account) { + async savePassword(account, password) { try { - await account.savePassword(); + await account.savePassword(password); await this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account.settings'); this.notify.success( this.intl.t('notify.save-success') @@ -34,6 +35,6 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout */ @action cancel() { - this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account'); + this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account.settings'); } } diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs index 07b4e30bc..41e9ca5c6 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs @@ -1,4 +1,4 @@ - Date: Tue, 15 Sep 2020 16:36:40 -0400 Subject: [PATCH 08/19] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20target=20de?= =?UTF-8?q?fault=5Fport=20field=20to=20API=20and=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/fragment-target-attributes.js | 10 +++++++ addons/api/addon/models/target.js | 8 +++++- .../app/models/fragment-target-attributes.js | 1 + .../api/tests/unit/serializers/target-test.js | 5 +++- ui/core/app/components/form/target/index.hbs | 27 +++++++++++++++---- ui/core/mirage/factories/target.js | 14 ++++++++++ ui/core/translations/en-us.yaml | 1 + 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 addons/api/addon/models/fragment-target-attributes.js create mode 100644 addons/api/app/models/fragment-target-attributes.js diff --git a/addons/api/addon/models/fragment-target-attributes.js b/addons/api/addon/models/fragment-target-attributes.js new file mode 100644 index 000000000..1ab994d9d --- /dev/null +++ b/addons/api/addon/models/fragment-target-attributes.js @@ -0,0 +1,10 @@ +import Fragment from 'ember-data-model-fragments/fragment'; +import { attr } from '@ember-data/model'; + +export default class FragmentTargetAttributesModel extends Fragment { + + @attr('number', { + description: 'The default port a target should use if present.' + }) default_port; + +} diff --git a/addons/api/addon/models/target.js b/addons/api/addon/models/target.js index 03a3ad5d7..57b87ff29 100644 --- a/addons/api/addon/models/target.js +++ b/addons/api/addon/models/target.js @@ -1,11 +1,17 @@ import GeneratedTargetModel from '../generated/models/target'; -import { fragmentArray } from 'ember-data-model-fragments/attributes'; +import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes'; import { computed } from '@ember/object'; export default class TargetModel extends GeneratedTargetModel { // =attributes + /** + * Attributes of this resource, if any, represented as a JSON fragment. + * @type {FragmentTargetAttributesModel} + */ + @fragment('fragment-target-attributes', { defaultValue: {} }) attributes; + /** * @type {[FragmentHostSetModel]} */ diff --git a/addons/api/app/models/fragment-target-attributes.js b/addons/api/app/models/fragment-target-attributes.js new file mode 100644 index 000000000..41eb7d88f --- /dev/null +++ b/addons/api/app/models/fragment-target-attributes.js @@ -0,0 +1 @@ +export { default } from 'api/models/fragment-target-attributes'; diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js index 94cab05e5..e129331eb 100644 --- a/addons/api/tests/unit/serializers/target-test.js +++ b/addons/api/tests/unit/serializers/target-test.js @@ -30,7 +30,10 @@ module('Unit | Serializer | target', function(hooks) { description: 'Description', version: 1, type: 'tcp', - scope_id: 'org_1' + scope_id: 'org_1', + attributes: { + default_port: null + } }); }); diff --git a/ui/core/app/components/form/target/index.hbs b/ui/core/app/components/form/target/index.hbs index a6e5a204e..5a977d2e4 100644 --- a/ui/core/app/components/form/target/index.hbs +++ b/ui/core/app/components/form/target/index.hbs @@ -14,11 +14,10 @@ {{#if @model.errors.name}} @@ -31,12 +30,10 @@ {{#if @model.errors.description}} @@ -47,6 +44,26 @@ {{/if}} + {{!-- TODO this is a type-specific field --}} + + {{!-- TODO need to figure out how to reference `attributes.errors` here --}} + {{#if @model.errors.default_port}} + + {{#each @model.errors.default_port as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + Math.random() < chance; const hostSetChance = 0.3; export default factory.extend({ + /** + * Generates attributes fields by type. + */ + afterCreate(target) { + if (target.type === 'tcp') { + target.update({ + attributes: { + default_port: random.number() + } + }); + } + }, + /** * Randomly selects existing host sets to assign to target. */ diff --git a/ui/core/translations/en-us.yaml b/ui/core/translations/en-us.yaml index 394f1e6ec..142c3577f 100644 --- a/ui/core/translations/en-us.yaml +++ b/ui/core/translations/en-us.yaml @@ -140,6 +140,7 @@ form: address: Address protocol: Protocol actions: Actions + default_port: Default Port errors: titles: unauthenticated-error: You are not signed in From d9353bdc3b3164961702f8646da6a40ef47a6793 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 16:51:07 -0400 Subject: [PATCH 09/19] fix: Remove password attribute from account model --- addons/api/addon/models/account.js | 25 +++++++ .../models/fragment-account-attributes.js | 3 - addons/api/addon/serializers/account.js | 39 +++++++++++ addons/api/app/serializers/account.js | 1 + .../tests/unit/serializers/account-test.js | 67 +++++++++++++++++-- 5 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 addons/api/addon/serializers/account.js create mode 100644 addons/api/app/serializers/account.js diff --git a/addons/api/addon/models/account.js b/addons/api/addon/models/account.js index 76321d86d..4c16a34a4 100644 --- a/addons/api/addon/models/account.js +++ b/addons/api/addon/models/account.js @@ -9,4 +9,29 @@ export default class AccountModel extends GeneratedAccountModel { */ @fragment('fragment-account-attributes', { defaultValue: {} }) attributes; + // =methods + + /** + * Save account password via the `set-password` method. + * See serializer and adapter for more information. + * @param {string} password + * @param {object} options + * @param {object} options.adapterOptions + * @return {Promise} + */ + savePassword(password, options={ adapterOptions: {} }) { + const defaultAdapterOptions = { + method: 'set-password', + serializeWithNewPassword: true, + password + }; + return this.save({ + ...options, + adapterOptions: { + ...defaultAdapterOptions, + ...options.adapterOptions + } + }); + } + } diff --git a/addons/api/addon/models/fragment-account-attributes.js b/addons/api/addon/models/fragment-account-attributes.js index ee2281f18..76ee82487 100644 --- a/addons/api/addon/models/fragment-account-attributes.js +++ b/addons/api/addon/models/fragment-account-attributes.js @@ -7,7 +7,4 @@ export default class FragmentAccountAttributesModel extends Fragment { description: 'The account login name' }) login_name; - @attr('string', { - description: 'The account password' - }) password; } diff --git a/addons/api/addon/serializers/account.js b/addons/api/addon/serializers/account.js new file mode 100644 index 000000000..acad9cb7e --- /dev/null +++ b/addons/api/addon/serializers/account.js @@ -0,0 +1,39 @@ +import ApplicationSerializer from './application'; +import { get } from '@ember/object'; + +export default class AccountSerializer extends ApplicationSerializer { + + // =methods + + /** + * If `adapterOptions.serializeWithNewPassword` is true, the serialization should + * include **password** and the version. + * If `adapterOptions.password` is set, the serialization should + * include **password** in it's `attributes`. + * @override + * @param {Snapshot} snapshot + * @return {object} + */ + serialize(snapshot) { + const password = get(snapshot, 'adapterOptions.password'); + const serializeWithNewPassword = get(snapshot, 'adapterOptions.serializeWithNewPassword'); + let serialized = super.serialize(...arguments); + if (password) serialized.attributes.password = password; + if (serializeWithNewPassword) serialized = this.serializeWithNewPassword(snapshot, password) + return serialized; + } + + /** + * Returns a payload containing only new password. + * @param {Snapshot} snapshot + * @param {string} password + * @return {object} + */ + serializeWithNewPassword(snapshot, password) { + return { + version: snapshot.attr('version'), + password, + }; + } + +} diff --git a/addons/api/app/serializers/account.js b/addons/api/app/serializers/account.js new file mode 100644 index 000000000..af9b2cc1c --- /dev/null +++ b/addons/api/app/serializers/account.js @@ -0,0 +1 @@ +export { default } from 'api/serializers/account'; diff --git a/addons/api/tests/unit/serializers/account-test.js b/addons/api/tests/unit/serializers/account-test.js index 9ab5b521c..7a523d9dd 100644 --- a/addons/api/tests/unit/serializers/account-test.js +++ b/addons/api/tests/unit/serializers/account-test.js @@ -4,19 +4,18 @@ import { setupTest } from 'ember-qunit'; module('Unit | Serializer | account', function(hooks) { setupTest(hooks); - test('it serializes account', function (assert) { + test('it serializes normally', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('account'); const record = store.createRecord('account', { type: 'password', name: 'Name', + auth_method_id: '1', description: 'Description', attributes: { login_name: 'Login Name', - password: 'Password', }, - auth_method_id: '1', version: 1 }); const snapshot = record._createSnapshot(); @@ -25,14 +24,70 @@ module('Unit | Serializer | account', function(hooks) { assert.deepEqual(serializedRecord, { type: 'password', name: 'Name', + auth_method_id: '1', description: 'Description', attributes: { - login_name: 'Login Name', - password: 'Password', + login_name: 'Login Name' }, - auth_method_id: '1', version: 1 }); }); + test('it serializes password attribute when `adapterOptions.password` is true', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('account'); + const record = store.createRecord('account', { + type: 'password', + name: 'Name', + auth_method_id: '1', + description: 'Description', + attributes: { + login_name: 'Login Name', + }, + version: 1 + }); + const snapshot = record._createSnapshot(); + snapshot.adapterOptions = { + password: 'Password' + }; + const serializedRecord = serializer.serialize(snapshot); + assert.deepEqual(serializedRecord, { + type: 'password', + name: 'Name', + auth_method_id: '1', + description: 'Description', + attributes: { + login_name: 'Login Name', + password: 'Password' + }, + version: 1 + }); + }); + + test('it serializes only password when `adapterOptions.serializeWithNewPassword` is true', function (assert) { + assert.expect(1); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('account'); + const record = store.createRecord('account', { + type: 'password', + name: 'Name', + description: 'Description', + attributes: { + login_name: 'Login Name' + }, + auth_method_id: '1', + version: 1 + }); + const snapshot = record._createSnapshot(); + snapshot.adapterOptions = { + serializeWithNewPassword: true, + password: 'Password' + }; + const serializedRecord = serializer.serialize(snapshot); + assert.deepEqual(serializedRecord, { + password: 'Password', + version: 1 + }); + }); }); From b6c91ede402e93baf09cdebd1130746cc6085c7a Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 17:02:36 -0400 Subject: [PATCH 10/19] test: Remove inverse relation in auth-method --- ui/core/mirage/config.js | 2 +- ui/core/mirage/models/auth-method.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index f3a7cda5f..7f2ea5ba0 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -64,7 +64,7 @@ export default function() { const account = accounts.find(id); const updatedAttrs = { version: attrs.version, - attributes: {} + attributes: account.attributes }; // Set new password if (method === 'set-password') { diff --git a/ui/core/mirage/models/auth-method.js b/ui/core/mirage/models/auth-method.js index 878b8bd8a..3aebcb472 100644 --- a/ui/core/mirage/models/auth-method.js +++ b/ui/core/mirage/models/auth-method.js @@ -2,7 +2,6 @@ import { Model, belongsTo, hasMany} from 'ember-cli-mirage'; export default Model.extend({ - scope: belongsTo(), - accounts: hasMany('account') + scope: belongsTo() }); From 6549e094c1703210507e6cea19dbcbb76e1a1bc4 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 17:06:33 -0400 Subject: [PATCH 11/19] fix: Remove unused 'hasMany' import in auth-method mirage --- ui/core/mirage/models/auth-method.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/core/mirage/models/auth-method.js b/ui/core/mirage/models/auth-method.js index 3aebcb472..08b1f5ad3 100644 --- a/ui/core/mirage/models/auth-method.js +++ b/ui/core/mirage/models/auth-method.js @@ -1,4 +1,4 @@ -import { Model, belongsTo, hasMany} from 'ember-cli-mirage'; +import { Model, belongsTo } from 'ember-cli-mirage'; export default Model.extend({ From f9c88012ffbce9cf3831bbe650f58d68a0be61bb Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 17:23:51 -0400 Subject: [PATCH 12/19] refactor: Use @model.isNew instead of custom allowPassword --- ui/core/app/components/form/account/password/index.hbs | 2 +- .../scopes/scope/auth-methods/auth-method/accounts/new.hbs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/core/app/components/form/account/password/index.hbs b/ui/core/app/components/form/account/password/index.hbs index 33574e3eb..8c920be38 100644 --- a/ui/core/app/components/form/account/password/index.hbs +++ b/ui/core/app/components/form/account/password/index.hbs @@ -63,7 +63,7 @@ {{/if}} - {{#if @allowPassword}} + {{#if @model.isNew}} Date: Tue, 15 Sep 2020 18:11:23 -0400 Subject: [PATCH 13/19] refactor: Remove serializeWithNewPassword adapteroptions --- addons/api/addon/models/account.js | 3 +-- addons/api/addon/serializers/account.js | 16 ++++++++-------- .../api/tests/unit/serializers/account-test.js | 8 ++++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/api/addon/models/account.js b/addons/api/addon/models/account.js index 4c16a34a4..4c52347f5 100644 --- a/addons/api/addon/models/account.js +++ b/addons/api/addon/models/account.js @@ -19,10 +19,9 @@ export default class AccountModel extends GeneratedAccountModel { * @param {object} options.adapterOptions * @return {Promise} */ - savePassword(password, options={ adapterOptions: {} }) { + setPassword(password, options={ adapterOptions: {} }) { const defaultAdapterOptions = { method: 'set-password', - serializeWithNewPassword: true, password }; return this.save({ diff --git a/addons/api/addon/serializers/account.js b/addons/api/addon/serializers/account.js index acad9cb7e..c014c2361 100644 --- a/addons/api/addon/serializers/account.js +++ b/addons/api/addon/serializers/account.js @@ -1,13 +1,12 @@ import ApplicationSerializer from './application'; -import { get } from '@ember/object'; export default class AccountSerializer extends ApplicationSerializer { // =methods /** - * If `adapterOptions.serializeWithNewPassword` is true, the serialization should - * include **password** and the version. + * If `adapterOptions.method` is `set-password`, the serialization should + * include only **password** and the version. * If `adapterOptions.password` is set, the serialization should * include **password** in it's `attributes`. * @override @@ -15,11 +14,12 @@ export default class AccountSerializer extends ApplicationSerializer { * @return {object} */ serialize(snapshot) { - const password = get(snapshot, 'adapterOptions.password'); - const serializeWithNewPassword = get(snapshot, 'adapterOptions.serializeWithNewPassword'); + const password = snapshot?.adapterOptions?.password; let serialized = super.serialize(...arguments); - if (password) serialized.attributes.password = password; - if (serializeWithNewPassword) serialized = this.serializeWithNewPassword(snapshot, password) + if (password && snapshot?.record?.isNew) serialized.attributes.password = password; + if (snapshot?.adapterOptions?.method === 'set-password') { + serialized = this.serializeForSetPassword(snapshot, password); + } return serialized; } @@ -29,7 +29,7 @@ export default class AccountSerializer extends ApplicationSerializer { * @param {string} password * @return {object} */ - serializeWithNewPassword(snapshot, password) { + serializeForSetPassword(snapshot, password) { return { version: snapshot.attr('version'), password, diff --git a/addons/api/tests/unit/serializers/account-test.js b/addons/api/tests/unit/serializers/account-test.js index 7a523d9dd..85f9b655f 100644 --- a/addons/api/tests/unit/serializers/account-test.js +++ b/addons/api/tests/unit/serializers/account-test.js @@ -65,7 +65,11 @@ module('Unit | Serializer | account', function(hooks) { }); }); - test('it serializes only password when `adapterOptions.serializeWithNewPassword` is true', function (assert) { + test('it does not serialize password for non-new records', function (assert) { + assert.expect(0); + }); + + test('it serializes only password when `adapterOptions.method` is set to `set-password`', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('account'); @@ -81,7 +85,7 @@ module('Unit | Serializer | account', function(hooks) { }); const snapshot = record._createSnapshot(); snapshot.adapterOptions = { - serializeWithNewPassword: true, + method: 'set-password', password: 'Password' }; const serializedRecord = serializer.serialize(snapshot); From fa9706c7b19e959c484280cc7a57505fd11b9c8c Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 18:16:07 -0400 Subject: [PATCH 14/19] fix: Use updated setPassword method instead of savePassword --- .../auth-methods/auth-method/accounts/account/settings.js | 6 +++--- .../auth-methods/auth-method/accounts/account/settings.hbs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js index 115becc12..07f416dcf 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js @@ -12,13 +12,13 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout // =actions /** - * Save password for current account. + * Set password for current account. * @param {AccountModel} account */ @action - async savePassword(account) { + async setPassword(account) { try { - await account.savePassword(); + await account.setPassword(); await this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account.settings'); this.notify.success( this.intl.t('notify.save-success') diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs index 98fe07606..c26483e46 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/settings.hbs @@ -2,6 +2,6 @@ From 40c4741c58ff091d4a21d900ba2aa77b76c9762b Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 09:48:07 -0400 Subject: [PATCH 15/19] =?UTF-8?q?chore:=20=F0=9F=A4=96=20minor=20stylistic?= =?UTF-8?q?=20tweaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/scopes/scope/auth-methods/auth-method.js | 2 +- .../scopes/scope/auth-methods/auth-method/accounts.js | 10 ++++++---- .../scope/auth-methods/auth-method/accounts/account.js | 3 +-- .../scope/auth-methods/auth-method/accounts/index.hbs | 4 ++-- ui/core/translations/en-us.yaml | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method.js index a0d7dca9d..3c608f660 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method.js @@ -4,7 +4,7 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route { // =methods /** - * Load a single auth-method in current scope. + * Load an auth method by ID. * @param {object} params * @param {string} params.auth_method_id * @return {authMethodModel} diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js index 54ac54e9f..7bd909128 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js @@ -12,15 +12,17 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route // =methods /** - * Returns accounts in current auth method. + * Returns accounts for the current auth method. * @return {Promise{[AccountModel]}} */ model() { - const { id: auth_method_id } = this.modelFor('scopes.scope.auth-methods.auth-method'); + const { id: auth_method_id } = + this.modelFor('scopes.scope.auth-methods.auth-method'); return this.store.query('account', { auth_method_id }); } // =actions + /** * Rollback changes on an account. * @param {AccountModel} account @@ -38,11 +40,11 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route async save(account) { try { await account.save(); - this.refresh(); + await this.refresh(); + await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account); this.notify.success( this.intl.t('notify.save-success') ); - this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account); } catch (error) { // TODO: replace with translated strings this.notify.error(error.message, { closeAfter: null }); diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account.js index 9b848945a..4b290a2c3 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account.js @@ -5,7 +5,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountRoute extend // =methods /** - * Load an account in current scope. + * Load an account by ID. * @param {object} params * @param {string} params.account_id * @return {AccountModel} @@ -27,7 +27,6 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountRoute extend }); this.render('-empty', { - // this.render('scopes/scope/auth-methods/auth-method/accounts/account/-actions', { into: 'scopes/scope/auth-methods/auth-method', outlet: 'actions' }); 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 6b68c78f7..8586ac7c0 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 @@ -30,9 +30,9 @@ {{else}} - + - {{t "descriptions.auth-method-accounts-welcome"}} + {{t "descriptions.accounts-welcome"}} diff --git a/ui/core/translations/en-us.yaml b/ui/core/translations/en-us.yaml index 3e972fc9e..bc7e08dc6 100644 --- a/ui/core/translations/en-us.yaml +++ b/ui/core/translations/en-us.yaml @@ -109,7 +109,7 @@ titles: no-available-users: No Users Available accounts: Accounts account: Account - auth-method-accounts-welcome: Welcome to Accounts + accounts-welcome: Welcome to Accounts descriptions: host-catalogs: Overview of collections of hosts and host sets. empty-set: There are no items to display yet. You may be able to add items or try back later. @@ -130,7 +130,7 @@ descriptions: 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. - auth-method-accounts-welcome: No accounts are available in this auth method. + accounts-welcome: No accounts are available in this auth method. states: info: Info success: Success From 47b231be1b5114956d32adcff41fcb994890f6e4 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 09:50:21 -0400 Subject: [PATCH 16/19] chore: remove badge from header as it is unprecedented and needs styles --- .../scopes/scope/auth-methods/auth-method/-header.hbs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/-header.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/-header.hbs index 12f2b18eb..b2abc5389 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/-header.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/-header.hbs @@ -1,4 +1,6 @@

{{t "resources.auth-method"}}

+{{!-- {{t (concat 'auth.method-types.' @model.type)}} - \ No newline at end of file + +--}} From 2e3b044ae99f0b5dc23cfc4cedd6c79f3440569e Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 12:01:54 -0400 Subject: [PATCH 17/19] =?UTF-8?q?chore:=20=F0=9F=A4=96=20cleanu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/account/password/index.hbs | 3 +- .../components/form/account/password/index.js | 6 +- .../account/password/set-password/index.js | 57 +++++++++++-------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/ui/core/app/components/form/account/password/index.hbs b/ui/core/app/components/form/account/password/index.hbs index 8c920be38..facd43c2f 100644 --- a/ui/core/app/components/form/account/password/index.hbs +++ b/ui/core/app/components/form/account/password/index.hbs @@ -87,4 +87,5 @@ @disabled={{if @model.cannotSave @model.cannotSave}} @submitText={{t "actions.save"}} @cancelText={{t "actions.cancel"}} /> -
\ No newline at end of file + + diff --git a/ui/core/app/components/form/account/password/index.js b/ui/core/app/components/form/account/password/index.js index 842036137..caf239d17 100644 --- a/ui/core/app/components/form/account/password/index.js +++ b/ui/core/app/components/form/account/password/index.js @@ -11,14 +11,16 @@ export default class FormAccountPasswordIndexComponent extends Component { */ password; + // =actions + /** * Submit with password value when it is allowed. * Callback with no arguments otherwise. - * @param {function} fn + * @param {function} fn */ @action submit(fn) { - this.args.allowPassword ? fn(`${this.password}`) : fn(); + this.args.model.isNew ? fn(this.password) : fn(); delete this.password; } } diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js index 2ddd5e563..a4039b76d 100644 --- a/ui/core/app/components/form/account/password/set-password/index.js +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -1,7 +1,7 @@ import Component from '@glimmer/component'; -import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; import { computed } from '@ember/object'; -import { set } from '@ember/object'; +import { action } from '@ember/object'; export default class FormAccountPasswordSetPasswordIndexComponent extends Component { @@ -11,28 +11,7 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon * New password property * @type {string} */ - password; - - /** - * Submit with password value when it is allowed. - * Callback with no arguments otherwise. - * @param {function} fn - */ - @action - submit(fn) { - fn(`${this.password}`); - this.resetPassword(); - } - - /** - * Unset password value before callback. - * @param {function} fn - */ - @action - cancel(fn) { - fn(); - this.resetPassword(); - } + @tracked password; /** * @type {boolean} @@ -42,8 +21,36 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon return !(this.password?.length > 0); } + // =methods + + /** + * Unsets the password field. + */ resetPassword() { - set(this, 'password', ''); + this.password = null; + } + + // =actions + + /** + * Submit with password value when it is allowed. + * Callback with no arguments otherwise. + * @param {function} fn + */ + @action + submit(fn) { + fn(this.password); + this.resetPassword(); + } + + /** + * Unset password value before callback. + * @param {function} fn + */ + @action + cancel(fn) { + fn(); + this.resetPassword(); } } From b1230a4b3fe5f5848864bdbda725cccf67ba11a1 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 12:13:16 -0400 Subject: [PATCH 18/19] =?UTF-8?q?chore:=20=F0=9F=A4=96=20cleanup=20passwor?= =?UTF-8?q?d=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/form/account/password/index.js | 22 ++++++++++++++++--- .../account/password/set-password/index.js | 20 +++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/ui/core/app/components/form/account/password/index.js b/ui/core/app/components/form/account/password/index.js index caf239d17..02f208746 100644 --- a/ui/core/app/components/form/account/password/index.js +++ b/ui/core/app/components/form/account/password/index.js @@ -1,4 +1,5 @@ import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; export default class FormAccountPasswordIndexComponent extends Component { @@ -9,7 +10,16 @@ export default class FormAccountPasswordIndexComponent extends Component { * Account password property * @type {string} */ - password; + @tracked password; + + // =methods + + /** + * Unsets the password field. + */ + resetPassword() { + this.password = null; + } // =actions @@ -20,7 +30,13 @@ export default class FormAccountPasswordIndexComponent extends Component { */ @action submit(fn) { - this.args.model.isNew ? fn(this.password) : fn(); - delete this.password; + try { + this.args.model.isNew ? fn(this.password) : fn(); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } } diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js index a4039b76d..2449d4c6f 100644 --- a/ui/core/app/components/form/account/password/set-password/index.js +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -39,8 +39,14 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action submit(fn) { - fn(this.password); - this.resetPassword(); + try { + fn(this.password); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } /** @@ -49,8 +55,14 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action cancel(fn) { - fn(); - this.resetPassword(); + try { + fn(); + } catch (e) { + // We want to guarantee password is unset + this.resetPassword(); + // But we don't want to silence the error + throw e; + } } } From a5b840f11bcc956f06d4a513ccc61846085d5632 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Sep 2020 12:20:35 -0400 Subject: [PATCH 19/19] =?UTF-8?q?chore:=20=F0=9F=A4=96=20reset=20password?= =?UTF-8?q?=20before=20executing=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/form/account/password/index.js | 11 +++------- .../account/password/set-password/index.js | 21 +++++-------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/ui/core/app/components/form/account/password/index.js b/ui/core/app/components/form/account/password/index.js index 02f208746..e80e48c95 100644 --- a/ui/core/app/components/form/account/password/index.js +++ b/ui/core/app/components/form/account/password/index.js @@ -30,13 +30,8 @@ export default class FormAccountPasswordIndexComponent extends Component { */ @action submit(fn) { - try { - this.args.model.isNew ? fn(this.password) : fn(); - } catch (e) { - // We want to guarantee password is unset - this.resetPassword(); - // But we don't want to silence the error - throw e; - } + const password = this.password; + this.resetPassword(); + this.args.model.isNew ? fn(password) : fn(); } } diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js index 2449d4c6f..477c14cee 100644 --- a/ui/core/app/components/form/account/password/set-password/index.js +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -39,14 +39,9 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action submit(fn) { - try { - fn(this.password); - } catch (e) { - // We want to guarantee password is unset - this.resetPassword(); - // But we don't want to silence the error - throw e; - } + const password = this.password; + this.resetPassword(); + fn(password); } /** @@ -55,14 +50,8 @@ export default class FormAccountPasswordSetPasswordIndexComponent extends Compon */ @action cancel(fn) { - try { - fn(); - } catch (e) { - // We want to guarantee password is unset - this.resetPassword(); - // But we don't want to silence the error - throw e; - } + this.resetPassword(); + fn(); } }