From a8268405403215b5d0ee163f214523c47c8364ce Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 23 Oct 2014 23:26:59 +0530 Subject: [PATCH] Moderators can search users by ip address --- config/locales/client.en.yml | 2 +- lib/admin_user_index_query.rb | 6 +++++- spec/components/admin_user_index_query_spec.rb | 15 +++------------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 7ea59463463..e76f52d99ff 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -576,7 +576,7 @@ en: created: 'Created' created_lowercase: 'created' trust_level: 'Trust Level' - search_hint: 'username' + search_hint: 'username or IP address' search_hint_admin: 'username, email or IP address' create_account: diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index 6e2e277b5ad..ac402772fcb 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -43,7 +43,11 @@ class AdminUserIndexQuery @query.where('username_lower ILIKE :filter OR email ILIKE :filter', filter: "%#{params[:filter]}%") end else - @query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%") + if params[:filter] =~ Resolv::IPv4::Regex || params[:filter] =~ Resolv::IPv6::Regex + @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:filter]) + else + @query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%") + end end end end diff --git a/spec/components/admin_user_index_query_spec.rb b/spec/components/admin_user_index_query_spec.rb index d6d5e2ea3e8..58bc92a74ee 100644 --- a/spec/components/admin_user_index_query_spec.rb +++ b/spec/components/admin_user_index_query_spec.rb @@ -140,18 +140,9 @@ describe AdminUserIndexQuery do context "by ip address fragment" do before(:each) { Fabricate(:user, ip_address: "117.207.94.9") } - context "when authenticated as a non-admin user" do - it "doesn't match the ip address" do - query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" }) - expect(query.find_users.count()).to eq(0) - end - end - - context "when authenticated as an admin user" do - it "matches the ip address" do - query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9", admin: true }) - expect(query.find_users.count()).to eq(1) - end + it "matches the ip address" do + query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" }) + expect(query.find_users.count()).to eq(1) end end