2015-08-11 05:11:27 +08:00
|
|
|
import debounce from 'discourse/lib/debounce';
|
2015-08-08 03:08:27 +08:00
|
|
|
import { i18n } from 'discourse/lib/computed';
|
2015-11-21 09:27:06 +08:00
|
|
|
import AdminUser from 'admin/models/admin-user';
|
2017-02-20 21:42:33 +08:00
|
|
|
import { observes } from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
export default Ember.Controller.extend({
|
2014-11-27 02:05:49 +08:00
|
|
|
query: null,
|
2017-02-20 21:42:33 +08:00
|
|
|
queryParams: ['order', 'ascending'],
|
2017-04-05 16:27:34 +08:00
|
|
|
order: null,
|
2017-02-20 21:42:33 +08:00
|
|
|
ascending: null,
|
2014-11-27 02:05:49 +08:00
|
|
|
showEmails: false,
|
|
|
|
refreshing: false,
|
|
|
|
listFilter: null,
|
|
|
|
selectAll: false,
|
|
|
|
|
|
|
|
queryNew: Em.computed.equal('query', 'new'),
|
|
|
|
queryPending: Em.computed.equal('query', 'pending'),
|
|
|
|
queryHasApproval: Em.computed.or('queryNew', 'queryPending'),
|
|
|
|
showApproval: Em.computed.and('siteSettings.must_approve_users', 'queryHasApproval'),
|
2015-08-08 03:08:27 +08:00
|
|
|
searchHint: i18n('search_hint'),
|
2014-11-27 02:05:49 +08:00
|
|
|
hasSelection: Em.computed.gt('selectedCount', 0),
|
|
|
|
|
|
|
|
selectedCount: function() {
|
|
|
|
var model = this.get('model');
|
|
|
|
if (!model || !model.length) return 0;
|
2016-10-27 03:44:36 +08:00
|
|
|
return model.filterBy('selected').length;
|
2014-11-27 02:05:49 +08:00
|
|
|
}.property('model.@each.selected'),
|
|
|
|
|
|
|
|
selectAllChanged: function() {
|
|
|
|
var val = this.get('selectAll');
|
|
|
|
this.get('model').forEach(function(user) {
|
|
|
|
if (user.get('can_approve')) {
|
|
|
|
user.set('selected', val);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}.observes('selectAll'),
|
|
|
|
|
|
|
|
title: function() {
|
|
|
|
return I18n.t('admin.users.titles.' + this.get('query'));
|
|
|
|
}.property('query'),
|
|
|
|
|
2015-08-11 05:11:27 +08:00
|
|
|
_filterUsers: debounce(function() {
|
2014-11-27 02:05:49 +08:00
|
|
|
this._refreshUsers();
|
|
|
|
}, 250).observes('listFilter'),
|
|
|
|
|
2017-02-20 21:42:33 +08:00
|
|
|
|
|
|
|
@observes('order', 'ascending')
|
2014-11-27 02:05:49 +08:00
|
|
|
_refreshUsers: function() {
|
|
|
|
this.set('refreshing', true);
|
|
|
|
|
2017-02-20 21:42:33 +08:00
|
|
|
AdminUser.findAll(this.get('query'), { filter: this.get('listFilter'), show_emails: this.get('showEmails'), order: this.get('order'), ascending: this.get('ascending') }).then( (result) => {
|
|
|
|
this.set('model', result);
|
|
|
|
}).finally( () => {
|
|
|
|
this.set('refreshing', false);
|
2014-11-27 02:05:49 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
approveUsers: function() {
|
2016-10-27 03:44:36 +08:00
|
|
|
AdminUser.bulkApprove(this.get('model').filterBy('selected'));
|
2014-11-27 02:05:49 +08:00
|
|
|
this._refreshUsers();
|
|
|
|
},
|
|
|
|
|
|
|
|
rejectUsers: function() {
|
2014-12-16 03:41:08 +08:00
|
|
|
var maxPostAge = this.siteSettings.delete_user_max_post_age;
|
2014-11-27 02:05:49 +08:00
|
|
|
var controller = this;
|
2016-10-27 03:44:36 +08:00
|
|
|
AdminUser.bulkReject(this.get('model').filterBy('selected')).then(function(result){
|
2014-11-27 02:05:49 +08:00
|
|
|
var message = I18n.t("admin.users.reject_successful", {count: result.success});
|
|
|
|
if (result.failed > 0) {
|
|
|
|
message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed});
|
2014-12-16 03:41:08 +08:00
|
|
|
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: maxPostAge});
|
2014-11-27 02:05:49 +08:00
|
|
|
}
|
|
|
|
bootbox.alert(message);
|
|
|
|
controller._refreshUsers();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showEmails: function() {
|
|
|
|
this.set('showEmails', true);
|
|
|
|
this._refreshUsers(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|