2021-10-18 14:27:42 +03:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import RSVP from 'rsvp';
|
2022-08-30 18:35:28 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-18 14:27:42 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2022-08-30 18:35:28 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
export default class IndexController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service session;
|
|
|
|
@service store;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
@tracked showInviteUserModal = false;
|
|
|
|
@tracked showResetAllPasswordsModal = false;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
inviteOrder = ['email'];
|
|
|
|
userOrder = ['name', 'email'];
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
allInvites = this.store.peekAll('invite');
|
|
|
|
allUsers = this.store.peekAll('user');
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
get currentUser() {
|
|
|
|
return this.model;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
get invites() {
|
|
|
|
return this.allInvites
|
|
|
|
.filter(i => !i.isNew)
|
|
|
|
.sortBy(...this.inviteOrder);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
get activeUsers() {
|
2022-08-30 18:35:28 +03:00
|
|
|
return this.allUsers
|
|
|
|
.filter(u => u.status !== 'inactive')
|
|
|
|
.sortBy(...this.userOrder);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
get suspendedUsers() {
|
2022-08-30 18:35:28 +03:00
|
|
|
return this.allUsers
|
|
|
|
.filter(u => u.status === 'inactive')
|
|
|
|
.sortBy(...this.userOrder);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleInviteUserModal() {
|
2022-08-30 18:35:28 +03:00
|
|
|
this.showInviteUserModal = !this.showInviteUserModal;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleResetAllPasswordsModal() {
|
2022-08-30 18:35:28 +03:00
|
|
|
this.showResetAllPasswordsModal = !this.showResetAllPasswordsModal;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
@task
|
2022-08-30 18:41:48 +03:00
|
|
|
*backgroundUpdateTask() {
|
|
|
|
let users = this.fetchUsersTask.perform();
|
|
|
|
let invites = this.fetchInvitesTask.perform();
|
2021-10-18 14:27:42 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
yield RSVP.all([users, invites]);
|
|
|
|
} catch (error) {
|
|
|
|
this.send('error', error);
|
|
|
|
}
|
2022-08-30 18:35:28 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
@task
|
2022-08-30 18:41:48 +03:00
|
|
|
*fetchUsersTask() {
|
2021-10-18 14:27:42 +03:00
|
|
|
yield this.store.query('user', {limit: 'all'});
|
2022-08-30 18:35:28 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-08-30 18:35:28 +03:00
|
|
|
@task
|
2022-08-30 18:41:48 +03:00
|
|
|
*fetchInvitesTask() {
|
2021-10-18 14:27:42 +03:00
|
|
|
if (this.currentUser.isAuthorOrContributor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure roles are loaded before invites. Invites do not have embedded
|
|
|
|
// role records which means Ember Data will throw errors when trying to
|
|
|
|
// read the invite.role data when the role has not yet been loaded
|
|
|
|
yield this.store.query('role', {limit: 'all'});
|
|
|
|
|
|
|
|
return yield this.store.query('invite', {limit: 'all'});
|
2022-08-30 18:35:28 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|