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

99 lines
2.5 KiB
JavaScript
Raw Normal View History

import Route from '@ember/routing/route';
2021-11-09 10:29:49 -08:00
import { action } from '@ember/object';
2021-11-10 07:32:40 -08:00
import { inject as service } from '@ember/service';
2022-01-03 09:28:24 -05:00
import { loading } from 'ember-loading';
2021-11-10 07:32:40 -08:00
import { confirm } from 'core/decorators/confirm';
2021-11-09 12:01:30 -08:00
import { notifySuccess, notifyError } from 'core/decorators/notify';
2021-11-08 11:16:32 -08:00
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route {
2021-11-09 12:01:30 -08:00
// =services
2021-11-10 09:07:17 -08:00
@service intl;
2021-11-09 12:01:30 -08:00
@service notify;
2021-11-10 09:07:17 -08:00
@service can;
@service router;
2021-11-10 09:07:17 -08:00
//=methods
2021-11-08 11:16:32 -08:00
/**
*
* @returns {Promise{[ManagedGroupsModel]}}
*/
2022-01-14 16:56:59 -05:00
async model() {
2021-11-08 11:16:32 -08:00
const authMethod = this.modelFor('scopes.scope.auth-methods.auth-method');
const { id: auth_method_id } = authMethod;
2021-11-10 14:07:19 -08:00
const canListManagedGroups = this.can.can('list collection', authMethod, {
collection: 'managed-groups',
});
2022-01-14 16:56:59 -05:00
let managedGroups;
2021-11-10 14:07:19 -08:00
if (canListManagedGroups) {
2022-01-14 16:56:59 -05:00
managedGroups = await this.store.query('managed-group', {
auth_method_id,
});
2021-11-10 14:07:19 -08:00
}
2022-01-14 16:56:59 -05:00
return {
authMethod,
managedGroups,
};
2021-11-08 11:16:32 -08:00
}
2021-11-09 10:29:49 -08:00
// =actions
/**
* Rollback changes on a managed group.
* @param {ManagedGroupModel} managedGroup
*/
@action
cancel(managedGroup) {
const { isNew } = managedGroup;
managedGroup.rollbackAttributes();
if (isNew) {
this.router.transitionTo(
'scopes.scope.auth-methods.auth-method.managed-groups'
);
2021-11-09 10:29:49 -08:00
}
}
2021-11-09 12:01:30 -08:00
2021-11-10 09:07:17 -08:00
/**
* Save a managed group in current scope.
* @param {ManagedGroupModel} managedGroup
*/
2021-11-10 07:32:40 -08:00
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
async save(managedGroup) {
await managedGroup.save();
2021-11-11 17:58:08 -05:00
if (this.can.can('read model', managedGroup)) {
await this.router.transitionTo(
2021-11-11 17:58:08 -05:00
'scopes.scope.auth-methods.auth-method.managed-groups.managed-group',
managedGroup
);
} else {
await this.router.transitionTo(
2021-11-11 17:58:08 -05:00
'scopes.scope.auth-methods.auth-method.managed-groups'
);
}
2021-11-10 07:32:40 -08:00
this.refresh();
}
2021-11-09 12:01:30 -08:00
/**
* Delete a managed group in current scope and redirect to index
* @param {ManagedGroupModel} managed group
*/
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
2022-01-14 16:56:59 -05:00
async deleteManagedGroup(managedGroup) {
2021-11-09 12:01:30 -08:00
await managedGroup.destroyRecord();
await this.router.replaceWith(
2021-11-09 12:01:30 -08:00
'scopes.scope.auth-methods.auth-method.managed-groups'
);
this.refresh();
}
2021-11-08 11:16:32 -08:00
}