mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Compare commits
5 commits
219929272c
...
7e17971fda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e17971fda | ||
|
|
699504f4e9 | ||
|
|
878d863569 | ||
|
|
24378b150d | ||
|
|
35f4c0f1f6 |
25 changed files with 224 additions and 57 deletions
33
CHANGELOG.md
33
CHANGELOG.md
|
|
@ -19,6 +19,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- Notification about Photon API load is now disabled.
|
||||
- All distance values are now stored in the database in meters. Conversion to user's preferred unit is done on the fly.
|
||||
- Every night, Dawarich will try to fetch names for places and visits that don't have them. #1281 #902 #583 #212
|
||||
- ⚠️ User settings are now being serialized in a more consistent way ⚠. `GET /api/v1/users/me` now returns the following data structure:
|
||||
```json
|
||||
{
|
||||
"user": {
|
||||
"email": "test@example.com",
|
||||
"theme": "light",
|
||||
"created_at": "2025-01-01T00:00:00Z",
|
||||
"updated_at": "2025-01-01T00:00:00Z",
|
||||
"settings": {
|
||||
"maps": {
|
||||
"url": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
"name": "Custom OpenStreetMap",
|
||||
"distance_unit": "km"
|
||||
},
|
||||
"fog_of_war_meters": 51,
|
||||
"meters_between_routes": 500,
|
||||
"preferred_map_layer": "Light",
|
||||
"speed_colored_routes": false,
|
||||
"points_rendering_mode": "raw",
|
||||
"minutes_between_routes": 30,
|
||||
"time_threshold_minutes": 30,
|
||||
"merge_threshold_minutes": 15,
|
||||
"live_map_enabled": false,
|
||||
"route_opacity": 0.3,
|
||||
"immich_url": "https://persistence-test-1752264458724.com",
|
||||
"photoprism_url": "",
|
||||
"visits_suggestions_enabled": true,
|
||||
"speed_color_scale": "0:#00ff00|15:#00ffff|30:#ff00ff|50:#ffff00|100:#ff3300",
|
||||
"fog_of_war_threshold": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Fixed
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
class Api::V1::UsersController < ApiController
|
||||
def me
|
||||
render json: { user: current_api_user }
|
||||
render json: Api::UserSerializer.new(current_api_user).call
|
||||
end
|
||||
end
|
||||
|
|
|
|||
44
app/serializers/api/user_serializer.rb
Normal file
44
app/serializers/api/user_serializer.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Api::UserSerializer
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def call
|
||||
{
|
||||
user: {
|
||||
email: user.email,
|
||||
theme: user.theme,
|
||||
created_at: user.created_at,
|
||||
updated_at: user.updated_at,
|
||||
settings: settings,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def settings
|
||||
{
|
||||
maps: user.safe_settings.maps,
|
||||
fog_of_war_meters: user.safe_settings.fog_of_war_meters.to_i,
|
||||
meters_between_routes: user.safe_settings.meters_between_routes.to_i,
|
||||
preferred_map_layer: user.safe_settings.preferred_map_layer,
|
||||
speed_colored_routes: user.safe_settings.speed_colored_routes,
|
||||
points_rendering_mode: user.safe_settings.points_rendering_mode,
|
||||
minutes_between_routes: user.safe_settings.minutes_between_routes.to_i,
|
||||
time_threshold_minutes: user.safe_settings.time_threshold_minutes.to_i,
|
||||
merge_threshold_minutes: user.safe_settings.merge_threshold_minutes.to_i,
|
||||
live_map_enabled: user.safe_settings.live_map_enabled,
|
||||
route_opacity: user.safe_settings.route_opacity.to_f,
|
||||
immich_url: user.safe_settings.immich_url,
|
||||
photoprism_url: user.safe_settings.photoprism_url,
|
||||
visits_suggestions_enabled: user.safe_settings.visits_suggestions_enabled?,
|
||||
speed_color_scale: user.safe_settings.speed_color_scale,
|
||||
fog_of_war_threshold: user.safe_settings.fog_of_war_threshold
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -45,7 +45,9 @@ class Users::SafeSettings
|
|||
photoprism_api_key: photoprism_api_key,
|
||||
maps: maps,
|
||||
distance_unit: distance_unit,
|
||||
visits_suggestions_enabled: visits_suggestions_enabled?
|
||||
visits_suggestions_enabled: visits_suggestions_enabled?,
|
||||
speed_color_scale: speed_color_scale,
|
||||
fog_of_war_threshold: fog_of_war_threshold
|
||||
}
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
|
@ -118,4 +120,12 @@ class Users::SafeSettings
|
|||
def visits_suggestions_enabled?
|
||||
settings['visits_suggestions_enabled'] == 'true'
|
||||
end
|
||||
|
||||
def speed_color_scale
|
||||
settings['speed_color_scale']
|
||||
end
|
||||
|
||||
def fog_of_war_threshold
|
||||
settings['fog_of_war_threshold']
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Visits::Suggest
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
attr_reader :points, :user, :start_at, :end_at
|
||||
|
||||
def initialize(user, start_at:, end_at:)
|
||||
|
|
@ -14,6 +12,7 @@ class Visits::Suggest
|
|||
|
||||
def call
|
||||
visits = Visits::SmartDetect.new(user, start_at:, end_at:).call
|
||||
|
||||
create_visits_notification(user) if visits.any?
|
||||
|
||||
return nil unless DawarichSettings.reverse_geocoding_enabled?
|
||||
|
|
@ -35,7 +34,7 @@ class Visits::Suggest
|
|||
|
||||
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.
|
||||
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" class="link">Visits</a> page.
|
||||
CONTENT
|
||||
|
||||
user.notifications.create!(
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
development:
|
||||
adapter: redis
|
||||
url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %>
|
||||
url: <%= "#{ENV.fetch("REDIS_URL")}" %>
|
||||
db: <%= "#{ENV.fetch('RAILS_WS_DB', 2)}" %>
|
||||
|
||||
test:
|
||||
adapter: test
|
||||
|
||||
production:
|
||||
adapter: redis
|
||||
url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %>
|
||||
url: <%= "#{ENV.fetch("REDIS_URL")}" %>
|
||||
db: <%= "#{ENV.fetch('RAILS_WS_DB', 2)}" %>
|
||||
channel_prefix: dawarich_production
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Rails.application.configure do
|
|||
|
||||
# Enable/disable caching. By default caching is disabled.
|
||||
# Run rails dev:cache to toggle caching.
|
||||
config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" }
|
||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'], db: ENV.fetch('RAILS_CACHE_DB', 0) }
|
||||
|
||||
if Rails.root.join('tmp/caching-dev.txt').exist?
|
||||
config.action_controller.perform_caching = true
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ Rails.application.configure do
|
|||
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
|
||||
|
||||
# Use a different cache store in production.
|
||||
config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" }
|
||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'], db: ENV.fetch('RAILS_CACHE_DB', 0) }
|
||||
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment).
|
||||
config.active_job.queue_adapter = :sidekiq
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ settings = {
|
|||
debug_mode: true,
|
||||
timeout: 5,
|
||||
units: :km,
|
||||
cache: Redis.new(url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}"),
|
||||
cache: Redis.new(url: ENV['REDIS_URL'], db: ENV.fetch('RAILS_CACHE_DB', 0)),
|
||||
always_raise: :all,
|
||||
http_headers: {
|
||||
'User-Agent' => "Dawarich #{APP_VERSION} (https://dawarich.app)"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Sidekiq.configure_server do |config|
|
||||
config.redis = { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_JOB_QUEUE_DB', 1)}" }
|
||||
config.redis = { url: ENV['REDIS_URL'], db: ENV.fetch('RAILS_JOB_QUEUE_DB', 1) }
|
||||
config.logger = Sidekiq::Logger.new($stdout)
|
||||
|
||||
if ENV['PROMETHEUS_EXPORTER_ENABLED'].to_s == 'true'
|
||||
|
|
@ -24,7 +24,7 @@ Sidekiq.configure_server do |config|
|
|||
end
|
||||
|
||||
Sidekiq.configure_client do |config|
|
||||
config.redis = { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_JOB_QUEUE_DB', 1)}" }
|
||||
config.redis = { url: ENV['REDIS_URL'], db: ENV.fetch('RAILS_JOB_QUEUE_DB', 1) }
|
||||
end
|
||||
|
||||
Sidekiq::Queue['reverse_geocoding'].limit = 1 if Sidekiq.server? && DawarichSettings.photon_uses_komoot_io?
|
||||
|
|
|
|||
|
|
@ -7,12 +7,28 @@ RSpec.describe 'Api::V1::Users', type: :request do
|
|||
let(:user) { create(:user) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{user.api_key}" } }
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns success response' do
|
||||
get '/api/v1/users/me', headers: headers
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(user.email)
|
||||
expect(response.body).to include(user.id.to_s)
|
||||
end
|
||||
|
||||
it 'returns only the keys and values stated in the serializer' do
|
||||
get '/api/v1/users/me', headers: headers
|
||||
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
expect(json.keys).to eq([:user])
|
||||
expect(json[:user].keys).to match_array(
|
||||
%i[email theme created_at updated_at settings]
|
||||
)
|
||||
expect(json[:user][:settings].keys).to match_array(%i[
|
||||
maps fog_of_war_meters meters_between_routes preferred_map_layer
|
||||
speed_colored_routes points_rendering_mode minutes_between_routes
|
||||
time_threshold_minutes merge_threshold_minutes live_map_enabled
|
||||
route_opacity immich_url photoprism_url visits_suggestions_enabled
|
||||
speed_color_scale fog_of_war_threshold
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
85
spec/serializers/api/user_serializer_spec.rb
Normal file
85
spec/serializers/api/user_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::UserSerializer do
|
||||
describe '#call' do
|
||||
subject(:serializer) { described_class.new(user).call }
|
||||
|
||||
let(:user) { create(:user, email: 'test@example.com', theme: 'dark') }
|
||||
|
||||
it 'returns JSON with correct user attributes' do
|
||||
expect(serializer[:user][:email]).to eq(user.email)
|
||||
expect(serializer[:user][:theme]).to eq(user.theme)
|
||||
expect(serializer[:user][:created_at]).to eq(user.created_at)
|
||||
expect(serializer[:user][:updated_at]).to eq(user.updated_at)
|
||||
end
|
||||
|
||||
it 'returns settings with expected keys and types' do
|
||||
settings = serializer[:user][:settings]
|
||||
expect(settings).to include(
|
||||
:maps,
|
||||
:fog_of_war_meters,
|
||||
:meters_between_routes,
|
||||
:preferred_map_layer,
|
||||
:speed_colored_routes,
|
||||
:points_rendering_mode,
|
||||
:minutes_between_routes,
|
||||
:time_threshold_minutes,
|
||||
:merge_threshold_minutes,
|
||||
:live_map_enabled,
|
||||
:route_opacity,
|
||||
:immich_url,
|
||||
:photoprism_url,
|
||||
:visits_suggestions_enabled,
|
||||
:speed_color_scale,
|
||||
:fog_of_war_threshold
|
||||
)
|
||||
end
|
||||
|
||||
context 'with custom settings' do
|
||||
let(:custom_settings) do
|
||||
{
|
||||
'fog_of_war_meters' => 123,
|
||||
'meters_between_routes' => 456,
|
||||
'preferred_map_layer' => 'Satellite',
|
||||
'speed_colored_routes' => true,
|
||||
'points_rendering_mode' => 'cluster',
|
||||
'minutes_between_routes' => 42,
|
||||
'time_threshold_minutes' => 99,
|
||||
'merge_threshold_minutes' => 77,
|
||||
'live_map_enabled' => false,
|
||||
'route_opacity' => 0.75,
|
||||
'immich_url' => 'https://immich.example.com',
|
||||
'photoprism_url' => 'https://photoprism.example.com',
|
||||
'visits_suggestions_enabled' => 'false',
|
||||
'speed_color_scale' => 'rainbow',
|
||||
'fog_of_war_threshold' => 5,
|
||||
'maps' => { 'distance_unit' => 'mi' }
|
||||
}
|
||||
end
|
||||
|
||||
let(:user) { create(:user, settings: custom_settings) }
|
||||
|
||||
it 'serializes custom settings correctly' do
|
||||
settings = serializer[:user][:settings]
|
||||
expect(settings[:fog_of_war_meters]).to eq(123)
|
||||
expect(settings[:meters_between_routes]).to eq(456)
|
||||
expect(settings[:preferred_map_layer]).to eq('Satellite')
|
||||
expect(settings[:speed_colored_routes]).to eq(true)
|
||||
expect(settings[:points_rendering_mode]).to eq('cluster')
|
||||
expect(settings[:minutes_between_routes]).to eq(42)
|
||||
expect(settings[:time_threshold_minutes]).to eq(99)
|
||||
expect(settings[:merge_threshold_minutes]).to eq(77)
|
||||
expect(settings[:live_map_enabled]).to eq(false)
|
||||
expect(settings[:route_opacity]).to eq(0.75)
|
||||
expect(settings[:immich_url]).to eq('https://immich.example.com')
|
||||
expect(settings[:photoprism_url]).to eq('https://photoprism.example.com')
|
||||
expect(settings[:visits_suggestions_enabled]).to eq(false)
|
||||
expect(settings[:speed_color_scale]).to eq('rainbow')
|
||||
expect(settings[:fog_of_war_threshold]).to eq(5)
|
||||
expect(settings[:maps]).to eq({ 'distance_unit' => 'mi' })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -27,7 +27,9 @@ RSpec.describe Users::SafeSettings do
|
|||
photoprism_api_key: nil,
|
||||
maps: { "distance_unit" => "km" },
|
||||
distance_unit: 'km',
|
||||
visits_suggestions_enabled: true
|
||||
visits_suggestions_enabled: true,
|
||||
speed_color_scale: nil,
|
||||
fog_of_war_threshold: nil
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
@ -98,7 +100,9 @@ RSpec.describe Users::SafeSettings do
|
|||
photoprism_api_key: "photoprism-key",
|
||||
maps: { "name" => "custom", "url" => "https://custom.example.com" },
|
||||
distance_unit: nil,
|
||||
visits_suggestions_enabled: false
|
||||
visits_suggestions_enabled: false,
|
||||
speed_color_scale: nil,
|
||||
fog_of_war_threshold: nil
|
||||
}
|
||||
)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ RSpec.describe Visits::Suggest do
|
|||
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(true)
|
||||
# Create points for reverse geocoding test in a separate time range
|
||||
|
||||
create_visit_points(user, reverse_geocoding_start_at)
|
||||
clear_enqueued_jobs
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,19 +29,22 @@ describe 'Users API', type: :request do
|
|||
settings: {
|
||||
type: :object,
|
||||
properties: {
|
||||
immich_url: { type: :string },
|
||||
route_opacity: { type: :string },
|
||||
immich_api_key: { type: :string },
|
||||
live_map_enabled: { type: :boolean },
|
||||
fog_of_war_meters: { type: :string },
|
||||
maps: { type: :object },
|
||||
fog_of_war_meters: { type: :integer },
|
||||
meters_between_routes: { type: :integer },
|
||||
preferred_map_layer: { type: :string },
|
||||
speed_colored_routes: { type: :boolean },
|
||||
meters_between_routes: { type: :string },
|
||||
points_rendering_mode: { type: :string },
|
||||
minutes_between_routes: { type: :string },
|
||||
time_threshold_minutes: { type: :string },
|
||||
merge_threshold_minutes: { type: :string },
|
||||
speed_colored_polylines: { type: :boolean }
|
||||
minutes_between_routes: { type: :integer },
|
||||
time_threshold_minutes: { type: :integer },
|
||||
merge_threshold_minutes: { type: :integer },
|
||||
live_map_enabled: { type: :boolean },
|
||||
route_opacity: { type: :number },
|
||||
immich_url: { type: :string, nullable: true },
|
||||
photoprism_url: { type: :string, nullable: true },
|
||||
visits_suggestions_enabled: { type: :boolean },
|
||||
speed_color_scale: { type: :string, nullable: true },
|
||||
fog_of_war_threshold: { type: :string, nullable: true }
|
||||
}
|
||||
},
|
||||
admin: { type: :boolean }
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
|
||||
end
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
|
||||
# test "connects with cookies" do
|
||||
# cookies.signed[:user_id] = 42
|
||||
#
|
||||
# connect
|
||||
#
|
||||
# assert_equal connection.user_id, "42"
|
||||
# end
|
||||
end
|
||||
0
test/fixtures/files/.keep
vendored
0
test/fixtures/files/.keep
vendored
|
|
@ -1,13 +0,0 @@
|
|||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../config/environment"
|
||||
require "rails/test_help"
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
# Run tests in parallel with specified workers
|
||||
parallelize(workers: :number_of_processors)
|
||||
|
||||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||
fixtures :all
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
Loading…
Reference in a new issue