mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Refuse to start with a placeholder or short SECRET_KEY_BASE (under 32 characters); warn and fail sam:doctor under 64. .env.example no longer ships a placeholder. - First-run setup needs a one-time code printed only in the server log, so only whoever runs the server can create the admin account. - AirTrail: the server resolves the address and connects to exactly that; never the server itself or link-local addresses (cloud metadata); private-network addresses only for admins or hosts in AIRTRAIL_ALLOWED_HOSTS. - Host authorization when APP_HOST is set: APP_HOST, the APP_URL host, ALLOWED_HOSTS, localhost and IP addresses; /up exempt. A blocked name gets a short explanation instead of a blank 403. - docker-compose.direct.yml: HTTPS without a proxy via Thruster's built-in Let's Encrypt (TLS_DOMAIN). - Notes' Markdown no longer allows the unused class attribute. - README, .env.example and the user guide updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.3 KiB
Ruby
35 lines
1.3 KiB
Ruby
# A user's AirTrail account (https://github.com/johanohly/AirTrail). Flights
|
|
# the user logs are pushed there through AirTrail's REST API.
|
|
#
|
|
# The API key needs these scopes: profile.read, flight.read.own,
|
|
# flight.create.own, flight.update.own, flight.delete.own,
|
|
# reference_data.read and tracks.write.
|
|
class AirTrailConnection < ApplicationRecord
|
|
REQUIRED_SCOPES = %w[profile.read flight.read.own flight.create.own flight.update.own
|
|
flight.delete.own reference_data.read tracks.write].freeze
|
|
|
|
belongs_to :user
|
|
has_many :syncs, class_name: "AirTrailSync", dependent: :delete_all
|
|
has_many :airports, class_name: "AirTrailAirport", dependent: :delete_all
|
|
|
|
encrypts :api_key
|
|
|
|
normalizes :base_url, with: ->(url) { url.strip.chomp("/") }
|
|
validates :base_url, presence: true, format: { with: %r{\Ahttps?://[^\s/]+(:\d+)?(/\S*)?\z}i, message: "must be a http(s) URL" }
|
|
validates :api_key, presence: true
|
|
|
|
scope :active, -> { where(enabled: true) }
|
|
|
|
def client = AirTrailClient.new(base_url: base_url, api_key: api_key, allow_private: user&.admin?)
|
|
|
|
def ok? = status == "ok"
|
|
|
|
def unresolved_airport_codes
|
|
airports.where(remote_id: nil).order(:code).pluck(:code)
|
|
end
|
|
|
|
def counts
|
|
syncs.group(:status).count.reverse_merge("synced" => 0, "pending" => 0, "error" => 0)
|
|
end
|
|
end
|