FEATURE: delete all accounts from this IP in the IP lookup modal

This commit is contained in:
Régis Hanol 2014-11-20 19:59:20 +01:00
parent 5f4e4de02a
commit b8d806ee07
7 changed files with 67 additions and 20 deletions

View File

@ -39,6 +39,22 @@ export default Ember.Component.extend({
hide: function () { hide: function () {
this.set("show", false); this.set("show", false);
},
deleteAllOtherAccounts: function() {
var self = this;
this.setProperties({ other_accounts: null, otherAccountsLoading: true });
Discourse.ajax("/admin/users/delete-others-with-same-ip.json", {
type: "DELETE",
data: {
"ip": this.get("ip"),
"exclude": this.get("user_id"),
"order": "trust_level DESC"
}
}).then(function() {
self.send("lookup");
});
} }
} }
}); });

View File

@ -1,11 +1,11 @@
{{#if ip}} {{#if ip}}
<button class="btn" {{action "lookup"}}> <button class="btn" {{action "lookup"}}>
<span class="fa fa-globe"></span>&nbsp;{{i18n admin.user.ip_lookup}} {{fa-icon "globe"}}{{i18n admin.user.ip_lookup}}
</button> </button>
{{/if}} {{/if}}
{{#if show}} {{#if show}}
<div class="location-box"> <div class="location-box">
<a class="close" {{action "hide"}}>{{fa-icon "times"}}</a> <a class="close pull-right" {{action "hide"}}>{{fa-icon "times"}}</a>
<h4>{{i18n ip_lookup.title}}</h4> <h4>{{i18n ip_lookup.title}}</h4>
<dl> <dl>
{{#if location}} {{#if location}}
@ -37,10 +37,18 @@
{{loading-spinner size="small"}} {{loading-spinner size="small"}}
{{/if}} {{/if}}
<dt>{{i18n ip_lookup.other_accounts}}&nbsp;<strong>{{other_accounts.length}}</strong></dt> <dt>
<dd class="other-accounts"> {{i18n ip_lookup.other_accounts}}
{{#loading-spinner size="small" condition=otherAccountsLoading}} <strong>{{other_accounts.length}}</strong>
{{#if other_accounts}} {{#if other_accounts.length}}
<button class="btn btn-danger pull-right" {{action "deleteAllOtherAccounts"}}>
{{fa-icon "trash-o"}}{{i18n ip_lookup.delete_all}}
</button>
{{/if}}
</dt>
{{#loading-spinner size="small" condition=otherAccountsLoading}}
{{#if other_accounts.length}}
<dd class="other-accounts">
<table class="table table-condensed table-hover"> <table class="table table-condensed table-hover">
<thead> <thead>
<tr> <tr>
@ -63,11 +71,9 @@
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
{{else}} </dd>
{{i18n ip_lookup.no_other_accounts}} {{/if}}
{{/if}} {{/loading-spinner}}
{{/loading-spinner}}
<dd>
</dl> </dl>
</div> </div>
{{/if}} {{/if}}

View File

@ -82,16 +82,15 @@ td.flaggers td {
margin-top: -2px; margin-top: -2px;
background-color: $secondary; background-color: $secondary;
padding: 12px 12px 5px; padding: 12px 12px 5px;
.close {
float: right;
}
.other-accounts { .other-accounts {
margin: 0; margin: 5px 0 0;
max-height: 200px; max-height: 200px;
overflow: auto; overflow: auto;
width: 455px;
ul { margin: 0; } ul { margin: 0; }
li { list-style: none; } li { list-style: none; }
tr td:first-of-type { width: 130px; }
} }
} }
} }

View File

@ -264,10 +264,7 @@ class Admin::UsersController < Admin::AdminController
end end
def sync_sso def sync_sso
unless SiteSetting.enable_sso return render nothing: true, status: 404 unless SiteSetting.enable_sso
render nothing: true, status: 404
return
end
sso = DiscourseSingleSignOn.parse("sso=#{params[:sso]}&sig=#{params[:sig]}") sso = DiscourseSingleSignOn.parse("sso=#{params[:sso]}&sig=#{params[:sig]}")
user = sso.lookup_or_create_user user = sso.lookup_or_create_user
@ -275,6 +272,21 @@ class Admin::UsersController < Admin::AdminController
render_serialized(user, AdminDetailedUserSerializer, root: false) render_serialized(user, AdminDetailedUserSerializer, root: false)
end end
def delete_other_accounts_with_same_ip
params.require(:ip)
params.require(:exclude)
params.require(:order)
user_destroyer = UserDestroyer.new(current_user)
options = { delete_posts: true, block_email: true, block_urls: true, block_ip: true, delete_as_spammer: true }
AdminUserIndexQuery.new(params).find_users.each do |user|
user_destroyer.destroy(user, options) rescue nil
end
render json: success_json
end
private private
def fetch_user def fetch_user

View File

@ -279,7 +279,7 @@ en:
organisation: Organization organisation: Organization
phone: Phone phone: Phone
other_accounts: "Other accounts with this IP address:" other_accounts: "Other accounts with this IP address:"
no_other_accounts: (none) delete_all: "Delete all"
username: "username" username: "username"
trust_level: "TL" trust_level: "TL"
read_time: "read time" read_time: "read time"

View File

@ -52,6 +52,7 @@ Discourse::Application.routes.draw do
collection do collection do
get "list/:query" => "users#index" get "list/:query" => "users#index"
get "ip-info" => "users#ip_info" get "ip-info" => "users#ip_info"
delete "delete-others-with-same-ip" => "users#delete_other_accounts_with_same_ip"
put "approve-bulk" => "users#approve_bulk" put "approve-bulk" => "users#approve_bulk"
delete "reject-bulk" => "users#reject_bulk" delete "reject-bulk" => "users#reject_bulk"
end end

View File

@ -414,6 +414,19 @@ describe Admin::UsersController do
end end
context "delete_other_accounts_with_same_ip" do
it "works" do
Fabricate(:user, ip_address: "42.42.42.42")
Fabricate(:user, ip_address: "42.42.42.42")
UserDestroyer.any_instance.expects(:destroy).twice
xhr :delete, :delete_other_accounts_with_same_ip, ip: "42.42.42.42", exclude: -1, order: "trust_level DESC"
end
end
end end
it 'can sync up sso' do it 'can sync up sso' do