55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import Route from '@ember/routing/route';
|
|
import { inject as service } from '@ember/service';
|
|
import { action } from '@ember/object';
|
|
import { hash } from 'rsvp';
|
|
import { loading } from 'ember-loading';
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
|
|
|
export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
|
|
// =services
|
|
|
|
@service intl;
|
|
@service notify;
|
|
@service router;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Returns the current role, all users, and all groups
|
|
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
|
|
*/
|
|
model() {
|
|
const role = this.modelFor('scopes.scope.roles.role');
|
|
const { scopeID: scope_id } = role;
|
|
return hash({
|
|
role,
|
|
users: this.store.query('user', { scope_id }),
|
|
groups: this.store.query('group', { scope_id }),
|
|
});
|
|
}
|
|
|
|
// =actions
|
|
|
|
/**
|
|
* Save principal IDs to current role via the API.
|
|
* @param {RoleModel} role
|
|
* @param {[string]} principalIDs
|
|
*/
|
|
@action
|
|
@loading
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
@notifySuccess('notifications.add-success')
|
|
async addPrincipals(role, principalIDs) {
|
|
await role.addPrincipals(principalIDs);
|
|
this.router.replaceWith('scopes.scope.roles.role.principals');
|
|
}
|
|
|
|
/**
|
|
* Redirect to role principals as if nothing ever happened.
|
|
*/
|
|
@action
|
|
cancel() {
|
|
this.router.replaceWith('scopes.scope.roles.role.principals');
|
|
}
|
|
}
|