Files
threshold-ui/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/accounts.js
T

79 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-09-14 15:58:06 -04:00
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
2020-09-14 15:58:06 -04:00
export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route {
// =services
@service intl;
@service notify;
2020-09-14 15:58:06 -04:00
// =methods
/**
2020-09-16 09:48:07 -04:00
* Returns accounts for the current auth method.
2020-09-14 15:58:06 -04:00
* @return {Promise{[AccountModel]}}
*/
model() {
2020-09-16 14:33:04 -04:00
const { id: auth_method_id } = this.modelFor(
'scopes.scope.auth-methods.auth-method'
);
2020-09-14 15:58:06 -04:00
return this.store.query('account', { auth_method_id });
}
// =actions
2020-09-16 09:48:07 -04:00
/**
* Rollback changes on an account.
* @param {AccountModel} account
*/
@action
cancel(account) {
2020-09-14 17:43:07 -04:00
const { isNew } = account;
account.rollbackAttributes();
2020-09-16 14:33:04 -04:00
if (isNew)
this.transitionTo('scopes.scope.auth-methods.auth-method.accounts');
}
/**
* Save an account in current scope.
* @param {AccountModel} account
*/
@action
@loading
@notifyError(({ message }) => message)
2020-11-16 15:08:59 -05:00
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
async save(account, password) {
2020-09-14 17:43:07 -04:00
const { isNew } = account;
const adapterOptions = {};
2020-09-16 14:33:04 -04:00
if (isNew) {
adapterOptions.password = password;
}
await account.save({ adapterOptions });
await this.transitionTo(
'scopes.scope.auth-methods.auth-method.accounts.account',
account
);
this.refresh();
}
2020-09-14 17:12:51 -04:00
/**
* 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.replaceWith('scopes.scope.auth-methods.auth-method.accounts');
this.refresh();
2020-09-14 17:12:51 -04:00
}
2020-09-14 15:58:06 -04:00
}