Merge pull request #2906 from techAPJ/patch-3

Moderators can search users by ip address
This commit is contained in:
Robin Ward 2014-10-23 14:16:26 -04:00
commit 1944e87b10
3 changed files with 9 additions and 14 deletions

View File

@ -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:

View File

@ -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

View File

@ -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