Add reject option to pending users page
This commit is contained in:
parent
30caa0d0b0
commit
b6285b85d2
|
@ -119,6 +119,24 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
|
||||||
approveUsers: function() {
|
approveUsers: function() {
|
||||||
Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
|
Discourse.AdminUser.bulkApprove(this.get('content').filterProperty('selected'));
|
||||||
this.refreshUsers();
|
this.refreshUsers();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
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});
|
||||||
|
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_age});
|
||||||
|
}
|
||||||
|
bootbox.alert(message);
|
||||||
|
controller.refreshUsers();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -343,6 +343,21 @@ Discourse.AdminUser.reopenClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
bulkReject: function(users) {
|
||||||
|
_.each(users, function(user){
|
||||||
|
user.set('can_approve', false);
|
||||||
|
user.set('selected', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Discourse.ajax("/admin/users/reject-bulk", {
|
||||||
|
type: 'DELETE',
|
||||||
|
data: {
|
||||||
|
users: users.map(function(u) { return u.id; }),
|
||||||
|
context: window.location.pathname
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
find: function(username) {
|
find: function(username) {
|
||||||
return Discourse.ajax("/admin/users/" + username).then(function (result) {
|
return Discourse.ajax("/admin/users/" + username).then(function (result) {
|
||||||
result.loadedDetails = true;
|
result.loadedDetails = true;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
{{#if hasSelection}}
|
{{#if hasSelection}}
|
||||||
<div id='selected-controls'>
|
<div id='selected-controls'>
|
||||||
<button {{action approveUsers}} class='btn'>{{countI18n admin.users.approved_selected countBinding="selectedCount"}}</button>
|
<button {{action approveUsers}} class='btn'>{{countI18n admin.users.approved_selected countBinding="selectedCount"}}</button>
|
||||||
|
<button {{action rejectUsers}} class='btn btn-danger'>{{countI18n admin.users.reject_selected countBinding="selectedCount"}}</button>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,15 @@ class Admin::UsersController < Admin::AdminController
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reject_bulk
|
||||||
|
d = UserDestroyer.new(current_user)
|
||||||
|
success_count = 0
|
||||||
|
User.where(id: params[:users]).each do |u|
|
||||||
|
success_count += 1 if guardian.can_delete_user?(u) and d.destroy(u, params.slice(:context)) rescue UserDestroyer::PostsExistError
|
||||||
|
end
|
||||||
|
render json: {success: success_count, failed: (params[:users].try(:size) || 0) - success_count}
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
user = User.where(id: params[:id]).first
|
user = User.where(id: params[:id]).first
|
||||||
guardian.ensure_can_delete_user!(user)
|
guardian.ensure_can_delete_user!(user)
|
||||||
|
|
|
@ -1233,6 +1233,9 @@ en:
|
||||||
approved_selected:
|
approved_selected:
|
||||||
one: "approve user"
|
one: "approve user"
|
||||||
other: "approve users ({{count}})"
|
other: "approve users ({{count}})"
|
||||||
|
reject_selected:
|
||||||
|
one: "reject user"
|
||||||
|
other: "reject users ({{count}})"
|
||||||
titles:
|
titles:
|
||||||
active: 'Active Users'
|
active: 'Active Users'
|
||||||
new: 'New Users'
|
new: 'New Users'
|
||||||
|
@ -1246,6 +1249,12 @@ en:
|
||||||
moderators: 'Moderators'
|
moderators: 'Moderators'
|
||||||
blocked: 'Blocked Users'
|
blocked: 'Blocked Users'
|
||||||
banned: 'Banned Users'
|
banned: 'Banned Users'
|
||||||
|
reject_successful:
|
||||||
|
one: "Successfully rejected 1 user."
|
||||||
|
other: "Successfully rejected %{count} users."
|
||||||
|
reject_failures:
|
||||||
|
one: "Failed to reject 1 user."
|
||||||
|
other: "Failed to reject %{count} users."
|
||||||
|
|
||||||
user:
|
user:
|
||||||
ban_failed: "Something went wrong banning this user {{error}}"
|
ban_failed: "Something went wrong banning this user {{error}}"
|
||||||
|
|
|
@ -36,6 +36,7 @@ Discourse::Application.routes.draw do
|
||||||
collection do
|
collection do
|
||||||
get 'list/:query' => 'users#index'
|
get 'list/:query' => 'users#index'
|
||||||
put 'approve-bulk' => 'users#approve_bulk'
|
put 'approve-bulk' => 'users#approve_bulk'
|
||||||
|
delete 'reject-bulk' => 'users#reject_bulk'
|
||||||
end
|
end
|
||||||
put 'ban'
|
put 'ban'
|
||||||
put 'delete_all_posts'
|
put 'delete_all_posts'
|
||||||
|
|
|
@ -196,6 +196,57 @@ describe Admin::UsersController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '.reject_bulk' do
|
||||||
|
let(:reject_me) { Fabricate(:user) }
|
||||||
|
let(:reject_me_too) { Fabricate(:user) }
|
||||||
|
|
||||||
|
it 'does nothing without users' do
|
||||||
|
UserDestroyer.any_instance.expects(:destroy).never
|
||||||
|
xhr :delete, :reject_bulk
|
||||||
|
end
|
||||||
|
|
||||||
|
it "won't delete users if not allowed" do
|
||||||
|
Guardian.any_instance.stubs(:can_delete_user?).returns(false)
|
||||||
|
UserDestroyer.any_instance.expects(:destroy).never
|
||||||
|
xhr :delete, :reject_bulk, users: [reject_me.id]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports successes" do
|
||||||
|
Guardian.any_instance.stubs(:can_delete_user?).returns(true)
|
||||||
|
UserDestroyer.any_instance.stubs(:destroy).returns(true)
|
||||||
|
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
|
||||||
|
response.should be_success
|
||||||
|
json = ::JSON.parse(response.body)
|
||||||
|
json['success'].to_i.should == 2
|
||||||
|
json['failed'].to_i.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'failures' do
|
||||||
|
before do
|
||||||
|
Guardian.any_instance.stubs(:can_delete_user?).returns(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can handle some successes and some failures' do
|
||||||
|
UserDestroyer.any_instance.stubs(:destroy).with(reject_me, anything).returns(false)
|
||||||
|
UserDestroyer.any_instance.stubs(:destroy).with(reject_me_too, anything).returns(true)
|
||||||
|
xhr :delete, :reject_bulk, users: [reject_me.id, reject_me_too.id]
|
||||||
|
response.should be_success
|
||||||
|
json = ::JSON.parse(response.body)
|
||||||
|
json['success'].to_i.should == 1
|
||||||
|
json['failed'].to_i.should == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'reports failure due to a user still having posts' do
|
||||||
|
UserDestroyer.any_instance.expects(:destroy).with(reject_me, anything).raises(UserDestroyer::PostsExistError)
|
||||||
|
xhr :delete, :reject_bulk, users: [reject_me.id]
|
||||||
|
response.should be_success
|
||||||
|
json = ::JSON.parse(response.body)
|
||||||
|
json['success'].to_i.should == 0
|
||||||
|
json['failed'].to_i.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '.destroy' do
|
context '.destroy' do
|
||||||
before do
|
before do
|
||||||
@delete_me = Fabricate(:user)
|
@delete_me = Fabricate(:user)
|
||||||
|
|
Loading…
Reference in New Issue