From 3a22fa2f1b7641c303bdfa7f64aaa056183b3a8d Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 15 Sep 2020 16:33:15 -0400 Subject: [PATCH] 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 @@ -