2018-01-11 01:57:43 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
2017-08-22 10:53:26 +03:00
|
|
|
import Controller from '@ember/controller';
|
2019-01-14 17:50:30 +03:00
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import {alias, sort} from '@ember/object/computed';
|
2018-04-30 15:54:09 +03:00
|
|
|
import {computed} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2019-01-14 17:50:30 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2014-07-20 20:42:03 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Controller.extend({
|
2017-11-24 21:53:19 +03:00
|
|
|
session: service(),
|
2019-01-14 17:50:30 +03:00
|
|
|
store: service(),
|
2017-11-24 21:53:19 +03:00
|
|
|
|
2015-11-18 13:50:48 +03:00
|
|
|
showInviteUserModal: false,
|
2021-06-07 12:05:46 +03:00
|
|
|
showResetAllPasswordsModal: false,
|
2014-07-02 07:44:39 +04:00
|
|
|
|
2017-11-24 21:53:19 +03:00
|
|
|
inviteOrder: null,
|
|
|
|
userOrder: null,
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2018-03-19 14:54:54 +03:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.inviteOrder = ['email'];
|
|
|
|
this.userOrder = ['name', 'email'];
|
|
|
|
},
|
|
|
|
|
2019-01-14 17:50:30 +03:00
|
|
|
currentUser: alias('model'),
|
|
|
|
|
2018-04-30 15:54:09 +03:00
|
|
|
sortedInvites: sort('filteredInvites', 'inviteOrder'),
|
2017-03-08 21:21:35 +03:00
|
|
|
sortedActiveUsers: sort('activeUsers', 'userOrder'),
|
|
|
|
sortedSuspendedUsers: sort('suspendedUsers', 'userOrder'),
|
|
|
|
|
2020-10-23 11:58:55 +03:00
|
|
|
filteredInvites: computed.filterBy('invites', 'isNew', false),
|
|
|
|
|
2019-01-14 17:50:30 +03:00
|
|
|
invites: computed(function () {
|
|
|
|
return this.store.peekAll('invite');
|
|
|
|
}),
|
|
|
|
|
|
|
|
allUsers: computed(function () {
|
|
|
|
return this.store.peekAll('user');
|
|
|
|
}),
|
|
|
|
|
|
|
|
activeUsers: computed('allUsers.@each.status', function () {
|
|
|
|
return this.allUsers.filter((user) => {
|
|
|
|
return user.status !== 'inactive';
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
suspendedUsers: computed('allUsers.@each.status', function () {
|
|
|
|
return this.allUsers.filter((user) => {
|
|
|
|
return user.status === 'inactive';
|
|
|
|
});
|
2018-04-30 15:54:09 +03:00
|
|
|
}),
|
|
|
|
|
2015-11-18 13:50:48 +03:00
|
|
|
actions: {
|
|
|
|
toggleInviteUserModal() {
|
|
|
|
this.toggleProperty('showInviteUserModal');
|
2021-06-07 12:05:46 +03:00
|
|
|
},
|
|
|
|
toggleResetAllPasswordsModal() {
|
|
|
|
this.toggleProperty('showResetAllPasswordsModal');
|
2015-11-18 13:50:48 +03:00
|
|
|
}
|
2019-01-14 17:50:30 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
backgroundUpdate: task(function* () {
|
|
|
|
let users = this.fetchUsers.perform();
|
|
|
|
let invites = this.fetchInvites.perform();
|
|
|
|
|
|
|
|
try {
|
2019-01-14 20:01:30 +03:00
|
|
|
yield RSVP.all([users, invites]);
|
2019-01-14 17:50:30 +03:00
|
|
|
} catch (error) {
|
|
|
|
this.send('error', error);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
fetchUsers: task(function* () {
|
|
|
|
yield this.store.query('user', {limit: 'all'});
|
|
|
|
}),
|
|
|
|
|
|
|
|
fetchInvites: task(function* () {
|
|
|
|
if (this.currentUser.isAuthorOrContributor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-14 20:01:30 +03:00
|
|
|
// ensure roles are loaded before invites. Invites do not have embedded
|
2020-01-10 16:53:58 +03:00
|
|
|
// 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'});
|
2019-01-14 17:50:30 +03:00
|
|
|
|
2019-01-14 20:01:30 +03:00
|
|
|
return yield this.store.query('invite', {limit: 'all'});
|
2019-01-14 17:50:30 +03:00
|
|
|
})
|
2014-07-02 07:44:39 +04:00
|
|
|
});
|