2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action, computed} from '@ember/object';
|
|
|
|
import {alias, filterBy, sort} from '@ember/object/computed';
|
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-18 14:27:42 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class IndexController extends Controller {
|
|
|
|
@service
|
|
|
|
session;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@service
|
|
|
|
store;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
showInviteUserModal = false;
|
|
|
|
showResetAllPasswordsModal = false;
|
|
|
|
inviteOrder = null;
|
|
|
|
userOrder = null;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
|
|
|
init() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.init(...arguments);
|
2021-10-18 14:27:42 +03:00
|
|
|
this.inviteOrder = ['email'];
|
|
|
|
this.userOrder = ['name', 'email'];
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@alias('model')
|
|
|
|
currentUser;
|
|
|
|
|
|
|
|
@sort('filteredInvites', 'inviteOrder')
|
|
|
|
sortedInvites;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@sort('activeUsers', 'userOrder')
|
|
|
|
sortedActiveUsers;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@sort('suspendedUsers', 'userOrder')
|
|
|
|
sortedSuspendedUsers;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@filterBy('invites', 'isNew', false)
|
|
|
|
filteredInvites;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed
|
|
|
|
get invites() {
|
2021-10-18 14:27:42 +03:00
|
|
|
return this.store.peekAll('invite');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed
|
|
|
|
get allUsers() {
|
2021-10-18 14:27:42 +03:00
|
|
|
return this.store.peekAll('user');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('allUsers.@each.status')
|
|
|
|
get activeUsers() {
|
2021-10-18 14:27:42 +03:00
|
|
|
return this.allUsers.filter((user) => {
|
|
|
|
return user.status !== 'inactive';
|
|
|
|
});
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('allUsers.@each.status')
|
|
|
|
get suspendedUsers() {
|
2021-10-18 14:27:42 +03:00
|
|
|
return this.allUsers.filter((user) => {
|
|
|
|
return user.status === 'inactive';
|
|
|
|
});
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleInviteUserModal() {
|
|
|
|
this.toggleProperty('showInviteUserModal');
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleResetAllPasswordsModal() {
|
|
|
|
this.toggleProperty('showResetAllPasswordsModal');
|
|
|
|
}
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@task(function* () {
|
2021-10-18 14:27:42 +03:00
|
|
|
let users = this.fetchUsers.perform();
|
|
|
|
let invites = this.fetchInvites.perform();
|
|
|
|
|
|
|
|
try {
|
|
|
|
yield RSVP.all([users, invites]);
|
|
|
|
} catch (error) {
|
|
|
|
this.send('error', error);
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
|
|
|
backgroundUpdate;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@task(function* () {
|
2021-10-18 14:27:42 +03:00
|
|
|
yield this.store.query('user', {limit: 'all'});
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
|
|
|
fetchUsers;
|
2021-10-18 14:27:42 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@task(function* () {
|
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-02-01 12:34:03 +03:00
|
|
|
fetchInvites;
|
|
|
|
}
|