diff --git a/app/assets/javascripts/admin/addon/components/ip-lookup.hbs b/app/assets/javascripts/admin/addon/components/ip-lookup.hbs index 1097e54a84a..43c476e1049 100644 --- a/app/assets/javascripts/admin/addon/components/ip-lookup.hbs +++ b/app/assets/javascripts/admin/addon/components/ip-lookup.hbs @@ -31,7 +31,15 @@
{{i18n "ip_lookup.location"}}
- {{#if this.location.location}} + {{#if this.location.no_license}} + + {{i18n "ip_lookup.no_license"}} + + {{else if this.location.location}} MaxMindDB" copied: "copied" + no_license: "Configure MaxMind to enable GeoIP information" user_fields: none: "(select an option)" diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 2949f5858cb..5ef1332d6b6 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -11,8 +11,10 @@ class DiscourseIpInfo end def open_db(path) - @loc_mmdb = mmdb_load(File.join(path, "GeoLite2-City.mmdb")) - @asn_mmdb = mmdb_load(File.join(path, "GeoLite2-ASN.mmdb")) + unless GlobalSetting.maxmind_license_key.blank? + @loc_mmdb = mmdb_load(File.join(path, "GeoLite2-City.mmdb")) + @asn_mmdb = mmdb_load(File.join(path, "GeoLite2-ASN.mmdb")) + end @cache = LruRedux::ThreadSafeCache.new(2000) end @@ -105,6 +107,8 @@ class DiscourseIpInfo message: "IP #{ip} could not be looked up in MaxMind GeoLite2-City database.", ) end + else + ret[:no_license] = true end if @asn_mmdb diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 3efcf065fb8..e1f381c84cd 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -1153,6 +1153,8 @@ RSpec.describe Report do freeze_time DateTime.parse("2017-03-01 12:00") ip = [81, 2, 69, 142] + # Assign a dummy MaxMind license key, which is now checked in open_db + global_setting "maxmind_license_key", "dummy" DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) Resolv::DNS diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index 9a9e87b120d..add2a2755ce 100644 --- a/spec/requests/admin/users_controller_spec.rb +++ b/spec/requests/admin/users_controller_spec.rb @@ -1680,6 +1680,8 @@ RSpec.describe Admin::UsersController do shared_examples "IP info retrieval possible" do it "retrieves IP info" do ip = "81.2.69.142" + # Assign a dummy MaxMind license key, which is now checked in open_db + global_setting "maxmind_license_key", "dummy" DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com") @@ -1717,6 +1719,8 @@ RSpec.describe Admin::UsersController do it "prevents retrieval of IP info with a 404 response" do ip = "81.2.69.142" + # Assign a dummy MaxMind license key, which is now checked in open_db + global_setting "maxmind_license_key", "dummy" DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) Resolv::DNS.any_instance.stubs(:getname).with(ip).returns("ip-81-2-69-142.example.com") diff --git a/spec/serializers/user_auth_token_serializer_spec.rb b/spec/serializers/user_auth_token_serializer_spec.rb index f90bf21eb0b..5461caf6550 100644 --- a/spec/serializers/user_auth_token_serializer_spec.rb +++ b/spec/serializers/user_auth_token_serializer_spec.rb @@ -3,6 +3,8 @@ RSpec.describe UserAuthTokenSerializer do fab!(:user) { Fabricate(:moderator) } let(:token) { UserAuthToken.generate!(user_id: user.id, client_ip: "2a02:ea00::", staff: true) } + # Assign a dummy MaxMind license key, which is now checked in open_db + global_setting "maxmind_license_key", "dummy" before(:each) { DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) }