mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-01 08:25:18 -04:00
Merge pull request #2902 from techAPJ/patch-1
FEATURE: search by ip address on admin user list page
This commit is contained in:
commit
02371e1108
3 changed files with 25 additions and 3 deletions
config/locales
lib
spec/components
|
@ -577,7 +577,7 @@ en:
|
||||||
created_lowercase: 'created'
|
created_lowercase: 'created'
|
||||||
trust_level: 'Trust Level'
|
trust_level: 'Trust Level'
|
||||||
search_hint: 'username'
|
search_hint: 'username'
|
||||||
search_hint_admin: 'username or email'
|
search_hint_admin: 'username, email or IP address'
|
||||||
|
|
||||||
create_account:
|
create_account:
|
||||||
title: "Create New Account"
|
title: "Create New Account"
|
||||||
|
|
|
@ -37,7 +37,11 @@ class AdminUserIndexQuery
|
||||||
def filter_by_search
|
def filter_by_search
|
||||||
if params[:filter].present?
|
if params[:filter].present?
|
||||||
if params[:admin] == true
|
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
|
else
|
||||||
@query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%")
|
@query.where('username_lower ILIKE :filter', filter: "%#{params[:filter]}%")
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,6 @@ describe AdminUserIndexQuery do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "users with trust level" do
|
describe "users with trust level" do
|
||||||
|
|
||||||
TrustLevel.levels.each do |key, value|
|
TrustLevel.levels.each do |key, value|
|
||||||
|
@ -138,5 +137,24 @@ describe AdminUserIndexQuery do
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue