/ip_addresses: allow searching multiple IPs at once.
Fixes #4208. Allow searching for multiple IPs or user IDs. Separate using spaces or commas.
This commit is contained in:
@@ -51,8 +51,13 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def where_inet_matches(attr, value)
|
def where_inet_matches(attr, value)
|
||||||
ip = IPAddress.parse(value)
|
if value.match?(/[, ]/)
|
||||||
where("#{qualified_column_for(attr)} <<= ?", ip.to_string)
|
ips = value.split(/[, ]+/).map { |ip| IPAddress.parse(ip).to_string }
|
||||||
|
where("#{qualified_column_for(attr)} = ANY(ARRAY[?]::inet[])", ips)
|
||||||
|
else
|
||||||
|
ip = IPAddress.parse(value)
|
||||||
|
where("#{qualified_column_for(attr)} <<= ?", ip.to_string)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def where_array_includes_any(attr, values)
|
def where_array_includes_any(attr, values)
|
||||||
|
|||||||
@@ -371,8 +371,8 @@ class Tag < ApplicationRecord
|
|||||||
when /\A>(.+)/
|
when /\A>(.+)/
|
||||||
return [:gt, parse_cast($1, type)]
|
return [:gt, parse_cast($1, type)]
|
||||||
|
|
||||||
when /,/
|
when /[, ]/
|
||||||
return [:in, range.split(/,/).map {|x| parse_cast(x, type)}]
|
return [:in, range.split(/[, ]+/).map {|x| parse_cast(x, type)}]
|
||||||
|
|
||||||
else
|
else
|
||||||
return [:eq, parse_cast(range, type)]
|
return [:eq, parse_cast(range, type)]
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
<p>
|
||||||
|
<%= link_to "Find all users associated with the top 10 IP addresses", ip_addresses_path(search: { ip_addr: @ip_addresses.map(&:to_s).take(10).join(" "), group_by: "user" }) %>
|
||||||
|
</p>
|
||||||
|
|
||||||
<table class="striped autofit">
|
<table class="striped autofit">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
<p>
|
||||||
|
<%= link_to "Find all IP addresses associated with these users", ip_addresses_path(search: { user_id: @ip_addresses.map(&:user_id).join(" "), group_by: "ip_addr" }) %>
|
||||||
|
</p>
|
||||||
|
|
||||||
<table class="striped autofit">
|
<table class="striped autofit">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user