mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
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>
74 lines
3.0 KiB
Ruby
74 lines
3.0 KiB
Ruby
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
|