Records integrity: history, nightly backup and check, records package

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>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 13:21:26 -05:00
1 parent d719f663bc
commit 68a1719db2
53 files changed
+750 -12

No files matched your search

+32
View File
@@ -78,6 +78,38 @@
</div>
</div>
<section class="card mt-5" id="records">
<div class="card-header">
<div>
<h2 class="card-title">Records integrity</h2>
<p class="text-xs text-slate-500">Nightly: a verified database backup, then a check of the record history chains and every electronic signature (AC 120-78B 3.2).</p>
</div>
<%= button_to "Back up and check now", admin_check_records_path, class: "btn-secondary btn-sm", data: { turbo_submits_with: "Checking…" } %>
</div>
<% check = IntegrityCheck.latest %>
<% backup = BackupRun.latest %>
<%= render "pairs", pairs: [
[ "Last check", check ? "#{l(check.created_at, format: :short)} · #{check.ok ? 'no problems' : pluralize(check.problems.size, 'problem')}" : "not run yet" ],
[ "Checked", check ? "#{number_with_delimiter(check.versions_checked)} history entries, #{number_with_delimiter(check.signatures_checked)} signatures" : nil ],
[ "Last backup", backup ? "#{l(backup.created_at, format: :short)} · #{backup.ok ? number_to_human_size(backup.bytes) : 'FAILED'}" : "not run yet" ],
[ "Backup check", backup&.message ],
[ "Backups kept", "#{Setting.integer('backups_kept')} (in storage/backups)" ]
] %>
<% if check && !check.ok %>
<ul class="list-disc space-y-1 px-8 pb-3 text-sm text-red-700"><% check.problems.each do |p| %><li><%= p %></li><% end %></ul>
<% end %>
</section>
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">Software versions</h2></div>
<% revisions = AppRevision.latest_first.limit(20) %>
<% if revisions.any? %>
<%= render "pairs", pairs: revisions.map { |r| [ r.revision, "#{l(r.first_seen_at, format: :short)} – #{l(r.last_seen_at, format: :short)}" ] } %>
<% else %>
<%= empty_state "No versions recorded yet." %>
<% end %>
</section>
<details class="card mt-5">
<summary class="card-header cursor-pointer"><span class="card-title">All gems (<%= info.all_gems.size %>)</span></summary>
<div class="grid gap-x-6 px-4 py-3 font-mono text-xs sm:grid-cols-2 lg:grid-cols-3">
+9
View File
@@ -22,5 +22,14 @@
</p>
</div>
<h2 class="card-title pt-2">Backups</h2>
<% kept = Setting::INTEGERS["backups_kept"] %>
<div>
<%= label_tag "settings[backups_kept]", kept[:label], class: "label" %>
<%= number_field_tag "settings[backups_kept]", @values["backups_kept"], id: "settings_backups_kept", min: kept[:in].min, max: kept[:in].max,
step: 1, required: true, class: "input w-32" %>
<p class="hint">A verified copy of the database is made nightly in storage/backups; this many of the newest are kept. Back up the whole storage volume off the server too.</p>
</div>
<div class="flex gap-2"><%= f.submit "Save Settings", class: "btn-primary" %><%= link_to "Cancel", admin_about_path, class: "btn-secondary" %></div>
<% end %>
@@ -0,0 +1,5 @@
<p>Last night's records check found a problem.</p>
<p>Backup: <strong><%= @backup.ok ? "OK" : "FAILED: #{@backup.message}" %></strong><br>
Integrity check: <strong><%= @check.ok ? "OK" : "#{@check.problems.size} problem(s)" %></strong></p>
<ul><% Array(@check.problems).first(20).each do |p| %><li><%= p %></li><% end %></ul>
<p>See Admin → About for details.</p>
@@ -0,0 +1,9 @@
Last night's records check found a problem.
Backup: <%= @backup.ok ? "OK" : "FAILED: #{@backup.message}" %>
Integrity check: <%= @check.ok ? "OK" : "#{@check.problems.size} problem(s)" %>
<% Array(@check.problems).first(20).each do |p| %>
- <%= p %>
<% end %>
See Admin → About for details.
+2
View File
@@ -25,6 +25,8 @@
<p class="hint">To change hours use “Update Hours” on the overview, so component times stay in sync.</p>
<% end %>
<%= f.field :picture, as: :file, accept: "image/*" %>
<%= f.field :electronic_records_since, as: :date, label: "Electronic records since", wrapper: { class: "max-w-xs" },
hint: "The date this app became the maintenance record. Earlier records stay in the paper logbooks (mark their scans as legacy records)." %>
<%= f.field :airworthiness_enforcement, as: :checkbox, label: "Enforce airworthiness",
hint: "Block flight logs and hours updates while the aircraft shows Grounded." %>
<div class="flex gap-2">
+7
View File
@@ -67,5 +67,12 @@
</div>
<%= link_to "Download .sam.zip", aircraft_export_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
</div>
<div class="card-header border-t border-slate-100">
<div>
<h2 class="card-title">Records package</h2>
<p class="hint">For an FAA or NTSB request, or a buyer: every logbook entry as a PDF with its electronic signature, a signature register, the full change history, the status report, and the .sam.zip, in one ZIP with a README.</p>
</div>
<%= link_to "Download records package", aircraft_records_package_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
</div>
</section>
</div>
+1
View File
@@ -2,6 +2,7 @@
<div>
<%= link_to doc.name, aircraft_document_path(aircraft, doc), class: "link font-medium" %>
<span class="ml-2 text-xs text-slate-500"><%= doc.type_label %> · <%= pluralize(doc.pages.size, "file") %></span>
<% if doc.legacy_record? %><span class="ml-1 badge-gray" title="Scan of the paper (legacy) records">Legacy record</span><% end %>
<% if doc.expires_on %><span class="ml-1 <%= doc.expired? ? 'badge-red' : (Date.current + doc.expiry_warning_days >= doc.expires_on ? 'badge-orange' : 'badge-gray') %>"><%= doc.expired? ? "Expired" : "Expires" %> <%= doc.expires_on %></span><% end %>
<% if doc.description.present? %><div class="text-xs text-slate-500"><%= doc.description.truncate(120) %></div><% end %>
</div>
+2
View File
@@ -8,6 +8,8 @@
<%= f.field :visibility, as: :select, label: "Share-link visibility",
collection: [["Inherit from collection", nil]] + DocumentCollection::VISIBILITIES.invert.to_a %>
</div>
<%= f.field :legacy_record, as: :checkbox, label: "Legacy record (a scan of the paper logbooks or records)",
hint: "Records from before the electronic records began. Keep the paper originals." %>
<%= f.field :expires_on, as: :date, label: "Expires on", wrapper: { class: "max-w-xs" },
hint: "Optional. Registration (good for 7 years, 14 CFR 47.40), insurance, radio license… You'll be reminded before it expires; an expired registration shows the aircraft grounded." %>
<%= f.field :description, as: :textarea, rows: 2 %>
+3
View File
@@ -3,9 +3,12 @@
<section class="card">
<div class="card-header">
<h2 class="card-title">Activity Log</h2>
<div class="flex flex-wrap items-center gap-2">
<%= link_to "Record history", aircraft_record_versions_path(@aircraft), class: "btn-secondary btn-sm", title: "Every change to the maintenance records, field by field" %>
<%= form_with url: aircraft_events_path(@aircraft), method: :get, class: "flex gap-2" do |f| %>
<%= f.select :category, AircraftEvent::CATEGORIES.invert, { include_blank: "All categories", selected: @category }, class: "input", data: { submit_on_change: true } %>
<% end %>
</div>
</div>
<%= render "events/list", events: @events, full: true %>
</section>
+8
View File
@@ -58,3 +58,11 @@
<% end %>
</div>
</section>
<% history = (@entry.versions.to_a + @entry.parts.flat_map { _1.versions.to_a } + (@entry.signature ? @entry.signature.versions.to_a : [])).sort_by(&:id).reverse %>
<% if history.any? %>
<details class="card mt-5 max-w-4xl">
<summary class="card-header cursor-pointer"><span class="card-title">Change history (<%= history.size %>)</span></summary>
<%= render "record_versions/list", versions: history %>
</details>
<% end %>
@@ -22,6 +22,7 @@
<dt class="text-slate-500">Airframe time in service</dt><dd class="font-semibold"><%= hours(@report.time_in_service) %> hrs (<%= clock %>)</dd>
<dt class="text-slate-500">Tach / Hobbs</dt><dd><%= hours(a.tach_time) %> / <%= hours(a.hobbs_time) %></dd>
<dt class="text-slate-500">Status</dt><dd><%= airworthiness_badge(@report.airworthiness) %></dd>
<dt class="text-slate-500">Electronic records since</dt><dd><%= a.electronic_records_since || "—" %></dd>
</dl>
</header>
+19
View File
@@ -0,0 +1,19 @@
<%# Locals: versions. %>
<ul class="divide-y divide-slate-100 text-sm">
<% versions.each do |v| %>
<li class="px-4 py-2">
<div class="flex flex-wrap items-baseline justify-between gap-2">
<span><span class="font-medium"><%= v.item_type.underscore.humanize %> #<%= v.item_id %></span>
<span class="<%= { 'create' => 'badge-green', 'update' => 'badge-blue', 'destroy' => 'badge-red' }[v.event] %> ml-1"><%= { "create" => "created", "update" => "changed", "destroy" => "deleted" }[v.event] %></span></span>
<span class="text-xs text-slate-500"><%= v.created_at.utc.strftime("%Y-%m-%d %H:%M:%S UTC") %> · <%= v.user&.display_name || "system" %><%= " · #{v.ip_address}" if v.ip_address %></span>
</div>
<% if v.event == "update" %>
<dl class="mt-1 grid gap-x-3 text-xs text-slate-600 sm:grid-cols-[10rem_1fr]">
<% v.changes_hash.each do |field, (before, after)| %>
<dt class="text-slate-500"><%= field.humanize %></dt><dd class="break-words"><span class="line-through decoration-slate-400"><%= before.to_s.truncate(120).presence || "—" %></span> → <%= after.to_s.truncate(120).presence || "—" %></dd>
<% end %>
</dl>
<% end %>
</li>
<% end %>
</ul>
+14
View File
@@ -0,0 +1,14 @@
<% content_for :title, "#{@aircraft.tail_number} Record history" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<section class="card">
<div class="card-header">
<div>
<h2 class="card-title">Record history</h2>
<p class="text-xs text-slate-500">Every change to the maintenance records, kept for good and chained so that removing or altering history shows in the nightly check.</p>
</div>
<%= form_with url: aircraft_record_versions_path(@aircraft), method: :get, class: "flex gap-2" do %>
<%= select_tag :type, options_for_select([ [ "All records", "" ] ] + @types.map { [ _1.underscore.humanize, _1 ] }, @type), class: "input w-48", data: { submit_on_change: true } %>
<% end %>
</div>
<% if @versions.any? %><%= render "record_versions/list", versions: @versions %><% else %><%= empty_state "No changes recorded yet." %><% end %>
</section>