mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: search by ip address on admin user list page
This commit is contained in:
parent
de415b804c
commit
1035df46bf
3 changed files with 25 additions and 3 deletions
|
@ -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"
|
||||
|
|
|
@ -37,7 +37,11 @@ class AdminUserIndexQuery
|
|||
def filter_by_search
|
||||
if params[:filter].present?
|
||||
if params[:admin] == true
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue