From 3a22fa2f1b7641c303bdfa7f64aaa056183b3a8d Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 16:33:15 -0400 Subject: [PATCH 1/5] 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 17:23:51 -0400 Subject: [PATCH 2/5] 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: Wed, 16 Sep 2020 12:01:54 -0400 Subject: [PATCH 3/5] =?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 4/5] =?UTF-8?q?chore:=20=F0=9F=A4=96=20cleanup=20password?= =?UTF-8?q?=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 5/5] =?UTF-8?q?chore:=20=F0=9F=A4=96=20reset=20password=20?= =?UTF-8?q?before=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(); } }