Records package viewer: read-only, no account needed

SAM_VIEWER=true (set only by the records package's
viewer/docker-compose.yml) makes the app a read-only copy of an archive,
for whoever receives the records: `docker compose up`, then open
http://localhost:3000.

- At start (bin/docker-entrypoint → sam:viewer:prepare) the package's
  .sam.zip, mounted read-only, is imported once.
- No sign-in: everyone browses as a built-in account. Nothing can be
  changed: any request but GET/HEAD is refused, no role permission
  applies (so no edit buttons), and there's no sign-out or profile. A
  banner names the archive and when it was exported.
- It refuses to start, and every page answers 503, when the database
  has any other account, so turning it on for a real installation stops
  the app instead of exposing its records.
- The viewer listens on 127.0.0.1 only, and skips scheduled jobs
  (reminders, backups, AD searches).
- Docs: the package README (three steps now), Access & sharing, README
  settings and features, the suggested recordkeeping procedures.

Checked end to end with a built image and a real records package: the
archive imported at start, pages browsed without an account, a change
refused, and the container refusing to start once an account existed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-15 20:03:56 -05:00
1 parent 34e3232350
commit d956cfbe83
14 files changed
+229 -33

No files matched your search

+3 -1
View File
@@ -94,6 +94,8 @@ The app is a standard Rails app. Run `bin/rails db:prepare && bin/thrust bin/rai
| `PWNED_PASSWORDS_CHECK` | `false` turns off the check of new passwords against Have I Been Pwned (only the first 5 characters of the password's SHA-1 are sent). Use it if the server has no outbound internet access; the check also allows the password if the service can't be reached. |
| `PASSWORD_LOGIN` | `false` hides email/password sign-in, emailed sign-in links and password resets once SSO works. It's ignored while SSO isn't configured, so you can't lock yourself out. |
| `APP_REPOSITORY_URL` | Optional. The source code link on Admin → About, for a fork. |
| `APP_IMAGE` | Optional. The image the records package's viewer runs, used as is (for a fork). Default: the published image at the release that made the package. |
| `SAM_VIEWER`, `SAM_VIEWER_ARCHIVE` | **Only for the records package's viewer** (its `viewer/docker-compose.yml` sets them). `SAM_VIEWER=true` makes the app a read-only copy with no sign-in: it imports the `.sam.zip` at `SAM_VIEWER_ARCHIVE` at start, everyone browses as a built-in account, and nothing can be changed. It refuses to start on a database with any user account, so turning it on for a real installation stops the app instead of exposing its records. |
| `APP_REVISION`, `APP_BUILT_AT` | Set as Docker build arguments (see the `Dockerfile`) so Admin → About shows the version and the records keep a software version history. |
### Single sign-on (Authentik example)
@@ -150,7 +152,7 @@ To back up or move a single aircraft with all its files, use **More → Download
| Logbook | Maintenance entries with search and a link to a scanned document page. Records the signer's certificate kind and number and an inspection's result, and flags what 43.9 / 43.11 needs that's missing. Entries transcribed by Claude stay "unverified" until someone checks them against the scan. Entry templates (built-in pilot preventive maintenance per 43.3(g) and Part 43 Appendix A(c); admins add and edit their own under Admin → Logbook templates). Engine and propeller entries link the component and record its total time and time since overhaul (SMOH/SFOH/SNEW) at the entry, worked out from the entry's airframe total time; sub-components (an oil filter on the engine…) can be included with their own times. Print entries as a PDF on Avery 5163/8163 or 5164/8164 labels or half-letter/letter pages (boxed) to sign and put in the paper logbook. |
| Documents | Collections, multi-file documents with a page viewer (PDFs drawn page by page with PDF.js on phones, fetching only the pages viewed), per-document share visibility, bulk upload, and expiration dates (registration, insurance…). Their text is read for search: PDF text layers directly, scans by Tesseract OCR (in the image) or optionally Claude. |
| Electronic signatures | Logbook entries can be signed electronically along the lines of AC 120-78B chapter 2: the signer reviews the entry, picks their certificate, re-enters their password (or signs in again with SSO) and confirms a "Certified by" statement. The signature records who, which certificate, the statement, the time and a SHA-256 fingerprint of the entry, sealed by the server; the signer gets an email. Signed entries are locked: a correction is a new signed entry that supersedes the original. Owners can invite an outside mechanic to sign one entry with their own account. Disabled accounts can't sign; their past signatures stay. |
| Records integrity | Every change to maintenance records is kept (who, when, field by field) in a hash chain per aircraft (Activity → Record history). Nightly: a verified SQLite backup in `storage/backups` (how many are kept: Admin → Settings), then a check of the history chains and every signature; admins are emailed on a problem (Admin → About). Software versions are recorded. A records package (Access & Sharing) bundles every entry as a PDF with signatures, a signature register, the history, the status report and the `.sam.zip` for the FAA or a buyer, with a README (and a ready-to-run `viewer/docker-compose.yml`) so the recipient can browse the data in their own local copy of the app. Scans of paper logbooks can be marked as legacy records, with an "electronic records since" date per aircraft. |
| Records integrity | Every change to maintenance records is kept (who, when, field by field) in a hash chain per aircraft (Activity → Record history). Nightly: a verified SQLite backup in `storage/backups` (how many are kept: Admin → Settings), then a check of the history chains and every signature; admins are emailed on a problem (Admin → About). Software versions are recorded. A records package (Access & Sharing) bundles every entry as a PDF with signatures, a signature register, the history, the status report and the `.sam.zip` for the FAA or a buyer, with a README and a ready-to-run `viewer/docker-compose.yml`: `docker compose up` gives the recipient a read-only copy of the app on their own computer, with the archive imported and no sign-in (`SAM_VIEWER`). Scans of paper logbooks can be marked as legacy records, with an "electronic records since" date per aircraft. |
| Off-site backup | Nightly copy of the verified database snapshot (newest 30 kept) and every new uploaded file to Google Drive, using your own Google OAuth client and the `drive.file` scope (the app sees only its own files). Restore test from the admin page; failures emailed to admins; `bin/rails offsite:restore_files` brings files back after a restore. |
| Recordkeeping procedures and audits | Admin → Recordkeeping Procedures generates the procedures document AC 120-78B asks for (who is responsible, who may sign, signing, corrections, backups, access, audits, transfer, legacy records) from the system setup plus a few details you fill in (with suggested text built from the installation's settings; a revision can't be adopted while a [bracketed] blank is left); adopt it as numbered, unchangeable revisions, included in the records package. Admin → Records Audits is a periodic QC checklist (app checks plus a restore test, a sample of entries against source documents and a user review); admins get the due date in the weekly reminder. The users' instructions are the guide's [Electronic records and signing](docs/guide/records.md) page. |
| Major repairs and alterations | Form 337, STC, and ICA tracking; an STC's ICA can become a tracked recurring inspection. |
+13
View File
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
include RejectsNullBytes
prepend_before_action :redirect_to_setup
prepend_before_action :viewer_guard # first (see Viewer)
before_action { Current.ip_address = request.remote_ip } # for record history
helper_method :current_user
@@ -40,6 +41,18 @@ class ApplicationController < ActionController::Base
def current_user = Current.user
# First run: no users yet → create the initial admin.
# Viewer mode: never with real accounts, and nothing can be changed.
def viewer_guard
return unless Viewer.enabled?
return render(plain: Viewer::RealAccounts.new.message, status: :service_unavailable) if Viewer.real_accounts?
Viewer.user
return if request.get? || request.head?
respond_to do |format|
format.html { redirect_back fallback_location: root_path, alert: t("viewer.read_only") }
format.any { head :forbidden }
end
end
def redirect_to_setup
redirect_to new_setup_path if !User.exists? && !is_a?(SetupController)
end
+3 -2
View File
@@ -49,10 +49,11 @@ module AircraftScoped
@current_role = current_user.role_for(@aircraft)
end
def can?(permission) = current_user.admin? || current_role&.can?(permission) || false
# Nothing in viewer mode (a read-only copy, see Viewer).
def can?(permission) = !Viewer.enabled? && (current_user.admin? || current_role&.can?(permission) || false)
# The Owner role (or an administrator): everything.
def owner? = current_user.admin? || current_role&.owner? || false
def owner? = !Viewer.enabled? && (current_user.admin? || current_role&.owner? || false)
def authorize_permission!
rules = self.class.permission_rules.select do |_, only, except|
+6 -1
View File
@@ -21,7 +21,12 @@ module Authentication
end
def require_authentication
resume_session || request_authentication
resume_session || start_viewer_session || request_authentication
end
# Viewer mode: everyone is its built-in account, without signing in.
def start_viewer_session
start_new_session_for(Viewer.user) if Viewer.enabled? && !Viewer.real_accounts?
end
def resume_session
+2 -1
View File
@@ -123,10 +123,11 @@ class User < ApplicationRecord
# Adding an aircraft (or importing one) makes you its Owner: administrators,
# or everyone when Admin → Settings allows it.
def can_add_aircraft? = admin? || Setting.anyone_adds_aircraft?
def can_add_aircraft? = !Viewer.enabled? && (admin? || Setting.anyone_adds_aircraft?)
# Administrators can do everything on every aircraft.
def can?(permission, aircraft)
return false if Viewer.enabled?
admin? || role_for(aircraft)&.can?(permission) || false
end
+63
View File
@@ -0,0 +1,63 @@
# Viewer mode (SAM_VIEWER=true): a read-only copy of an aircraft archive for
# whoever receives a records package (the FAA, a buyer), with no sign-in. It's
# what the package's viewer/docker-compose.yml runs, on that person's own
# computer.
#
# - At start (bin/rails sam:viewer:prepare, from bin/docker-entrypoint), the
# archive at SAM_VIEWER_ARCHIVE is imported, owned by a built-in account.
# - Everyone is that account (Authentication): no sign-in.
# - Nothing can be changed: requests other than GET/HEAD are refused
# (ApplicationController), and no role permission applies (AircraftScoped).
#
# So that it can never open a real installation, it refuses to run when the
# database has any account other than the built-in one: setting SAM_VIEWER on
# a real server stops it rather than exposing its records.
module Viewer
EMAIL = "viewer@sam-viewer.invalid".freeze
class RealAccounts < StandardError
def message = "SAM_VIEWER is on, but this database has user accounts: viewer mode is only for an empty " \
"copy made to look at an archive. Turn SAM_VIEWER off for a real installation."
end
def self.enabled? = ENV["SAM_VIEWER"] == "true"
def self.archive = ENV["SAM_VIEWER_ARCHIVE"].presence
# What was imported, for the banner (kept with the data).
def self.info_path = Pathname(ENV["SAM_VIEWER_INFO"].presence || Rails.root.join("storage/viewer.json"))
def self.real_accounts? = User.where.not(email_address: EMAIL).exists?
# The built-in account everyone browses as (made when first needed). It
# can't sign in by password: nobody knows it.
def self.user
User.find_or_create_by!(email_address: EMAIL) do |u|
u.name = I18n.t("viewer.account_name")
u.password = SecureRandom.base58(40)
end
end
# Checks the database, then imports the archive the first time.
def self.prepare!(output: $stdout)
raise RealAccounts if real_accounts?
owner = user
if Aircraft.exists?
output.puts "Viewer: already imported (#{Aircraft.ordered.pluck(:tail_number).join(', ')})."
elsif archive.nil? || !File.file?(archive)
output.puts "Viewer: no archive at SAM_VIEWER_ARCHIVE (#{archive.inspect}); nothing to show."
else
output.puts "Viewer: importing #{File.basename(archive)}…"
preview = AircraftArchive::Importer.check(archive)
result = AircraftArchive::Importer.new(archive, owner: owner).run
File.write(info_path, { file: File.basename(archive), tail_number: result[:aircraft].tail_number,
exported_at: preview.exported_at&.iso8601 }.to_json)
output.puts "Viewer: imported #{result[:aircraft].tail_number}: #{result[:counts].map { |k, n| "#{n} #{k.tr('_', ' ')}" }.join(', ')}"
end
output.puts "Viewer ready: open http://localhost:3000"
end
# What the banner says: the archive's file and when it was exported.
def self.info
JSON.parse(info_path.read) if info_path.file?
rescue JSON::ParserError
nil
end
end
+14 -9
View File
@@ -76,30 +76,35 @@ class RecordsPackage
"#{image.sub(/:[^:\/]+\z/, '')}:#{version}"
end
# A ready-to-run local viewer, with its own throwaway secret key (never this
# installation's), plain HTTP on localhost.
# A ready-to-run local viewer of the archive: read-only, no account needed
# (viewer mode, see Viewer), reachable only from that computer, with its own
# throwaway secret key (never this installation's).
def viewer_compose
image = viewer_image
archive = "#{@aircraft.tail_number.downcase}.sam.zip"
<<~YAML
# Simple Aircraft Manager on your own computer, to browse #{@aircraft.tail_number.downcase}.sam.zip.
# 1. docker compose up -d
# 2. Open http://localhost:3000 and create the first (admin) account. It asks
# for a one-time setup code: docker compose logs web | grep "Setup code"
# 3. Fleet -> More -> Import from a .sam.zip archive: choose #{@aircraft.tail_number.downcase}.sam.zip
# Stop: docker compose down (add -v to delete this local copy)
# Simple Aircraft Manager on your own computer, showing #{archive} read-only.
# 1. In this folder: docker compose up
# The first start imports the records; wait for "Viewer ready".
# 2. Open http://localhost:3000 (no account needed).
# Stop: Ctrl+C, then docker compose down (add -v to delete this local copy).
# Prepared with software version #{SystemInfo.new.version_label}.#{" Source: #{repository}" if repository}
services:
web:
#{image ? "image: #{image}" : "build: . # no published image known: build from the source code"}
restart: "no"
ports:
- "3000:80"
- "127.0.0.1:3000:80" # this computer only
environment:
SAM_VIEWER: "true"
SAM_VIEWER_ARCHIVE: /import/#{archive}
SECRET_KEY_BASE: #{SecureRandom.hex(64)} # for this local copy only
APP_HOST: localhost:3000
FORCE_SSL: "false"
SOLID_QUEUE_IN_PUMA: "true"
SOLID_QUEUE_SKIP_RECURRING: "true" # no reminders, backups or AD searches
volumes:
- ../#{archive}:/import/#{archive}:ro # the archive next to this folder, in the package
- viewer_storage:/rails/storage
volumes:
viewer_storage:
+11 -4
View File
@@ -45,7 +45,7 @@
<summary class="flex cursor-pointer list-none items-center rounded px-3 py-2 text-lg leading-none hover:bg-white/10 [&::-webkit-details-marker]:hidden" aria-label="<%= t(".menu") %>">☰</summary>
<div class="absolute right-0 z-30 mt-2 w-56 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
<p class="truncate px-4 pt-2 pb-1 text-xs text-slate-500"><%= current_user.email_address %></p>
<%= link_to t(".profile"), edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<% unless Viewer.enabled? %><%= link_to t(".profile"), edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %><% end %>
<%= link_to t(".search"), search_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<%= link_to t(".help"), help_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<% if current_user.admin? %>
@@ -54,7 +54,7 @@
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
<% end %>
<% end %>
<div class="border-t border-slate-100"><%= button_to t(".sign_out"), session_path, method: :delete, class: "block w-full px-4 py-2.5 text-left hover:bg-slate-100", form: { data: { controller: "sign-out", action: "submit->sign-out#clean" } } %></div>
<% unless Viewer.enabled? %><div class="border-t border-slate-100"><%= button_to t(".sign_out"), session_path, method: :delete, class: "block w-full px-4 py-2.5 text-left hover:bg-slate-100", form: { data: { controller: "sign-out", action: "submit->sign-out#clean" } } %></div><% end %>
</div>
</details>
</nav>
@@ -78,9 +78,9 @@
</details>
<% end %>
<%= link_to t(".help"), help_path, class: "hover:text-sky-300" %>
<%= link_to current_user.display_name, edit_profile_path, class: "text-white/70 hover:text-sky-300 hidden sm:inline" %>
<% unless Viewer.enabled? %><%= link_to current_user.display_name, edit_profile_path, class: "text-white/70 hover:text-sky-300 hidden sm:inline" %><% end %>
<%= render "shared/theme_toggle" %>
<%= button_to t(".sign_out"), session_path, method: :delete, class: "rounded bg-white/10 px-2 py-1 hover:bg-white/20", form: { data: { controller: "sign-out", action: "submit->sign-out#clean" } } %>
<% unless Viewer.enabled? %><%= button_to t(".sign_out"), session_path, method: :delete, class: "rounded bg-white/10 px-2 py-1 hover:bg-white/20", form: { data: { controller: "sign-out", action: "submit->sign-out#clean" } } %><% end %>
</nav>
<% end %>
</div>
@@ -92,6 +92,13 @@
</div>
<div class="hidden space-y-1 bg-amber-50 px-4 py-2 text-center text-sm text-amber-900 ring-1 ring-amber-200" data-offline-sync-target="banner" role="status"></div>
<% if Viewer.enabled? %>
<%# Viewer mode: a read-only copy of a records package's archive (see Viewer). %>
<% info = Viewer.info %>
<div class="bg-sky-50 px-4 py-2 text-center text-sm text-sky-900 ring-1 ring-sky-200" role="note" id="viewer-banner">
<%= info ? t("viewer.banner", file: info["file"], date: (info["exported_at"] ? fmt_date(Time.zone.parse(info["exported_at"])) : t("viewer.unknown_date"))) : t("viewer.banner_no_archive") %>
</div>
<% end %>
<main id="main" tabindex="-1" class="mx-auto max-w-7xl px-4 py-6 focus:outline-none">
<%= render "shared/flash" %>
<%= yield %>
+4
View File
@@ -9,6 +9,10 @@ fi
# If running the rails server then create or migrate existing database
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
./bin/rails db:prepare
# Viewer mode (records package): refuse a real database, import the archive.
if [ "${SAM_VIEWER}" == "true" ]; then
./bin/rails sam:viewer:prepare
fi
fi
exec "${@}"
+13 -8
View File
@@ -1641,7 +1641,7 @@ en:
n8_quality_control_and_auditing: 8. Quality control and auditing
every_months_the_responsible_person_html: Every %{audit_interval_months} months the responsible person carries out and records an audit in the system (3.2.8.5). The app checks that the integrity check and backups are passing, the procedures are adopted, signatures are intact, and lists expired certificates and software versions since the last audit. The auditor restores the off-site backup somewhere separate and opens it, compares %{audit_sample_size} randomly chosen entries with their work orders or source documents, reviews the users and roles (disabling accounts no longer needed), and confirms the paper logbooks are kept. Audit results are kept in the system.%{latest}
n9_making_records_available_to: 9. Making records available to the FAA and NTSB
on_request_14_cfr_91: 'On request (14 CFR 91.417(c), 49 CFR 830), the responsible person provides the records package for the aircraft: every logbook entry as a PDF with its electronic signature, a signature register, the full change history, the maintenance status report and the data archive, with a README. Printed copies are produced the same way. Direct access to the system can be offered but isn''t required (3.2.8.6).'
on_request_14_cfr_91: 'On request (14 CFR 91.417(c), 49 CFR 830), the responsible person provides the records package for the aircraft: every logbook entry as a PDF with its electronic signature, a signature register, the full change history, the maintenance status report and the data archive, with a README and a viewer that shows the records, read-only, on the recipient''s own computer. Printed copies are produced the same way. Direct access to the system can be offered but isn''t required (3.2.8.6).'
n10_transfer_of_records: 10. Transfer of records
at_sale_91_419_3_html: "<strong>At sale (91.419, 3.2.8.12):</strong> the buyer receives the records package and the data archive, which another installation of the system can import, together with the paper logbooks. <strong>To another system (3.2.8.9):</strong> records are exported as the data archive and the records package; both systems run side by side until the transfer is checked."
n11_continuity: 11. Continuity
@@ -4208,14 +4208,13 @@ en:
inspections, documents, flights, oil and fuel) the way the owner sees it, run the app on your own computer:
1. Install Docker Desktop (https://www.docker.com/products/docker-desktop/).
2. In a terminal, go to the "viewer" folder of this package and run: docker compose up -d
3. Open http://localhost:3000 and create the first (admin) account. It asks for a one-time setup code,
which this shows (in the same folder): docker compose logs web | grep "Setup code"
4. Choose Fleet -> More -> Import from a .sam.zip archive and select %{archive} from this package (or this whole zip file).
2. Unzip this package, and in a terminal go to its "viewer" folder and run: docker compose up
The first start imports %{archive}; wait for the line "Viewer ready".
3. Open http://localhost:3000. No account is needed: it's a read-only copy.
The copy runs only on your computer and stays separate from the owner's system. Electronic signatures are
shown as imported: compare their fingerprints with signatures.csv and logbook-entries.pdf. To stop it:
docker compose down (add -v to delete the local copy).
The copy runs only on your computer (it can't be reached from other machines), can't be changed, and stays
separate from the owner's system. Electronic signatures are shown as imported: compare their fingerprints with
signatures.csv and logbook-entries.pdf. To stop it: Ctrl+C, then docker compose down (add -v to delete the copy).
%{repository}
not_recorded: not recorded
not_stated: not stated
@@ -4415,6 +4414,12 @@ en:
test:
title: Notifications are working
body: This device will get notifications from Simple Aircraft Manager.
viewer:
account_name: Viewer
read_only: This is a read-only copy of the records; nothing can be changed here.
banner: 'Read-only copy of the records in %{file}, exported %{date}. Nothing here can be changed, and it isn''t connected to the owner''s system.'
banner_no_archive: Read-only viewer. No archive was imported (see the viewer folder's docker-compose.yml).
unknown_date: on an unknown date
shortcuts:
choose:
log_flight: 'Log Flight: choose the aircraft'
+3 -1
View File
@@ -23,7 +23,9 @@ Give it a label and optionally an expiry. Documents only appear if their visibil
## Records package
**Download records package** builds a zip for the FAA, a buyer or a new maintainer: every logbook entry as a PDF with its signatures, a signature register, the change history, the status report, the current recordkeeping procedures, and the data archive. Its README explains each file, links to the source code, and includes a ready-to-run `viewer/docker-compose.yml`: with Docker Desktop, the recipient can run the app on their own computer and import the archive to browse everything.
**Download records package** builds a zip for the FAA, a buyer or a new maintainer: every logbook entry as a PDF with its signatures, a signature register, the change history, the status report, the current recordkeeping procedures, and the data archive. Its README explains each file, links to the source code, and includes a ready-to-run `viewer/docker-compose.yml`. With Docker Desktop, the recipient runs `docker compose up` in that folder and opens http://localhost:3000 to browse everything the way you see it: the archive is imported by itself, and no account is needed.
That copy is a **read-only viewer**: nothing in it can be changed, it can only be reached from their own computer, and it isn't connected to your system. It runs the release of the app that made the package, and shows a banner naming the archive and when it was exported. Electronic signatures appear as imported, to compare with the PDF and signature register.
## Backup and transfer
+14
View File
@@ -0,0 +1,14 @@
# Viewer mode (SAM_VIEWER=true, see Viewer): checks the database has no real
# accounts and imports SAM_VIEWER_ARCHIVE the first time. bin/docker-entrypoint
# runs it before the server starts.
namespace :sam do
namespace :viewer do
desc "Viewer mode: check the database and import the archive"
task prepare: :environment do
abort "SAM_VIEWER isn't on." unless Viewer.enabled?
Viewer.prepare!
rescue Viewer::RealAccounts, AircraftArchive::Error => e
abort "Viewer: #{e.message}"
end
end
end
+7 -6
View File
@@ -82,12 +82,13 @@ class RecordsIntegrityTest < ActionDispatch::IntegrationTest
def zip.text(name) = read(name).force_encoding("UTF-8")
assert_equal %w[README.txt logbook-entries.pdf n12345.sam.zip record-history.csv signatures.csv status-report.html viewer/docker-compose.yml], zip.entries.map(&:name).sort
readme = zip.text("README.txt")
assert_includes readme, 'docker compose logs web | grep "Setup code"'
viewer = YAML.safe_load(zip.text("viewer/docker-compose.yml"))
version = SystemInfo.new.version
assert_equal "barrettefab/simple-aircraft-manager-rails:#{version}", viewer.dig("services", "web", "image") # the release that made it
assert_equal "false", viewer.dig("services", "web", "environment", "FORCE_SSL")
assert_includes zip.text("viewer/docker-compose.yml"), 'grep "Setup code"'
assert_includes readme, "No account is needed: it's a read-only copy."
web = YAML.safe_load(zip.text("viewer/docker-compose.yml")).dig("services", "web")
assert_equal "barrettefab/simple-aircraft-manager-rails:#{SystemInfo.new.version}", web["image"] # the release that made it
assert_equal({ "SAM_VIEWER" => "true", "SAM_VIEWER_ARCHIVE" => "/import/n12345.sam.zip", "SOLID_QUEUE_SKIP_RECURRING" => "true" },
web["environment"].slice("SAM_VIEWER", "SAM_VIEWER_ARCHIVE", "SOLID_QUEUE_SKIP_RECURRING"))
assert_equal [ "127.0.0.1:3000:80" ], web["ports"] # this computer only
assert_includes web["volumes"], "../n12345.sam.zip:/import/n12345.sam.zip:ro"
assert_includes readme, "All 2 logbook entries, oldest first. 1 are signed electronically"
assert_includes readme, "Electronic records since: 2026-01-01"
assert_includes readme, "scans marked \"legacy record\""
+73
View File
@@ -0,0 +1,73 @@
require "test_helper"
# Viewer mode (SAM_VIEWER, see Viewer): what a records package's viewer runs.
# The archive is imported at start; everyone browses it read-only, without
# signing in; and it refuses to run on a database with real accounts.
class ViewerModeTest < ActionDispatch::IntegrationTest
setup do
@saved = ENV.values_at("SAM_VIEWER", "SAM_VIEWER_ARCHIVE", "SAM_VIEWER_INFO")
owner = create_user("owner@example.com")
aircraft = create_aircraft(owner: owner, tail_number: "N12345", tach_time: 1234.5)
aircraft.squawks.create!(priority: 1, issue_reported: "Left nav light out")
@archive = File.join(Dir.mktmpdir, "n12345.sam.zip")
AircraftArchive::Exporter.new(aircraft).write_to(@archive)
Aircraft.destroy_all
User.delete_all # a fresh, empty copy, as in the viewer's own container
ENV["SAM_VIEWER"] = "true"
ENV["SAM_VIEWER_ARCHIVE"] = @archive
ENV["SAM_VIEWER_INFO"] = File.join(File.dirname(@archive), "viewer.json") # this test's own (tests run in parallel)
end
teardown do
ENV["SAM_VIEWER"], ENV["SAM_VIEWER_ARCHIVE"], ENV["SAM_VIEWER_INFO"] = @saved
end
def prepare
out = StringIO.new
Viewer.prepare!(output: out)
out.string
end
test "the archive is imported at start, once" do
assert_match "Viewer: imported N12345", prepare
assert_equal [ "N12345" ], Aircraft.pluck(:tail_number)
assert_match "already imported", prepare
assert_equal 1, Aircraft.count
end
test "anyone browses it without signing in, and can't change anything" do
prepare
get root_path
assert_response :success
assert_select "#viewer-banner", text: /Read-only copy of the records in n12345\.sam\.zip/
assert_includes response.body, "N12345"
assert_select "a[href=?]", new_aircraft_path, 0
assert_select "form[action=?]", session_path, 0 # no sign-out
aircraft = Aircraft.sole
get aircraft_path(aircraft)
assert_response :success
assert_select "a[href=?]", new_aircraft_flight_log_path(aircraft), 0
assert_select "form[action=?]", hours_aircraft_path(aircraft), 0
get aircraft_squawks_path(aircraft)
assert_includes response.body, "Left nav light out"
post aircraft_flight_logs_path(aircraft), params: { flight_log: { date: Date.current, tach_out: 1234.5, tach_in: 1235.5 } }
assert_equal "This is a read-only copy of the records; nothing can be changed here.", flash[:alert]
assert_equal 0, aircraft.flight_logs.count
patch hours_aircraft_path(aircraft), params: { tach_time: 2000 }
assert_equal 1234.5, aircraft.reload.tach_time
delete session_path
get root_path
assert_response :success # still in
end
test "it refuses to run on a database with real accounts" do
create_user("someone@example.com")
assert_raises(Viewer::RealAccounts) { prepare }
assert_equal 0, Aircraft.count
get root_path
assert_response :service_unavailable
assert_includes response.body, "SAM_VIEWER is on, but this database has user accounts"
end
end