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:
Bianca Nenciu 2022-03-02 23:51:42 +02:00 committed by GitHub
parent df2441ee37
commit b21bf840cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -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.")

View File

@ -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",