Initial commit: Rails port of Simple Aircraft Manager

Rails 8.1 + SQLite rewrite of marbindrakon/simple-aircraft-manager,
designed to self-host as a single container (Solid Queue/Cache/Cable,
Active Storage on disk, Hotwire + importmap, Tailwind).

- Airworthiness engine ported from health/services.py (ADs, grounding
  squawks, inspection recurrency, component replacement)
- Hours updates and flight logs cascading to in-service components,
  optional airworthiness enforcement
- Components, squawks, ADs, inspections, logbook, documents, major
  records, oil/fuel consumption stats and charts, activity log
- Admin/owner/pilot RBAC and public share links (status/maintenance)
- Docker Compose and Kamal deployment, env-driven production config
- Service and integration tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 17:59:08 -05:00
commit 38df19c331
264 files changed
+8365

No files matched your search

View File
Whitespace-only changes.
@@ -0,0 +1,46 @@
# Scopes a controller to one aircraft the current user can access and exposes
# role helpers. Unknown and inaccessible aircraft both 404 (enumeration-safe).
#
# Access matrix (mirrors the original):
# admin – everything
# owner – everything on their aircraft
# pilot – view all; update hours; create squawks, notes, oil/fuel, flight logs
module AircraftScoped
extend ActiveSupport::Concern
included do
before_action :set_aircraft
helper_method :current_role, :owner?, :can_write?
end
private
def aircraft_param = params[:aircraft_id]
def set_aircraft
@aircraft = current_user.accessible_aircraft.find(aircraft_param)
end
def current_role
@current_role ||= current_user.role_for(@aircraft)
end
# Owner-level write access (admins included).
def owner? = current_role.in?(%w[admin owner])
alias_method :can_write?, :owner?
def require_owner!
return if owner?
redirect_back fallback_location: aircraft_path(@aircraft),
alert: "Only owners can do that."
end
# Returns id only if it belongs to the given (aircraft-scoped) relation; else nil.
def scoped_id(scope, id)
id.present? && scope.where(id: id).exists? ? id : nil
end
def log_event(category, name, notes: nil)
@aircraft.log_event!(category, name, notes: notes)
end
end
+38
View File
@@ -0,0 +1,38 @@
# ADs and inspection types are shared reference data that can apply to many
# aircraft. From an aircraft's page we only ever touch *this* aircraft's links:
# the airframe itself and/or some of its components.
module Applicability
extend ActiveSupport::Concern
private
def apply_applicability(record, to_airframe:, component_ids:)
mine = @aircraft.components.where(id: Array(component_ids).compact_blank).to_a
others = record.components.where.not(aircraft_id: @aircraft.id).to_a
record.components = others + mine
if to_airframe
record.aircraft << @aircraft unless record.aircraft.include?(@aircraft)
else
record.aircraft.delete(@aircraft)
end
# Never let a record silently drop off this aircraft entirely.
record.aircraft << @aircraft if mine.empty? && !to_airframe
end
def detach_from_aircraft(record)
record.aircraft.delete(@aircraft)
record.components.delete(*record.components.where(aircraft_id: @aircraft.id))
record.destroy if record.aircraft.empty? && record.components.empty? && orphan_deletable?(record)
end
def orphan_deletable?(record)
case record
when AirworthinessDirective then record.ad_compliances.none?
when InspectionType then record.inspection_records.none?
else false
end
end
def applies_to_airframe? = params[:applies_to_airframe] == "1"
def applicable_component_ids = params[:component_ids]
end
@@ -0,0 +1,52 @@
module Authentication
extend ActiveSupport::Concern
included do
before_action :require_authentication
helper_method :authenticated?
end
class_methods do
def allow_unauthenticated_access(**options)
skip_before_action :require_authentication, **options
end
end
private
def authenticated?
resume_session
end
def require_authentication
resume_session || request_authentication
end
def resume_session
Current.session ||= find_session_by_cookie
end
def find_session_by_cookie
Session.find_by(id: cookies.signed[:session_id]) if cookies.signed[:session_id]
end
def request_authentication
session[:return_to_after_authenticating] = request.url
redirect_to new_session_path
end
def after_authentication_url
session.delete(:return_to_after_authenticating) || root_url
end
def start_new_session_for(user)
user.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |session|
Current.session = session
cookies.signed.permanent[:session_id] = { value: session.id, httponly: true, same_site: :lax }
end
end
def terminate_session
Current.session.destroy
cookies.delete(:session_id)
end
end