Fix owntracks point creation

This commit is contained in:
Eugene Burmakin 2025-07-20 17:43:55 +02:00
parent 45713f46dc
commit 708bca26eb
6 changed files with 54 additions and 40 deletions

View file

@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Fixed ## Fixed
- Swagger documentation is now valid again. - Swagger documentation is now valid again.
- Invalid owntracks points are now ignored.
# [0.29.1] - 2025-07-02 # [0.29.1] - 2025-07-02

View file

@ -8,7 +8,7 @@ class Owntracks::PointCreatingJob < ApplicationJob
def perform(point_params, user_id) def perform(point_params, user_id)
parsed_params = OwnTracks::Params.new(point_params).call parsed_params = OwnTracks::Params.new(point_params).call
return if parsed_params[:timestamp].nil? || parsed_params[:lonlat].nil? return if parsed_params.try(:[], :timestamp).nil? || parsed_params.try(:[], :lonlat).nil?
return if point_exists?(parsed_params, user_id) return if point_exists?(parsed_params, user_id)
Point.create!(parsed_params.merge(user_id:)) Point.create!(parsed_params.merge(user_id:))

View file

@ -10,6 +10,8 @@ class OwnTracks::Params
# rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/AbcSize
def call def call
return unless valid_point?
{ {
lonlat: "POINT(#{params[:lon]} #{params[:lat]})", lonlat: "POINT(#{params[:lon]} #{params[:lat]})",
battery: params[:batt], battery: params[:batt],
@ -84,4 +86,8 @@ class OwnTracks::Params
def owntracks_point? def owntracks_point?
params[:topic].present? params[:topic].present?
end end
def valid_point?
params[:lon].present? && params[:lat].present? && params[:tst].present?
end
end end

View file

@ -28,5 +28,13 @@ RSpec.describe Owntracks::PointCreatingJob, type: :job do
expect { perform }.not_to(change { Point.count }) expect { perform }.not_to(change { Point.count })
end end
end end
context 'when point is invalid' do
let(:point_params) { { lat: 1.0, lon: 1.0, tid: 'test', tst: nil, topic: 'iPhone 12 pro' } }
it 'does not create a point' do
expect { perform }.not_to(change { Point.count })
end
end
end end
end end

View file

@ -185,5 +185,13 @@ RSpec.describe OwnTracks::Params do
expect(params[:trigger]).to eq('unknown') expect(params[:trigger]).to eq('unknown')
end end
end end
context 'when point is invalid' do
let(:raw_point_params) { super().merge(lon: nil, lat: nil, tst: nil) }
it 'returns parsed params' do
expect(params).to eq(nil)
end
end
end end
end end

View file

@ -1059,18 +1059,14 @@ paths:
type: string type: string
example: your-photoprism-api-key example: your-photoprism-api-key
description: API key for PhotoPrism photo service description: API key for PhotoPrism photo service
maps: speed_color_scale:
type: object
properties:
distance_unit:
type: string type: string
example: km example: viridis
description: Distance unit preference (km or miles) description: Color scale for speed-colored routes
description: Map-related settings fog_of_war_threshold:
visits_suggestions_enabled: type: number
type: boolean example: 100
example: true description: Fog of war threshold value
description: Whether visit suggestions are enabled
examples: examples:
'0': '0':
summary: Updates user settings summary: Updates user settings
@ -1090,9 +1086,8 @@ paths:
immich_api_key: your-immich-api-key immich_api_key: your-immich-api-key
photoprism_url: https://photoprism.example.com photoprism_url: https://photoprism.example.com
photoprism_api_key: your-photoprism-api-key photoprism_api_key: your-photoprism-api-key
maps: speed_color_scale: viridis
distance_unit: km fog_of_war_threshold: 100
visits_suggestions_enabled: true
get: get:
summary: Retrieves user settings summary: Retrieves user settings
tags: tags:
@ -1116,28 +1111,28 @@ paths:
type: object type: object
properties: properties:
route_opacity: route_opacity:
type: string type: number
example: '60' example: 60
description: Route opacity percentage (0-100) description: Route opacity percentage (0-100)
meters_between_routes: meters_between_routes:
type: string type: number
example: '500' example: 500
description: Minimum distance between routes in meters description: Minimum distance between routes in meters
minutes_between_routes: minutes_between_routes:
type: string type: number
example: '30' example: 30
description: Minimum time between routes in minutes description: Minimum time between routes in minutes
fog_of_war_meters: fog_of_war_meters:
type: string type: number
example: '50' example: 50
description: Fog of war radius in meters description: Fog of war radius in meters
time_threshold_minutes: time_threshold_minutes:
type: string type: number
example: '30' example: 30
description: Time threshold for grouping points in minutes description: Time threshold for grouping points in minutes
merge_threshold_minutes: merge_threshold_minutes:
type: string type: number
example: '15' example: 15
description: Threshold for merging nearby points in minutes description: Threshold for merging nearby points in minutes
preferred_map_layer: preferred_map_layer:
type: string type: string
@ -1172,18 +1167,14 @@ paths:
type: string type: string
example: your-photoprism-api-key example: your-photoprism-api-key
description: API key for PhotoPrism photo service description: API key for PhotoPrism photo service
maps: speed_color_scale:
type: object
properties:
distance_unit:
type: string type: string
example: km example: viridis
description: Distance unit preference (km or miles) description: Color scale for speed-colored routes
description: Map-related settings fog_of_war_threshold:
visits_suggestions_enabled: type: number
type: boolean example: 100
example: true description: Fog of war threshold value
description: Whether visit suggestions are enabled
"/api/v1/stats": "/api/v1/stats":
get: get:
summary: Retrieves all stats summary: Retrieves all stats