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

+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