refactor: 💡 remove route-action usage in accounts (#2134)
* refactor: 💡 remove route-action usage in accounts ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12616
This commit is contained in:
1 parent
7dab184bb9
commit
a54aecee07
18 files changed
+238
-141
No files matched your search
@@ -12,7 +12,7 @@
|
||||
<dropdown.button
|
||||
@style='danger'
|
||||
@disabled={{@model.canSave}}
|
||||
{{on 'click' (route-action 'deleteAccount' @model)}}
|
||||
{{on 'click' (fn @delete @model)}}
|
||||
>
|
||||
{{t 'resources.account.actions.delete'}}
|
||||
</dropdown.button>
|
||||
|
||||
@@ -5,9 +5,45 @@
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class AccountChangePasswordController extends Controller {
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Changes the password on the account and then redirects to the index route.
|
||||
* @param {AccountModel} account
|
||||
* @param {string} currentPassword
|
||||
* @param {string} newPassword
|
||||
*/
|
||||
@action
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.save-success')
|
||||
async changePassword(account, currentPassword, newPassword) {
|
||||
await account.changePassword(currentPassword, newPassword);
|
||||
// Transition to index after success. We ignore errors in the transition,
|
||||
// since the index route is responsible for additional
|
||||
// redirects depending on the authentication context. These additional
|
||||
// redirects may abort this initial transition, resulting in a
|
||||
// TransitionAborted error, which we do not want to show to the user.
|
||||
try {
|
||||
await this.router.replaceWith('index');
|
||||
} catch (e) {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On cancel, redirects to index route for further processing.
|
||||
*/
|
||||
@action
|
||||
cancel() {
|
||||
this.router.replaceWith('index');
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountIndexController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/auth-method/accounts/index') accounts;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSetPasswordController extends Controller {
|
||||
// =controllers
|
||||
|
||||
@controller('scopes/scope/auth-methods/auth-method/accounts/index') accounts;
|
||||
|
||||
// =services
|
||||
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Set password for the specified account.
|
||||
* @param {AccountModel} account
|
||||
* @param {string} password
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.save-success')
|
||||
async setPassword(account, password) {
|
||||
await account.setPassword(password);
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.accounts.account.set-password',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsIndexController extends Controller {
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on an account.
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
async cancel(account) {
|
||||
const { isNew } = account;
|
||||
account.rollbackAttributes();
|
||||
if (isNew) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an account in current scope.
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(account, password) {
|
||||
const { isNew } = account;
|
||||
const adapterOptions = {};
|
||||
if (isNew) {
|
||||
adapterOptions.password = password;
|
||||
}
|
||||
await account.save({ adapterOptions });
|
||||
if (this.can.can('read model', account)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts.account',
|
||||
account,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an account in current scope and redirect to index
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(account) {
|
||||
await account.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
await this.router.refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsNewController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/auth-method/accounts/index') accounts;
|
||||
}
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
/**
|
||||
* The change password flow is associated only with password-type auth methods.
|
||||
@@ -30,33 +28,4 @@ export default class AccountChangePasswordRoute extends Route {
|
||||
const account_id = this.session?.data?.authenticated?.account_id;
|
||||
return this.store.findRecord('account', account_id);
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Changes the password on the account and then redirects to the index route.
|
||||
* @param {AccountModel} account
|
||||
* @param {string} currentPassword
|
||||
* @param {string} newPassword
|
||||
*/
|
||||
@action
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.save-success')
|
||||
async changePassword(account, currentPassword, newPassword) {
|
||||
await account.changePassword(currentPassword, newPassword);
|
||||
// Transition to index after success. We ignore errors in the transition,
|
||||
// since the index route is responsible for additional
|
||||
// redirects depending on the authentication context. These additional
|
||||
// redirects may abort this initial transition, resulting in a
|
||||
// TransitionAborted error, which we do not want to show to the user.
|
||||
await this.router.replaceWith('index').catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* On cancel, redirects to index route for further processing.
|
||||
*/
|
||||
@action
|
||||
cancel() {
|
||||
this.router.replaceWith('index');
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,13 @@
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service intl;
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =methods
|
||||
|
||||
@@ -42,67 +36,4 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
|
||||
accounts,
|
||||
};
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on an account.
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
cancel(account) {
|
||||
const { isNew } = account;
|
||||
account.rollbackAttributes();
|
||||
if (isNew)
|
||||
this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an account in current scope.
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(account, password) {
|
||||
const { isNew } = account;
|
||||
const adapterOptions = {};
|
||||
if (isNew) {
|
||||
adapterOptions.password = password;
|
||||
}
|
||||
await account.save({ adapterOptions });
|
||||
if (this.can.can('read model', account)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts.account',
|
||||
account,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an account in current scope and redirect to index
|
||||
* @param {AccountModel} account
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async deleteAccount(account) {
|
||||
await account.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.accounts',
|
||||
);
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
+1
-29
@@ -4,33 +4,5 @@
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Set password for the specified account.
|
||||
* @param {AccountModel} account
|
||||
* @param {string} password
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.save-success')
|
||||
async setPassword(account, password) {
|
||||
await account.setPassword(password);
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.accounts.account.set-password',
|
||||
);
|
||||
}
|
||||
}
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSetPasswordRoute extends Route {}
|
||||
@@ -18,8 +18,8 @@
|
||||
<page.body>
|
||||
<Form::Account::Password::ChangePassword
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'changePassword' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@submit={{fn this.changePassword @model}}
|
||||
@cancel={{fn this.cancel @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
|
||||
+6
-3
@@ -18,14 +18,17 @@
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::Accounts::Account::Actions @model={{@model}} />
|
||||
<AuthMethods::AuthMethod::Accounts::Account::Actions
|
||||
@model={{@model}}
|
||||
@delete={{this.accounts.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::Account
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@submit={{fn this.accounts.save @model}}
|
||||
@cancel={{fn this.accounts.cancel @model}}
|
||||
/>
|
||||
|
||||
</page.body>
|
||||
|
||||
+6
-3
@@ -26,14 +26,17 @@
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::Accounts::Account::Actions @model={{@model}} />
|
||||
<AuthMethods::AuthMethod::Accounts::Account::Actions
|
||||
@model={{@model}}
|
||||
@delete={{this.accounts.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::Account::Password::SetPassword
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'setPassword' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@submit={{fn this.setPassword @model}}
|
||||
@cancel={{fn this.accounts.cancel @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
<page.body>
|
||||
<Form::Account
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@submit={{fn this.accounts.save @model}}
|
||||
@cancel={{fn this.accounts.cancel @model}}
|
||||
/>
|
||||
|
||||
</page.body>
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/account/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/accounts/account/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/account/set-password',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/accounts/account/set-password',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/accounts/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/new',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/accounts/new',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -9,7 +9,6 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// TODO: Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
|
||||
Reference in new issue
Block a user