diff --git a/.ruby-version b/.ruby-version index ab96aa9..042302e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.2.3 +ruby-4.0.9 diff --git a/Dockerfile b/Dockerfile index e38463d..c710e49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html # Make sure RUBY_VERSION matches the Ruby version in .ruby-version -ARG RUBY_VERSION=3.2.3 +ARG RUBY_VERSION=4.0.9 FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base # Rails app lives here @@ -65,6 +65,13 @@ RUN groupadd --system --gid 1000 rails && \ chown -R rails:rails db log storage tmp USER 1000:1000 +# Shown on the admin About page: docker build --build-arg APP_REVISION=$(git rev-parse --short HEAD) \ +# --build-arg APP_BUILT_AT=$(date -u +%FT%TZ) … (last, so it doesn't bust the layer cache) +ARG APP_REVISION="" +ARG APP_BUILT_AT="" +ENV APP_REVISION=$APP_REVISION \ + APP_BUILT_AT=$APP_BUILT_AT + # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] diff --git a/Gemfile b/Gemfile index 1e78e09..5a370a0 100644 --- a/Gemfile +++ b/Gemfile @@ -64,9 +64,9 @@ end gem "chartkick", "~> 5.2" -gem "json", "~> 2.10" +gem "json", "~> 3.1" -gem "roo", "~> 2.10" +gem "roo", "~> 4.0" gem "csv", "~> 3.3" @@ -75,7 +75,7 @@ gem "caxlsx", "~> 4.5", group: :test gem "webmock", "~> 3.34", group: :test gem "pdf-reader", "~> 2.16" -gem "rubyzip", ">= 2.4", "< 3" # aircraft archives (.sam.zip) +gem "rubyzip", "~> 3.7" # aircraft archives (.sam.zip) gem "anthropic", "~> 2.6" # AI logbook transcription (Claude) gem "commonmarker", "~> 2.10" # Markdown in notes diff --git a/Gemfile.lock b/Gemfile.lock index bbbb0a4..800be3e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,7 +114,7 @@ GEM marcel (~> 1.0) nokogiri (~> 1.10, >= 1.10.4) rubyzip (>= 2.4, < 4) - chartkick (5.2.1) + chartkick (5.3.0) commonmarker (2.10.1-aarch64-linux) commonmarker (2.10.1-aarch64-linux-musl) commonmarker (2.10.1-arm-linux-gnu) @@ -171,7 +171,7 @@ GEM prism (>= 1.3.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - json (2.21.2) + json (3.1.0) json-jwt (1.17.2) activesupport (>= 4.2) aes_key_wrap @@ -225,7 +225,7 @@ GEM net-ssh (>= 5.0.0, < 9.0.0) net-smtp (0.5.2) net-protocol - net-ssh (7.3.8) + net-ssh (7.3.9) logger nio4r (2.7.5) nokogiri (1.19.7-aarch64-linux-gnu) @@ -267,10 +267,10 @@ GEM tzinfo validate_url webfinger (~> 2.0) - opentelemetry-api (1.8.0) + opentelemetry-api (1.11.1) logger ostruct (0.6.3) - parallel (1.28.0) + parallel (2.3.0) parser (3.3.13.0) ast (~> 2.4.1) racc @@ -343,7 +343,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.4.2) - rbs (4.1.3) + rbs (4.2.0) logger prism (>= 1.6.0) tsort @@ -356,9 +356,12 @@ GEM reline (0.7.0) io-console (~> 0.5) rexml (3.4.4) - roo (2.10.1) + roo (4.0.0) + base64 (~> 0.2) + csv (~> 3) + logger (~> 1) nokogiri (~> 1) - rubyzip (>= 1.3.0, < 3.0.0) + rubyzip (>= 3.0.0, < 4.0.0) rubocop (1.92.2) json (>= 2.3) language_server-protocol (~> 3.17.0.2) @@ -388,15 +391,14 @@ GEM rubocop-performance (>= 1.24) rubocop-rails (>= 2.30) ruby-progressbar (1.13.0) - rubyzip (2.4.1) + rubyzip (3.7.0) securerandom (0.4.1) - selenium-webdriver (4.44.0) + selenium-webdriver (4.52.0) base64 (~> 0.2) logger (~> 1.4) - rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 4.0) websocket (~> 1.0) - solid_cable (3.0.12) + solid_cable (4.1.0) actioncable (>= 7.2) activejob (>= 7.2) activerecord (>= 7.2) @@ -427,7 +429,7 @@ GEM net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) ostruct - standardwebhooks (1.0.1) + standardwebhooks (1.1.0) stimulus-rails (1.3.4) railties (>= 6.0.0) swd (2.0.3) @@ -438,13 +440,13 @@ GEM tailwindcss-rails (4.7.0) railties (>= 7.0.0) tailwindcss-ruby (~> 4.0) - tailwindcss-ruby (4.3.3) - tailwindcss-ruby (4.3.3-aarch64-linux-gnu) - tailwindcss-ruby (4.3.3-aarch64-linux-musl) - tailwindcss-ruby (4.3.3-arm64-darwin) - tailwindcss-ruby (4.3.3-x86_64-darwin) - tailwindcss-ruby (4.3.3-x86_64-linux-gnu) - tailwindcss-ruby (4.3.3-x86_64-linux-musl) + tailwindcss-ruby (4.3.4) + tailwindcss-ruby (4.3.4-aarch64-linux-gnu) + tailwindcss-ruby (4.3.4-aarch64-linux-musl) + tailwindcss-ruby (4.3.4-arm64-darwin) + tailwindcss-ruby (4.3.4-x86_64-darwin) + tailwindcss-ruby (4.3.4-x86_64-linux-gnu) + tailwindcss-ruby (4.3.4-x86_64-linux-musl) thor (1.5.0) thruster (0.1.27) thruster (0.1.27-aarch64-linux) @@ -511,7 +513,7 @@ DEPENDENCIES csv (~> 3.3) debug importmap-rails - json (~> 2.10) + json (~> 3.1) kamal omniauth (~> 2.1) omniauth-rails_csrf_protection (~> 2.0) @@ -520,9 +522,9 @@ DEPENDENCIES propshaft puma (>= 5.0) rails (~> 8.1.0) - roo (~> 2.10) + roo (~> 4.0) rubocop-rails-omakase - rubyzip (>= 2.4, < 3) + rubyzip (~> 3.7) selenium-webdriver solid_cable solid_cache @@ -569,7 +571,7 @@ CHECKSUMS builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef caxlsx (4.5.0) sha256=e3d98d859f148df05d5462086b5079b523f29c1766b569535f1d68629ce743ff - chartkick (5.2.1) sha256=2848d7de87189f30f28d077eb0bbdebc8a1f0f6f81de1ded95008fe564369949 + chartkick (5.3.0) sha256=19a2bba39decf54c4939d3f31460535f8814c85045672ba2ed616c6897325b00 commonmarker (2.10.1-aarch64-linux) sha256=3ab9e7027d2350364bdc541680cc28e21011b2950abf7d08ac29093fa691bdc3 commonmarker (2.10.1-aarch64-linux-musl) sha256=98e6d1a03ba708438d804702e3c25f3423bff21a1e9975280eb265d889677dfc commonmarker (2.10.1-arm-linux-gnu) sha256=dc1ce6cfe5547d2814351ef306d5d1dd05f9c08ad405c76baa94748326c83b7f @@ -604,7 +606,7 @@ CHECKSUMS importmap-rails (2.2.3) sha256=7101be2a4dc97cf1558fb8f573a718404c5f6bcfe94f304bf1f39e444feeb16a io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5 irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3 - json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a + json (3.1.0) sha256=3ce7ccf8fde58960177a3a756c31f292a4c1e1dedee884547096a5b0604e3bd8 json-jwt (1.17.2) sha256=97e37c1c3e22e9e1d74a1c0d77319c5cdc8a636226e5dbb1664b0b34eddcf1c9 kamal (2.12.0) sha256=c51d1ab085e515470f98d0c0f043637122b5ebf76e8b610cb1fbbed0b7f9b8fa language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0 @@ -624,7 +626,7 @@ CHECKSUMS net-scp (4.2.1) sha256=5c9ff6743da37eef6746f248043d97d2bbf3910a4694ec8e372326ec588c2394 net-sftp (4.1.1) sha256=dc2019e59e3e3552943b576f14cb0201ec55823935b967e10dcda169b04e4573 net-smtp (0.5.2) sha256=35103cc04d6b2d94632f9928ede07483c24b70b9c0db1f231fea43909b678f3c - net-ssh (7.3.8) sha256=16bb1fccc4d9a580decdeea8ddb98e8544df29b7e6ac8cb94d4b379cfe4bee9f + net-ssh (7.3.9) sha256=f91bf1e05c5366d25817d17936e25e6f9a90e373b17c8d7a26f9382acf7d4cb3 nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1 nokogiri (1.19.7-aarch64-linux-gnu) sha256=8f5e15d299602456406e1f03a9f3456cceb33a0722811e818d2ee2214eb4c84a nokogiri (1.19.7-aarch64-linux-musl) sha256=efe0c3602e6e54521bc21c681930ce5568e2d11203de17400710b2b3ca2e4cb4 @@ -638,9 +640,9 @@ CHECKSUMS omniauth-rails_csrf_protection (2.0.1) sha256=c6e3204d7e3925bb537cb52d50fdfc9f05293f1a9d87c5d4ab4ca3a39ba8c32d omniauth_openid_connect (0.8.0) sha256=1f2f3890386e2a742221cee0d2e903b78d874e6fab9ea3bfa31c1462f4793d25 openid_connect (2.5.0) sha256=659aff8edce0907798e3f6837e5f27ae2937ae8735216f3e900ab8daa29e39c4 - opentelemetry-api (1.8.0) sha256=3af51183daf0f56a164bc1579782245be70a40678566b9a393cbe5af28ea87c6 + opentelemetry-api (1.11.1) sha256=d07f9987ea6240b3fd5ed5dd7450f93c58e403e0553e804069c23ae18ba61ff7 ostruct (0.6.3) sha256=95a2ed4a4bd1d190784e666b47b2d3f078e4a9efda2fccf18f84ddc6538ed912 - parallel (1.28.0) sha256=33e6de1484baf2524792d178b0913fc8eb94c628d6cfe45599ad4458c638c970 + parallel (2.3.0) sha256=f75a3e904101ce6a1ccb6b8dc800cbafd42166d83330192438dcf29395167a6f parser (3.3.13.0) sha256=e02f9b63c2fe05b0c68f692ba4df89b3cb113b663964f75d988fbebfd6c3deca pdf-reader (2.16.0) sha256=bf1b5564c085264d8279bde3cf1467778b75841494d20c0fe7da3dad475f3732 pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570 @@ -663,22 +665,22 @@ CHECKSUMS railties (8.1.4.1) sha256=ff2ef4b5a62cbc89811f88be11c776e2ed71b14dd012eae6a494d37994aa9782 rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701 - rbs (4.1.3) sha256=0c4474a9751cdc14364bfad0b3e53678323bbdc2c31683b0445932867dbab8c4 + rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674 rdoc (8.1.0) sha256=befc37880a5cfd36dcb176c748b5fd5ee39dd3536a75e81824e4972ce230f60a regexp_parser (2.13.1) sha256=5aedb6b7c35688f51e86eef17a15374dfd287c83f4ca644b2c5f3ec50a33b44b reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142 - roo (2.10.1) sha256=cbb43bc955f9c110e74b721c835fb9bd3515b63af88ec709ac87fbf30f8be70e + roo (4.0.0) sha256=83e25e85add9313fcf9d1e6c88720ce2bba2fa22590375eca23092be1d0690e8 rubocop (1.92.2) sha256=14fb31eed143a0dc6f78186c550c1715e81cd38f59d05d1165050e445c1f5382 rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db rubocop-performance (1.27.0) sha256=eeeb1374d062a368ee1c787b70eb0b0cc4b184cb1f8565f424760946146d61ce rubocop-rails (2.38.0) sha256=6e2b7c532efa95e3050371bec20b8f5b025662acead8bc70ee31f0e3e6fa2f06 rubocop-rails-omakase (1.1.0) sha256=2af73ac8ee5852de2919abbd2618af9c15c19b512c4cfc1f9a5d3b6ef009109d ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33 - rubyzip (2.4.1) sha256=8577c88edc1fde8935eb91064c5cb1aef9ad5494b940cf19c775ee833e075615 + rubyzip (3.7.0) sha256=65c19294da75297a939006f3516deacc33185fbd721ff1954f7a231db6d3e121 securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1 - selenium-webdriver (4.44.0) sha256=6f1df072529af369589c46f0e01132952aabb250cfd683c274d74dc1eb5d8477 - solid_cable (3.0.12) sha256=a168a54731a455d5627af48d8441ea3b554b8c1f6e6cd6074109de493e6b0460 + selenium-webdriver (4.52.0) sha256=5d45ba100ea8b57f5a8c25979a636d48b4c60c39973478930d78e884bdeecd2d + solid_cable (4.1.0) sha256=828e3d509207b82b4f05f4e9c85f696994710679b52d511aa7f97ebd212d3226 solid_cache (1.0.10) sha256=bc05a2fb3ac78a6f43cbb5946679cf9db67dd30d22939ededc385cb93e120d41 solid_queue (1.7.2) sha256=a22685e1d2ee14ce7b4e5d4592c9d8e837951884c51555609dee58679ed03325 sqlite3 (2.10.2-aarch64-linux-gnu) sha256=e9aea2c2b3476fc875dd8a89313a9a2862818519c0186bfb5b56d6f57bb08d98 @@ -690,17 +692,17 @@ CHECKSUMS sqlite3 (2.10.2-x86_64-linux-gnu) sha256=ca92731ab464df9cae503fa1a439a549e2724f6953c8c05a7769b59366e38f15 sqlite3 (2.10.2-x86_64-linux-musl) sha256=b9f8fc62f3e0eb8966b41de251b492b4c8e9d1b23559beb6e150ad7f8d590941 sshkit (1.25.1) sha256=be3f10b9d6eb0b44d5eaba3f7cbe41bc6bb894bce4339688ac20124391455b78 - standardwebhooks (1.0.1) sha256=35db391599d9318747e1e75e77b96236b3fc25241b92387c9a8d31bd974f3d7d + standardwebhooks (1.1.0) sha256=356ba711c14def4fb27310e4163b26bd5cccf325212c3440cabadd825e4be11f stimulus-rails (1.3.4) sha256=765676ffa1f33af64ce026d26b48e8ffb2e0b94e0f50e9119e11d6107d67cb06 swd (2.0.3) sha256=4cdbe2a4246c19f093fce22e967ec3ebdd4657d37673672e621bf0c7eb770655 tailwindcss-rails (4.7.0) sha256=9b09bd677d7cd226fc8ff3f7d2d91c6dc6c3da75dd74dc4cab5f94711f69ba41 - tailwindcss-ruby (4.3.3) sha256=ee0a64030749862deb501acab4c4aaf5adbee13865746a33299d46d7b5d0952a - tailwindcss-ruby (4.3.3-aarch64-linux-gnu) sha256=c86d6dd3eccc85fe0d792a832b06f2bf3c0a7a83b399308aeb9d8f5725f42a6a - tailwindcss-ruby (4.3.3-aarch64-linux-musl) sha256=72b77ca9edea82383dd09510ab520a122e3cb9f9864ca5b38e27698098d2b899 - tailwindcss-ruby (4.3.3-arm64-darwin) sha256=776c51fc734aac64bde0c253eadd2ed2e610b2ba0d8e760501fe7cbec55fd6cf - tailwindcss-ruby (4.3.3-x86_64-darwin) sha256=483011e5d3792cf5ef4afdfb04c1d95daccf42c30cdb6fe53b77520954e7b922 - tailwindcss-ruby (4.3.3-x86_64-linux-gnu) sha256=2337017ff8b02698480eae1e9637cf01faa0e4824db89d067a13c5a5ee38c9b2 - tailwindcss-ruby (4.3.3-x86_64-linux-musl) sha256=27d478c417bcf73828e5b544744c5bdfd5b5cb54f1a266fc4f185281c32efe6c + tailwindcss-ruby (4.3.4) sha256=9efb1c084c43cb53578b708f66c3f541616d49f094b1c4881691b4f332356b55 + tailwindcss-ruby (4.3.4-aarch64-linux-gnu) sha256=09c647d5434b4be5c76ee607c1f52817f70f10c44bcfd9241ceeeaf783057d6b + tailwindcss-ruby (4.3.4-aarch64-linux-musl) sha256=4495aa1a28613661dbe3a23612e28a3f8cb6ef747c16139e12d7c19ac3f38b71 + tailwindcss-ruby (4.3.4-arm64-darwin) sha256=8165d282ed3246b96cca271b097cd03412b2359c54169532e9697230c882ea96 + tailwindcss-ruby (4.3.4-x86_64-darwin) sha256=1d0c718597ae57988ceda20e72abfe42e7bf948b44e1d5b6966f0af18810fe70 + tailwindcss-ruby (4.3.4-x86_64-linux-gnu) sha256=d6654344039ef34114e100c7abbfbecf213956a18676801e3c92d3d98c00fc56 + tailwindcss-ruby (4.3.4-x86_64-linux-musl) sha256=fca0843ab85b0c79f608a82210551b65940c991abc8d7a7f7b3276b42530e012 thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73 thruster (0.1.27) sha256=5fd3855192bb4e8d13db69ae5f70d39f2dfd88fe0394fa372104996edf0bb599 thruster (0.1.27-aarch64-linux) sha256=c50789f2dcd4dfa072c4719f99c38dea5d47ebb60ad0cc1fd1996b2266ecfd22 @@ -727,4 +729,4 @@ CHECKSUMS zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5 BUNDLED WITH - 4.0.8 + 4.0.20 diff --git a/app/controllers/admin/about_controller.rb b/app/controllers/admin/about_controller.rb new file mode 100644 index 0000000..a81f053 --- /dev/null +++ b/app/controllers/admin/about_controller.rb @@ -0,0 +1,7 @@ +class Admin::AboutController < ApplicationController + before_action :require_admin! + + def show + @info = SystemInfo.new + end +end diff --git a/app/models/system_info.rb b/app/models/system_info.rb new file mode 100644 index 0000000..2c6f2b4 --- /dev/null +++ b/app/models/system_info.rb @@ -0,0 +1,101 @@ +# What the admin About page shows: versions, configuration (never secrets) +# and a health summary of the database, file storage and background jobs. +class SystemInfo + KEY_GEMS = %w[ + puma thruster propshaft importmap-rails turbo-rails stimulus-rails tailwindcss-rails tailwindcss-ruby + solid_queue solid_cache solid_cable sqlite3 chartkick commonmarker anthropic + omniauth omniauth_openid_connect rubyzip roo pdf-reader bcrypt + ].freeze + + DATABASES = { "Main" => :primary, "Cache" => :cache, "Jobs" => :queue, "Cable" => :cable }.freeze + + # Set by the Docker build (see Dockerfile); in development, read from git. + def revision + @revision ||= ENV["APP_REVISION"].presence || + (Rails.root.join(".git").exist? && `git -C #{Rails.root} rev-parse --short HEAD 2>/dev/null`.strip.presence) || + "unknown" + end + + def built_at + Time.zone.parse(ENV["APP_BUILT_AT"].to_s) if ENV["APP_BUILT_AT"].present? + rescue ArgumentError + nil + end + + def booted_at = Rails.application.config.x.booted_at + + def runtime + { + "Ruby" => "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})", + "YJIT" => defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? "on" : "off", + "Rails" => Rails.version, + "SQLite" => SQLite3::SQLITE_VERSION, + "Bundler" => Bundler::VERSION, + "Environment" => Rails.env, + "Time zone" => Time.zone.name + } + end + + def key_gems + KEY_GEMS.filter_map { |name| (spec = specs[name]) && [ name, spec.version.to_s ] } + end + + def all_gems = specs.values.sort_by(&:name).map { [ _1.name, _1.version.to_s ] } + + # Configured or not; secret values are never read out. + def features + { + "Single sign-on" => Sso.enabled? ? "#{Sso.label}#{', password sign-in off' unless Sso.password_login?}" : "not configured", + "AI logbook transcription" => ENV["ANTHROPIC_API_KEY"].present? ? "on (#{LogbookTranscriber::MODEL})" : "no API key", + "Password-reset email" => ENV["SMTP_ADDRESS"].present? ? "SMTP" : "not configured", + "HTTPS enforced" => Rails.application.config.force_ssl ? "yes" : "no", + "File storage" => ActiveStorage::Blob.service.class.name.demodulize.delete_suffix("Service") + } + end + + def databases + DATABASES.filter_map do |label, name| + config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name.to_s) + next unless config + path = Rails.root.join(config.database.to_s) + [ label, path.exist? ? Dir["#{path}*"].sum { File.size(_1) } : nil ] + end + end + + def record_counts + { "Users" => User.count, "Aircraft" => Aircraft.count, "Documents" => Document.count, + "Logbook entries" => LogbookEntry.count, "Flights" => FlightLog.count, "Squawks" => Squawk.count } + end + + # Bytes saved by storing identical files once, estimated from checksums. + def storage + blobs = ActiveStorage::Blob + total = blobs.sum(:byte_size) + unique = blobs.group(:checksum).maximum(:byte_size).values.sum + { files: blobs.count, bytes: total, shared_bytes: total - unique, free_bytes: free_disk_bytes } + end + + def jobs + return unless defined?(SolidQueue) && SolidQueue::Job.table_exists? + { + workers: SolidQueue::Process.where(last_heartbeat_at: 5.minutes.ago..).count, + ready: SolidQueue::ReadyExecution.count, + scheduled: SolidQueue::ScheduledExecution.count, + failed: SolidQueue::FailedExecution.count + } + rescue ActiveRecord::ActiveRecordError + nil + end + + private + + def specs = Gem.loaded_specs + + def free_disk_bytes + root = ActiveStorage::Blob.service.try(:root) or return + line = IO.popen([ "df", "-Pk", root.to_s ], err: File::NULL, &:read).lines.last + line.split[3].to_i * 1024 if line + rescue SystemCallError + nil + end +end diff --git a/app/views/admin/about/_pairs.html.erb b/app/views/admin/about/_pairs.html.erb new file mode 100644 index 0000000..2661f51 --- /dev/null +++ b/app/views/admin/about/_pairs.html.erb @@ -0,0 +1,8 @@ +
+ <% pairs.each do |label, value| %> +
+
<%= label %>
+
<%= value.presence || "—" %>
+
+ <% end %> +
diff --git a/app/views/admin/about/show.html.erb b/app/views/admin/about/show.html.erb new file mode 100644 index 0000000..df7bdbd --- /dev/null +++ b/app/views/admin/about/show.html.erb @@ -0,0 +1,75 @@ +<% content_for :title, "About" %> +<% info = @info %> + +

About

+

Simple Aircraft Manager: what's running, and how it's set up.

+ +
+
+
+

Version

+

<%= info.revision %>

+
+
+
Built
<%= info.built_at ? l(info.built_at.in_time_zone, format: :short) : "—" %>
+
Started
<%= l(info.booted_at.in_time_zone, format: :short) %>
+
Uptime
<%= distance_of_time_in_words(info.booted_at, Time.current) %>
+
+
+
+ +
+
+

Runtime

+ <%= render "pairs", pairs: info.runtime %> +
+ +
+

Features

+ <%= render "pairs", pairs: info.features %> +
+ +
+

Key components

+ <%= render "pairs", pairs: info.key_gems %> +
+ +
+
+

Storage

+ <% s = info.storage %> + <%= render "pairs", pairs: [ + [ "Uploaded files", "#{number_with_delimiter(s[:files])} (#{number_to_human_size(s[:bytes])})" ], + [ "Saved by storing duplicates once", number_to_human_size(s[:shared_bytes]) ], + [ "Free disk space", s[:free_bytes] && number_to_human_size(s[:free_bytes]) ] + ] + info.databases.map { |label, bytes| [ "#{label} database", bytes && number_to_human_size(bytes) ] } %> +
+ +
+

Background jobs

+ <% if (j = info.jobs) %> + <%= render "pairs", pairs: [ + [ "Workers running", j[:workers].zero? ? tag.span("none", class: "badge-red") : j[:workers] ], + [ "Waiting", j[:ready] ], [ "Scheduled", j[:scheduled] ], + [ "Failed", j[:failed].positive? ? tag.span(j[:failed], class: "badge-orange") : 0 ] + ] %> + <% else %> + <%= empty_state "Job queue not available." %> + <% end %> +
+ +
+

Records

+ <%= render "pairs", pairs: info.record_counts.transform_values { number_with_delimiter(_1) } %> +
+
+
+ +
+ All gems (<%= info.all_gems.size %>) +
+ <% info.all_gems.each do |name, version| %> +
<%= name %><%= version %>
+ <% end %> +
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5909614..cfb3bf2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -37,7 +37,7 @@ <%= link_to "Profile", edit_profile_path, class: "block px-4 py-2.5 hover:bg-slate-100" %> <% if current_user.admin? %>

Admin

- <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ] ].each do |label, path| %> + <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "About", admin_about_path ] ].each do |label, path| %> <%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %> <% end %> <% end %> @@ -53,7 +53,7 @@ Admin
- <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ] ].each do |label, path| %> + <% [ [ "Users", admin_users_path ], [ "Component Types", admin_component_types_path ], [ "Airports", admin_airports_path ], [ "About", admin_about_path ] ].each do |label, path| %> <%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %> <% end %>
diff --git a/config/application.rb b/config/application.rb index 13e19e4..0d166a6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ Bundler.require(*Rails.groups) module SimpleAircraftManager class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 8.0 + config.load_defaults 8.1 # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. diff --git a/config/initializers/booted_at.rb b/config/initializers/booted_at.rb new file mode 100644 index 0000000..4ab236e --- /dev/null +++ b/config/initializers/booted_at.rb @@ -0,0 +1,2 @@ +# Shown on the admin About page (uptime). +Rails.application.config.x.booted_at = Time.current diff --git a/config/routes.rb b/config/routes.rb index ccff660..9a618d3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,7 @@ Rails.application.routes.draw do get "shared/:token", to: "shared#show", as: :shared namespace :admin do + get "about", to: "about#show" resources :users, except: :show resources :component_types, except: :show resources :airports, except: :show do diff --git a/test/integration/admin_about_test.rb b/test/integration/admin_about_test.rb new file mode 100644 index 0000000..8f38fd1 --- /dev/null +++ b/test/integration/admin_about_test.rb @@ -0,0 +1,42 @@ +require "test_helper" + +class AdminAboutTest < ActionDispatch::IntegrationTest + test "admins see versions and setup; nobody else can" do + sign_in create_user("pilot@example.com") + get admin_about_path + assert_redirected_to root_path + + admin = create_user("admin@example.com", admin: true) + sign_in admin + get root_path + assert_select "a[href='#{admin_about_path}']", text: "About" + + with_env("APP_REVISION" => "abc1234", "APP_BUILT_AT" => "2026-11-07T12:00:00Z", "ANTHROPIC_API_KEY" => "sk-ant-secret") do + get admin_about_path + end + assert_response :success + assert_select "[data-revision]", text: "abc1234" + body = response.body + [ RUBY_VERSION, Rails.version, SQLite3::SQLITE_VERSION, Gem.loaded_specs["turbo-rails"].version.to_s ].each { assert_includes body, _1 } + assert_includes body, "on (#{LogbookTranscriber::MODEL})" + refute_includes body, "sk-ant-secret" # configured or not; never the value + assert_select "summary", text: /All gems \(\d+\)/ + end + + test "storage figures count files stored once" do + info = SystemInfo.new + 2.times { |i| ActiveStorage::Blob.create_and_upload!(io: StringIO.new("same bytes"), filename: "copy#{i}.txt") } + ActiveStorage::Blob.create_and_upload!(io: StringIO.new("other"), filename: "other.txt") + assert_equal({ files: 3, bytes: 25, shared_bytes: 10 }, info.storage.slice(:files, :bytes, :shared_bytes)) + end + + private + + def with_env(vars) + saved = vars.keys.to_h { [ _1, ENV[_1] ] } + vars.each { ENV[_1] = _2 } + yield + ensure + saved.each { ENV[_1] = _2 } + end +end