mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +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:
@ -101,6 +101,13 @@ class DiscourseIpInfo
|
|||||||
ret[:latitude] = result.location.latitude
|
ret[:latitude] = result.location.latitude
|
||||||
ret[:longitude] = result.location.longitude
|
ret[:longitude] = result.location.longitude
|
||||||
ret[:location] = ret.values_at(:city, :region, :country).reject(&:blank?).uniq.join(", ")
|
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
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
Discourse.warn_exception(e, message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.")
|
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",
|
city: "London",
|
||||||
country: "United Kingdom",
|
country: "United Kingdom",
|
||||||
country_code: "GB",
|
country_code: "GB",
|
||||||
|
geoname_ids: [6255148, 2635167, 2643743, 6269131],
|
||||||
hostname: "ip-81-2-69-142.example.com",
|
hostname: "ip-81-2-69-142.example.com",
|
||||||
location: "London, England, United Kingdom",
|
location: "London, England, United Kingdom",
|
||||||
region: "England",
|
region: "England",
|
||||||
|
Reference in New Issue
Block a user