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:
Lisbet Alvarez authored and GitHub committed 2024-03-07 09:24:28 -08:00
1 parent 7dab184bb9
commit a54aecee07
18 files changed
+238 -141

No files matched your search

@@ -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;
}
@@ -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;
}