mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
bc185665a4
refs https://github.com/TryGhost/Ghost/issues/14101 refs https://github.com/TryGhost/Team/issues/1734 - use of the helper was generating deprecation warnings when building Admin - removed the single usage in favor of using `{{perform}}` directly on a controller task property as there was no need to go via the route - changed naming of task properties to include a `...Task` suffix so it's clear when dealing with a task object
84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import RSVP from 'rsvp';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class IndexController extends Controller {
|
|
@service session;
|
|
@service store;
|
|
|
|
@tracked showInviteUserModal = false;
|
|
@tracked showResetAllPasswordsModal = false;
|
|
|
|
inviteOrder = ['email'];
|
|
userOrder = ['name', 'email'];
|
|
|
|
allInvites = this.store.peekAll('invite');
|
|
allUsers = this.store.peekAll('user');
|
|
|
|
get currentUser() {
|
|
return this.model;
|
|
}
|
|
|
|
get invites() {
|
|
return this.allInvites
|
|
.filter(i => !i.isNew)
|
|
.sortBy(...this.inviteOrder);
|
|
}
|
|
|
|
get activeUsers() {
|
|
return this.allUsers
|
|
.filter(u => u.status !== 'inactive')
|
|
.sortBy(...this.userOrder);
|
|
}
|
|
|
|
get suspendedUsers() {
|
|
return this.allUsers
|
|
.filter(u => u.status === 'inactive')
|
|
.sortBy(...this.userOrder);
|
|
}
|
|
|
|
@action
|
|
toggleInviteUserModal() {
|
|
this.showInviteUserModal = !this.showInviteUserModal;
|
|
}
|
|
|
|
@action
|
|
toggleResetAllPasswordsModal() {
|
|
this.showResetAllPasswordsModal = !this.showResetAllPasswordsModal;
|
|
}
|
|
|
|
@task
|
|
*backgroundUpdateTask() {
|
|
let users = this.fetchUsersTask.perform();
|
|
let invites = this.fetchInvitesTask.perform();
|
|
|
|
try {
|
|
yield RSVP.all([users, invites]);
|
|
} catch (error) {
|
|
this.send('error', error);
|
|
}
|
|
}
|
|
|
|
@task
|
|
*fetchUsersTask() {
|
|
yield this.store.query('user', {limit: 'all'});
|
|
}
|
|
|
|
@task
|
|
*fetchInvitesTask() {
|
|
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'});
|
|
}
|
|
}
|