mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FEATURE: Return geoname IDs from MaxMindDb (#16082)
The geoname IDs can be used by plugins to locate the user more precisely.
This commit is contained in:
parent
df2441ee37
commit
b21bf840cb
|
@ -101,6 +101,13 @@ class DiscourseIpInfo
|
|||
ret[:latitude] = result.location.latitude
|
||||
ret[:longitude] = result.location.longitude
|
||||
ret[:location] = ret.values_at(:city, :region, :country).reject(&:blank?).uniq.join(", ")
|
||||
|
||||
# used by plugins or API to locate users more accurate
|
||||
ret[:geoname_ids] = [
|
||||
result.continent.geoname_id, result.country.geoname_id, result.city.geoname_id,
|
||||
*result.subdivisions.map(&:geoname_id)
|
||||
]
|
||||
ret[:geoname_ids].compact!
|
||||
end
|
||||
rescue => e
|
||||
Discourse.warn_exception(e, message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.")
|
||||
|
|
|
@ -993,6 +993,7 @@ RSpec.describe Admin::UsersController do
|
|||
city: "London",
|
||||
country: "United Kingdom",
|
||||
country_code: "GB",
|
||||
geoname_ids: [6255148, 2635167, 2643743, 6269131],
|
||||
hostname: "ip-81-2-69-142.example.com",
|
||||
location: "London, England, United Kingdom",
|
||||
region: "England",
|
||||
|
|
Loading…
Reference in New Issue
Block a user