FEATURE: search by ip address on admin user list page

This commit is contained in:
Arpit Jalan 2014-10-23 07:58:01 +05:30
parent de415b804c
commit 1035df46bf
3 changed files with 25 additions and 3 deletions

View File

@ -577,7 +577,7 @@ en:
created_lowercase: 'created'
trust_level: 'Trust Level'
search_hint: 'username'
search_hint_admin: 'username or email'
search_hint_admin: 'username, email or IP address'
create_account:
title: "Create New Account"

View File

@ -37,7 +37,11 @@ class AdminUserIndexQuery
def filter_by_search
if params[:filter].present?
if params[:admin] == true
@query.where('username_lower ILIKE :filter OR email 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 OR email ILIKE :filter', filter: "%#{params[:filter]}%")
end
else
@query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%")
end

View File

@ -29,7 +29,6 @@ describe AdminUserIndexQuery do
end
describe "users with trust level" do
TrustLevel.levels.each do |key, value|
@ -138,5 +137,24 @@ describe AdminUserIndexQuery do
end
end
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
end
end
end
end