mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
What people can do on an aircraft now comes from their role there, and administrators set what each role allows (Admin → Roles). - Roles are installation-wide sets of permissions (31, grouped as flying, squawks and notes, maintenance records, imports and exports, the aircraft, notifications). Seeing an aircraft's records needs none. - Built in: Owner (always every permission, so an aircraft can always be managed), Mechanic (shop maintenance: logbook, signing, components, inspections, ADs, squawks, reminders), Pilot (what pilots could do before) and Viewer (view only). Administrators can change all but Owner's, and add their own; a role can be deleted once nobody has it. - Existing owners and pilots keep exactly what they could do. - Admin → Users → a user lists their role on every aircraft, to change, remove or add. On the aircraft's Access page, anyone who manages people hands out roles, but only an Owner can give or take away Owner, nobody changes their own (except administrators), and an aircraft always keeps an Owner (AircraftAccess). - Controllers declare the permission each action needs; a request that changes something with none declared is refused (and raises in development and tests), and a test walks every route to check. - Weekly reminders and overdue alerts go to roles that get reminders; the DRS reminder also needs Manage ADs. The API follows the person's role; its owners_only error is now not_permitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.4 KiB
Ruby
58 lines
2.4 KiB
Ruby
# Owner-only bulk import of historical flights: upload → preview → confirm.
|
|
class FlightImportsController < ApplicationController
|
|
include AircraftScoped
|
|
include StoredUpload
|
|
requires_permission :import_flights
|
|
|
|
def new; end
|
|
|
|
# Store the upload, then redirect to the preview (Turbo requires a redirect after a form POST).
|
|
def create
|
|
token, error = store_upload(params[:file])
|
|
return redirect_to_upload(error) if error
|
|
redirect_to aircraft_flight_import_path(@aircraft, token: token, filename: params[:file].original_filename,
|
|
starting_tach: params[:starting_tach].presence,
|
|
starting_hobbs: params[:starting_hobbs].presence)
|
|
end
|
|
|
|
# Preview.
|
|
def show
|
|
@token = params[:token].to_s
|
|
return redirect_to_upload(t("flash.uploads.expired")) unless stored_file?(@token)
|
|
|
|
@filename = params[:filename].to_s
|
|
@starting_tach = params[:starting_tach].presence
|
|
@starting_hobbs = params[:starting_hobbs].presence
|
|
@import = build_import(@token, @filename)
|
|
@import.rows # parse now so header errors surface here
|
|
rescue FlightImport::Error => e
|
|
redirect_to_upload(e.message)
|
|
end
|
|
|
|
def confirm
|
|
token = params[:token].to_s
|
|
return redirect_to_upload(t("flash.uploads.expired")) unless stored_file?(token)
|
|
|
|
import = build_import(token, params[:filename], starting_tach: params[:starting_tach], starting_hobbs: params[:starting_hobbs])
|
|
count = import.import!(user: current_user, update_aircraft_hours: params[:update_aircraft_hours] == "1")
|
|
discard_upload(token)
|
|
redirect_to aircraft_flight_logs_path(@aircraft), notice: t("flash.flight_imports.imported_flights", count: count)
|
|
rescue FlightImport::Error => e
|
|
redirect_to new_aircraft_flight_import_path(@aircraft), alert: e.message
|
|
rescue AircraftGroundedError
|
|
redirect_to aircraft_flight_logs_path(@aircraft),
|
|
alert: t("flash.flight_imports.flights_imported_but_aircraft")
|
|
end
|
|
|
|
private
|
|
|
|
def redirect_to_upload(message)
|
|
redirect_to new_aircraft_flight_import_path(@aircraft), alert: message
|
|
end
|
|
|
|
def build_import(token, filename, starting_tach: @starting_tach, starting_hobbs: @starting_hobbs)
|
|
FlightImport.new(@aircraft, path: stored_path(token), filename: filename,
|
|
starting_tach: starting_tach, starting_hobbs: starting_hobbs)
|
|
end
|
|
end
|