Merge pull request #187 from hashicorp/ICU-580-remove-password-attribute-from-account-model
Remove password attribute dependency in account model
This commit is contained in:
9 files changed
+128
-99
No files matched your search
@@ -1,70 +0,0 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
as |form|
|
||||
>
|
||||
<form.input
|
||||
@value={{t (concat 'account.types.' @model.type)}}
|
||||
@label={{t "form.label.type"}}
|
||||
readonly={{true}}
|
||||
@disabled={{true}} />
|
||||
|
||||
<form.input
|
||||
@name="name"
|
||||
@type="name"
|
||||
@value={{@model.name}}
|
||||
@label={{t "form.label.name"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.textarea
|
||||
@name="description"
|
||||
@type="description"
|
||||
@value={{@model.description}}
|
||||
@label={{t "form.label.description"}}
|
||||
@error={{@model.errors.description}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|>
|
||||
{{#if @model.errors.description}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
|
||||
<form.input
|
||||
@name="login_name"
|
||||
@type="text"
|
||||
@value={{@model.attributes.login_name}}
|
||||
@label={{t "form.label.identification"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
@submitText={{t "actions.save"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
</Rose::Form>
|
||||
@@ -1,5 +1,5 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@onSubmit={{fn this.submit @submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
@@ -63,26 +63,29 @@
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.input
|
||||
@name="password"
|
||||
@type="password"
|
||||
@value={{@model.attributes.password}}
|
||||
@label={{t "form.label.password"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
autocomplete="new-password"
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
{{#if @model.isNew}}
|
||||
<form.input
|
||||
@name="password"
|
||||
@type="password"
|
||||
@value={{this.password}}
|
||||
@label={{t "form.label.password"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
autocomplete="new-password"
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
{{/if}}
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
@submitText={{t "actions.save"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
</Rose::Form>
|
||||
|
||||
</Rose::Form>
|
||||
@@ -0,0 +1,37 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class FormAccountPasswordIndexComponent extends Component {
|
||||
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* Account password property
|
||||
* @type {string}
|
||||
*/
|
||||
@tracked password;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Unsets the password field.
|
||||
*/
|
||||
resetPassword() {
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Submit with password value when it is allowed.
|
||||
* Callback with no arguments otherwise.
|
||||
* @param {function} fn
|
||||
*/
|
||||
@action
|
||||
submit(fn) {
|
||||
const password = this.password;
|
||||
this.resetPassword();
|
||||
this.args.model.isNew ? fn(password) : fn();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@onSubmit={{fn this.submit @submit}}
|
||||
@cancel={{fn this.cancel @cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
as |form|
|
||||
@@ -9,7 +9,7 @@
|
||||
<form.input
|
||||
@name="password"
|
||||
@type="password"
|
||||
@value={{@model.attributes.password}}
|
||||
@value={{this.password}}
|
||||
@label={{t "form.label.password"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
@@ -25,7 +25,7 @@
|
||||
</form.input>
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
@disabled={{this.cannotSave}}
|
||||
@submitText={{t "actions.save"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { computed } from '@ember/object';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class FormAccountPasswordSetPasswordIndexComponent extends Component {
|
||||
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* New password property
|
||||
* @type {string}
|
||||
*/
|
||||
@tracked password;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('password')
|
||||
get cannotSave() {
|
||||
return !(this.password?.length > 0);
|
||||
}
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Unsets the password field.
|
||||
*/
|
||||
resetPassword() {
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Submit with password value when it is allowed.
|
||||
* Callback with no arguments otherwise.
|
||||
* @param {function} fn
|
||||
*/
|
||||
@action
|
||||
submit(fn) {
|
||||
const password = this.password;
|
||||
this.resetPassword();
|
||||
fn(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset password value before callback.
|
||||
* @param {function} fn
|
||||
*/
|
||||
@action
|
||||
cancel(fn) {
|
||||
this.resetPassword();
|
||||
fn();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,12 +39,14 @@ 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 this.refresh();
|
||||
await account.save({ adapterOptions });
|
||||
await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account);
|
||||
this.refresh();
|
||||
this.notify.success(
|
||||
this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success')
|
||||
);
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout
|
||||
/**
|
||||
* Set password for current account.
|
||||
* @param {AccountModel} account
|
||||
* @param {string} password
|
||||
*/
|
||||
@action
|
||||
async setPassword(account) {
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<Form::Account
|
||||
<Form::Account::Password
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
|
||||
@@ -20,5 +20,4 @@ module('Integration | Component | form/account/password/set-password', function(
|
||||
|
||||
assert.ok(find('form'));
|
||||
});
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user