2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
This controller supports the interface for listing users in the admin section.
|
|
|
|
|
2013-05-07 11:15:28 -04:00
|
|
|
@class AdminUsersListController
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Ember.ArrayController
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-05-07 11:15:28 -04:00
|
|
|
**/
|
2014-07-22 23:20:45 -04:00
|
|
|
export default Ember.ArrayController.extend(Discourse.Presence, {
|
2013-02-22 15:41:12 -05:00
|
|
|
username: null,
|
|
|
|
query: null,
|
|
|
|
selectAll: false,
|
|
|
|
content: null,
|
2013-04-23 10:29:18 -04:00
|
|
|
loading: false,
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2014-09-11 16:30:47 -04:00
|
|
|
mustApproveUsers: Discourse.computed.setting('must_approve_users'),
|
2013-07-15 11:28:41 -04:00
|
|
|
queryNew: Em.computed.equal('query', 'new'),
|
|
|
|
queryPending: Em.computed.equal('query', 'pending'),
|
|
|
|
queryHasApproval: Em.computed.or('queryNew', 'queryPending'),
|
|
|
|
|
2014-10-29 17:08:41 -04:00
|
|
|
searchHint: function() { return I18n.t("search_hint"); }.property(),
|
2014-10-07 06:05:38 -04:00
|
|
|
|
2013-02-21 12:58:21 -05:00
|
|
|
/**
|
2013-02-22 15:41:12 -05:00
|
|
|
Triggered when the selectAll property is changed
|
|
|
|
|
|
|
|
@event selectAll
|
|
|
|
**/
|
2013-05-14 12:03:15 -04:00
|
|
|
selectAllChanged: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
var _this = this;
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(this.get('content'),function(user) {
|
2013-02-22 15:41:12 -05:00
|
|
|
user.set('selected', _this.get('selectAll'));
|
|
|
|
});
|
2013-05-14 12:03:15 -04:00
|
|
|
}.observes('selectAll'),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Triggered when the username filter is changed
|
|
|
|
|
|
|
|
@event filterUsers
|
|
|
|
**/
|
|
|
|
filterUsers: Discourse.debounce(function() {
|
|
|
|
this.refreshUsers();
|
|
|
|
}, 250).observes('username'),
|
|
|
|
|
|
|
|
/**
|
|
|
|
Triggered when the order of the users list is changed
|
|
|
|
|
|
|
|
@event orderChanged
|
|
|
|
**/
|
2013-05-14 12:03:15 -04:00
|
|
|
orderChanged: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
this.refreshUsers();
|
2013-05-14 12:03:15 -04:00
|
|
|
}.observes('query'),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2013-04-23 10:29:18 -04:00
|
|
|
/**
|
|
|
|
The title of the user list, based on which query was performed.
|
|
|
|
|
|
|
|
@property title
|
|
|
|
**/
|
|
|
|
title: function() {
|
2013-07-08 19:32:16 -04:00
|
|
|
return I18n.t('admin.users.titles.' + this.get('query'));
|
2013-04-23 10:29:18 -04:00
|
|
|
}.property('query'),
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Do we want to show the approval controls?
|
|
|
|
|
|
|
|
@property showApproval
|
|
|
|
**/
|
2013-05-14 12:03:15 -04:00
|
|
|
showApproval: function() {
|
2013-07-15 11:28:41 -04:00
|
|
|
return Discourse.SiteSettings.must_approve_users && this.get('queryHasApproval');
|
|
|
|
}.property('queryPending'),
|
2013-02-21 12:54:40 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
How many users are currently selected
|
2013-02-21 14:42:48 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
@property selectedCount
|
|
|
|
**/
|
2013-05-14 12:03:15 -04:00
|
|
|
selectedCount: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
if (this.blank('content')) return 0;
|
|
|
|
return this.get('content').filterProperty('selected').length;
|
2013-05-14 12:03:15 -04:00
|
|
|
}.property('content.@each.selected'),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Do we have any selected users?
|
|
|
|
|
|
|
|
@property hasSelection
|
|
|
|
**/
|
2013-07-11 19:35:52 -04:00
|
|
|
hasSelection: Em.computed.gt('selectedCount', 0),
|
2013-02-22 15:41:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Refresh the current list of users.
|
|
|
|
|
|
|
|
@method refreshUsers
|
|
|
|
**/
|
2014-11-03 06:46:08 -05:00
|
|
|
refreshUsers: function(showEmails) {
|
2013-05-07 11:15:28 -04:00
|
|
|
var adminUsersListController = this;
|
|
|
|
adminUsersListController.set('loading', true);
|
|
|
|
|
2014-11-03 06:46:08 -05:00
|
|
|
Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username'), show_emails: showEmails }).then(function (result) {
|
2013-05-07 11:15:28 -04:00
|
|
|
adminUsersListController.set('content', result);
|
|
|
|
adminUsersListController.set('loading', false);
|
2013-06-21 14:06:20 -04:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Show the list of users.
|
|
|
|
|
|
|
|
@method show
|
|
|
|
**/
|
|
|
|
show: function(term) {
|
|
|
|
if (this.get('query') === term) {
|
2013-02-21 12:58:21 -05:00
|
|
|
this.refreshUsers();
|
2013-02-22 15:41:12 -05:00
|
|
|
return;
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
this.set('query', term);
|
|
|
|
},
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Approve all the currently selected users.
|
|
|
|
|
|
|
|
@method approveUsers
|
|
|
|
**/
|
|
|
|
approveUsers: function() {
|
|
|
|
Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
|
2013-06-05 11:57:25 -04:00
|
|
|
this.refreshUsers();
|
2013-08-16 11:42:24 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reject all the currently selected users.
|
|
|
|
|
|
|
|
@method rejectUsers
|
|
|
|
**/
|
|
|
|
rejectUsers: function() {
|
|
|
|
var controller = this;
|
|
|
|
Discourse.AdminUser.bulkReject(this.get('content').filterProperty('selected')).then(function(result){
|
|
|
|
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-02-20 12:29:40 -05:00
|
|
|
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age});
|
2013-08-16 11:42:24 -04:00
|
|
|
}
|
|
|
|
bootbox.alert(message);
|
|
|
|
controller.refreshUsers();
|
|
|
|
});
|
2014-11-03 06:46:08 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
showEmails: function() {
|
|
|
|
this.refreshUsers(true);
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
2013-05-07 11:15:28 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|