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

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-08-12 15:43:34 -04:00
import Route from '@ember/routing/route';
2020-08-12 17:16:41 -04:00
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
2020-08-12 15:43:34 -04:00
export default class ScopesScopeAuthMethodsRoute extends Route {
2020-08-12 17:16:41 -04:00
// =services
@service intl;
@service notify;
@service session;
2020-08-12 17:16:41 -04:00
2020-08-12 15:43:34 -04:00
// =methods
/**
* If arriving here unauthenticated, redirect to index for further processing.
*/
beforeModel() {
if (!this.session.isAuthenticated) this.transitionTo('index');
}
2020-08-12 15:43:34 -04:00
/**
* Load all auth-methods under current scope
* @return {Promise[AuthMethodModel]}
*/
async model() {
2020-09-09 12:24:01 -04:00
const { id: scope_id } = this.modelFor('scopes.scope');
return this.store.query('auth-method', { scope_id });
2020-08-12 15:43:34 -04:00
}
2020-08-12 17:16:41 -04:00
// =actions
/**
* Rollback changes to an auth-method.
* @param {AuthMethodModel} authMethod
*/
@action
cancel(authMethod) {
const { isNew } = authMethod;
authMethod.rollbackAttributes();
if (isNew) this.transitionTo('scopes.scope.auth-methods');
}
/**
* Save an auth-method in current scope.
* @param {AuthMethodModel} authMethod
*/
@action
@loading
@notifyError(({ message }) => message)
2020-11-16 15:08:59 -05:00
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
2020-08-12 17:16:41 -04:00
async save(authMethod) {
await authMethod.save();
await this.transitionTo(
'scopes.scope.auth-methods.auth-method',
authMethod
);
this.refresh();
2020-08-12 17:16:41 -04:00
}
/**
* Delete an auth method in current scope and redirect to index
* @param {AuthMethodModel} authMethod
*/
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(authMethod) {
await authMethod.destroyRecord();
await this.replaceWith('scopes.scope.auth-methods');
this.refresh();
}
2020-08-12 15:43:34 -04:00
}