mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
AC 120-78B chapter 3:
- Every change to logbook entries, sub-components, signatures, inspection
records, AD compliance, major records, W&B, components, squawks and
documents is kept as a RecordVersion (who, IP, when, field changes),
hash-chained per aircraft; versions can't be edited or deleted. Shown on
each logbook entry and in Activity -> Record history
- Nightly job: SQLite online-backup copy to storage/backups, verified
(integrity_check + record counts), pruned to the configured number; then
an integrity check of the history chains and every signature's seal and
fingerprint. Results on Admin -> About ("Back up and check now"); admins
are emailed on failure
- Software versions recorded (first/last seen) on Admin -> About
- Records package (Access & Sharing): logbook entries PDF with signatures,
signatures.csv, record-history.csv, self-contained status report HTML,
the .sam.zip, and a README, for the FAA/NTSB or a buyer
- Legacy (paper) records: documents can be marked as legacy records;
aircraft have an "electronic records since" date (status report, package)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.7 KiB
Ruby
46 lines
1.7 KiB
Ruby
# App-wide settings an admin can change (Admin → Settings), stored as
|
|
# key/value rows. Read straight from the database each time, so a change
|
|
# applies to every server process at once.
|
|
#
|
|
# Setting.max_upload_mb # => 50
|
|
# Setting.max_upload_bytes # => 52428800
|
|
class Setting < ApplicationRecord
|
|
INTEGERS = {
|
|
"max_upload_mb" => { default: 50, in: 1..1024, label: "Maximum upload size (MB)" },
|
|
"backups_kept" => { default: 14, in: 1..365, label: "Database backups kept" },
|
|
"logbook_templates_seeded" => { default: 0, in: 0..1, label: "Built-in logbook templates added" } # internal flag
|
|
}.freeze
|
|
|
|
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
|
|
validate :value_in_range
|
|
|
|
class << self
|
|
def max_upload_mb = integer("max_upload_mb")
|
|
def max_upload_bytes = max_upload_mb.megabytes
|
|
|
|
def integer(key)
|
|
definition = INTEGERS.fetch(key)
|
|
value = find_by(key: key)&.value
|
|
value.present? ? value.to_i.clamp(definition[:in]) : definition[:default]
|
|
end
|
|
|
|
# Saves several settings; returns the records (check #errors) or [].
|
|
def update_integers(values)
|
|
records = values.to_h.slice(*INTEGERS.keys).map do |key, value|
|
|
find_or_initialize_by(key: key).tap { _1.value = value.to_s.strip }
|
|
end
|
|
transaction { records.each { _1.save || raise(ActiveRecord::Rollback) } }
|
|
records
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def value_in_range
|
|
definition = INTEGERS[key] or return
|
|
unless value.to_s.match?(/\A\d+\z/) && definition[:in].cover?(value.to_i)
|
|
errors.add(:base, "#{definition[:label]} must be a whole number from #{definition[:in].min} to #{definition[:in].max}")
|
|
end
|
|
end
|
|
end
|