FIX: trim leading & trailing whitespaces in admin user search
This commit is contained in:
parent
41ce205733
commit
8f68a95e56
|
@ -79,6 +79,7 @@ class AdminUserIndexQuery
|
||||||
|
|
||||||
def filter_by_search
|
def filter_by_search
|
||||||
if params[:filter].present?
|
if params[:filter].present?
|
||||||
|
params[:filter].strip!
|
||||||
if ip = IPAddr.new(params[:filter]) rescue nil
|
if ip = IPAddr.new(params[:filter]) rescue nil
|
||||||
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
|
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
|
||||||
else
|
else
|
||||||
|
@ -89,7 +90,7 @@ class AdminUserIndexQuery
|
||||||
|
|
||||||
def filter_by_ip
|
def filter_by_ip
|
||||||
if params[:ip].present?
|
if params[:ip].present?
|
||||||
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip])
|
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip].strip)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,12 @@ describe AdminUserIndexQuery do
|
||||||
before(:each) { Fabricate(:user, email: "test1@example.com") }
|
before(:each) { Fabricate(:user, email: "test1@example.com") }
|
||||||
|
|
||||||
it "matches the email" do
|
it "matches the email" do
|
||||||
query = ::AdminUserIndexQuery.new({ filter: "est1" })
|
query = ::AdminUserIndexQuery.new({ filter: " est1" })
|
||||||
expect(query.find_users.count()).to eq(1)
|
expect(query.find_users.count()).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "matches the email using any case" do
|
it "matches the email using any case" do
|
||||||
query = ::AdminUserIndexQuery.new({ filter: "Test1" })
|
query = ::AdminUserIndexQuery.new({ filter: "Test1\t" })
|
||||||
expect(query.find_users.count()).to eq(1)
|
expect(query.find_users.count()).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,12 +126,12 @@ describe AdminUserIndexQuery do
|
||||||
before(:each) { Fabricate(:user, username: "test_user_1") }
|
before(:each) { Fabricate(:user, username: "test_user_1") }
|
||||||
|
|
||||||
it "matches the username" do
|
it "matches the username" do
|
||||||
query = ::AdminUserIndexQuery.new({ filter: "user" })
|
query = ::AdminUserIndexQuery.new({ filter: "user\n" })
|
||||||
expect(query.find_users.count).to eq(1)
|
expect(query.find_users.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "matches the username using any case" do
|
it "matches the username using any case" do
|
||||||
query = ::AdminUserIndexQuery.new({ filter: "User" })
|
query = ::AdminUserIndexQuery.new({ filter: "\r\nUser" })
|
||||||
expect(query.find_users.count).to eq(1)
|
expect(query.find_users.count).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -141,7 +141,7 @@ describe AdminUserIndexQuery do
|
||||||
let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
|
let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
|
||||||
|
|
||||||
it "matches the ip address" do
|
it "matches the ip address" do
|
||||||
query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" })
|
query = ::AdminUserIndexQuery.new({ filter: " 117.207.94.9 " })
|
||||||
expect(query.find_users.count()).to eq(1)
|
expect(query.find_users.count()).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue