mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Remove REVERSE_GEOCODING_ENABLED env var
This commit is contained in:
parent
688440710f
commit
974f45a4c9
13 changed files with 25 additions and 25 deletions
|
|
@ -17,6 +17,7 @@ You may now use Geoapify API for reverse geocoding. To obtain an API key, sign u
|
|||
|
||||
- Photon ENV vars from the `.env.development` and docker-compose.yml files.
|
||||
- `APPLICATION_HOST` env var.
|
||||
- `REVERSE_GEOCODING_ENABLED` env var.
|
||||
|
||||
# 0.21.4 - 2025-01-05
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class ReverseGeocodingJob < ApplicationJob
|
|||
queue_as :reverse_geocoding
|
||||
|
||||
def perform(klass, id)
|
||||
return unless REVERSE_GEOCODING_ENABLED
|
||||
return unless DawarichSettings.reverse_geocoding_enabled?
|
||||
|
||||
rate_limit_for_photon_api
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Place < ApplicationRecord
|
|||
enum :source, { manual: 0, photon: 1 }
|
||||
|
||||
def async_reverse_geocode
|
||||
return unless REVERSE_GEOCODING_ENABLED
|
||||
return unless DawarichSettings.reverse_geocoding_enabled?
|
||||
|
||||
ReverseGeocodingJob.perform_later(self.class.to_s, id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Point < ApplicationRecord
|
|||
end
|
||||
|
||||
def async_reverse_geocode
|
||||
return unless REVERSE_GEOCODING_ENABLED
|
||||
return unless DawarichSettings.reverse_geocoding_enabled?
|
||||
|
||||
ReverseGeocodingJob.perform_later(self.class.to_s, id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Visit < ApplicationRecord
|
|||
end
|
||||
|
||||
def async_reverse_geocode
|
||||
return unless REVERSE_GEOCODING_ENABLED
|
||||
return unless DawarichSettings.reverse_geocoding_enabled?
|
||||
return if place.blank?
|
||||
|
||||
ReverseGeocodingJob.perform_later('place', place_id)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Visits::Suggest
|
|||
|
||||
create_visits_notification(user)
|
||||
|
||||
return nil unless reverse_geocoding_enabled?
|
||||
return nil unless DawarichSettings.reverse_geocoding_enabled?
|
||||
|
||||
reverse_geocode(visits)
|
||||
end
|
||||
|
|
@ -68,10 +68,6 @@ class Visits::Suggest
|
|||
visits.each(&:async_reverse_geocode)
|
||||
end
|
||||
|
||||
def reverse_geocoding_enabled?
|
||||
::REVERSE_GEOCODING_ENABLED && ::PHOTON_API_HOST.present?
|
||||
end
|
||||
|
||||
def create_visits_notification(user)
|
||||
content = <<~CONTENT
|
||||
New visits have been suggested based on your location data from #{Time.zone.at(start_at)} to #{Time.zone.at(end_at)}. You can review them on the <a href="#{visits_path}" class="link">Visits</a> page.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<p><%= stat.distance %><%= DISTANCE_UNIT %></p>
|
||||
<% if REVERSE_GEOCODING_ENABLED %>
|
||||
<% if DawarichSettings.reverse_geocoding_enabled? %>
|
||||
<div class="card-actions justify-end">
|
||||
<%= countries_and_cities_stat_for_month(stat) %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="stat-title">Geopoints tracked</div>
|
||||
</div>
|
||||
|
||||
<% if REVERSE_GEOCODING_ENABLED %>
|
||||
<% if DawarichSettings.reverse_geocoding_enabled? %>
|
||||
<%= render 'stats/reverse_geocoding_stats' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
<%= number_with_delimiter year_distance_stat(year, current_user) %><%= DISTANCE_UNIT %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% if REVERSE_GEOCODING_ENABLED %>
|
||||
<% if DawarichSettings.reverse_geocoding_enabled? %>
|
||||
<div class="card-actions justify-end">
|
||||
<%= countries_and_cities_stat_for_year(year, stats) %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ TELEMETRY_STRING = Base64.encode64('IjVFvb8j3P9-ArqhSGav9j8YcJaQiuNIzkfOPKQDk2lv
|
|||
TELEMETRY_URL = 'https://influxdb2.frey.today/api/v2/write'
|
||||
|
||||
# Reverse geocoding settings
|
||||
REVERSE_GEOCODING_ENABLED = ENV.fetch('REVERSE_GEOCODING_ENABLED', 'true') == 'true'
|
||||
|
||||
PHOTON_API_HOST = ENV.fetch('PHOTON_API_HOST', nil)
|
||||
PHOTON_API_KEY = ENV.fetch('PHOTON_API_KEY', nil)
|
||||
PHOTON_API_USE_HTTPS = ENV.fetch('PHOTON_API_USE_HTTPS', 'true') == 'true'
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@
|
|||
class DawarichSettings
|
||||
class << self
|
||||
def reverse_geocoding_enabled?
|
||||
photon_enabled? || geoapify_enabled?
|
||||
@reverse_geocoding_enabled ||= photon_enabled? || geoapify_enabled?
|
||||
end
|
||||
|
||||
def photon_enabled?
|
||||
PHOTON_API_HOST.present?
|
||||
@photon_enabled ||= PHOTON_API_HOST.present?
|
||||
end
|
||||
|
||||
def photon_uses_komoot_io?
|
||||
PHOTON_API_HOST == 'photon.komoot.io'
|
||||
@photon_uses_komoot_io ||= PHOTON_API_HOST == 'photon.komoot.io'
|
||||
end
|
||||
|
||||
def geoapify_enabled?
|
||||
GEOAPIFY_API_KEY.present?
|
||||
@geoapify_enabled ||= GEOAPIFY_API_KEY.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ RSpec.describe ReverseGeocodingJob, type: :job do
|
|||
allow(Geocoder).to receive(:search).and_return([double(city: 'City', country: 'Country')])
|
||||
end
|
||||
|
||||
context 'when REVERSE_GEOCODING_ENABLED is false' do
|
||||
before { stub_const('REVERSE_GEOCODING_ENABLED', false) }
|
||||
context 'when reverse geocoding is disabled' do
|
||||
before { allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(false) }
|
||||
|
||||
it 'does not update point' do
|
||||
expect { perform }.not_to(change { point.reload.city })
|
||||
|
|
@ -28,8 +28,8 @@ RSpec.describe ReverseGeocodingJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when REVERSE_GEOCODING_ENABLED is true' do
|
||||
before { stub_const('REVERSE_GEOCODING_ENABLED', true) }
|
||||
context 'when reverse geocoding is enabled' do
|
||||
before { allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(true) }
|
||||
|
||||
let(:stubbed_geocoder) { OpenStruct.new(data: { city: 'City', country: 'Country' }) }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DawarichSettings do
|
||||
before do
|
||||
described_class.instance_variables.each do |ivar|
|
||||
described_class.remove_instance_variable(ivar)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.reverse_geocoding_enabled?' do
|
||||
context 'when photon is enabled' do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ RSpec.describe Visits::Suggest do
|
|||
|
||||
context 'when reverse geocoding is enabled' do
|
||||
before do
|
||||
stub_const('REVERSE_GEOCODING_ENABLED', true)
|
||||
stub_const('PHOTON_API_HOST', 'http://localhost:2323')
|
||||
allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(true)
|
||||
end
|
||||
|
||||
it 'reverse geocodes visits' do
|
||||
|
|
@ -57,7 +56,7 @@ RSpec.describe Visits::Suggest do
|
|||
|
||||
context 'when reverse geocoding is disabled' do
|
||||
before do
|
||||
stub_const('REVERSE_GEOCODING_ENABLED', false)
|
||||
allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(false)
|
||||
end
|
||||
|
||||
it 'does not reverse geocode visits' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue