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