2020-09-01 17:31:22 -04:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
2020-09-02 16:20:12 -04:00
|
|
|
import { hash, all } from 'rsvp';
|
2022-01-03 09:28:24 -05:00
|
|
|
import { loading } from 'ember-loading';
|
2020-11-18 13:19:46 -05:00
|
|
|
import { confirm } from 'core/decorators/confirm';
|
2020-11-18 13:59:11 -05:00
|
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
2020-09-01 17:31:22 -04:00
|
|
|
|
|
|
|
|
export default class ScopesScopeGroupsGroupMembersRoute extends Route {
|
|
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service intl;
|
|
|
|
|
@service notify;
|
|
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns users associated with this group.
|
2020-09-02 16:20:12 -04:00
|
|
|
* @return {Promise{group: GroupModel, members: Promise{[UserModel]}}}
|
2020-09-01 17:31:22 -04:00
|
|
|
*/
|
2020-09-02 16:45:43 -04:00
|
|
|
model() {
|
2020-09-01 17:31:22 -04:00
|
|
|
const { id: scopeID } = this.modelFor('scopes.scope');
|
|
|
|
|
const group = this.modelFor('scopes.scope.groups.group');
|
2020-09-02 16:20:12 -04:00
|
|
|
return hash({
|
|
|
|
|
group,
|
2020-09-16 14:33:04 -04:00
|
|
|
members: all(
|
|
|
|
|
group.member_ids.map((id) =>
|
|
|
|
|
this.store.findRecord('user', id, { adapterOptions: { scopeID } })
|
|
|
|
|
)
|
|
|
|
|
),
|
2020-09-02 16:20:12 -04:00
|
|
|
});
|
2020-09-01 17:31:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =actions
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a member from the current role and redirect to members index.
|
|
|
|
|
* @param {GroupModel} group
|
|
|
|
|
* @param {UserModel} member
|
|
|
|
|
*/
|
|
|
|
|
@action
|
2020-09-25 18:09:56 -04:00
|
|
|
@loading
|
2020-09-30 18:50:12 -04:00
|
|
|
@confirm('questions.remove-confirm')
|
2020-10-08 18:01:27 -04:00
|
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
|
|
|
@notifySuccess('notifications.remove-success')
|
2020-09-01 17:31:22 -04:00
|
|
|
async removeMember(group, member) {
|
2020-10-08 18:01:27 -04:00
|
|
|
await group.removeMember(member.id);
|
|
|
|
|
this.refresh();
|
2020-09-01 17:31:22 -04:00
|
|
|
}
|
|
|
|
|
}
|