mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Flights can be corrected after they're saved
- Edit on a flight: owners can correct any flight; a pilot, the flights they logged (the same rule as its engine data). - Date, airports, route, notes, oil and fuel (its oil and fuel records follow) and the attached files can always be changed. - The meter readings only on the latest flight, while its tach in is still the aircraft's tach: the aircraft and installed components move by the difference, and with both readings the duration is worked out from them. On earlier flights they're locked (later flights started from them), pointing to Update Hours; the server ignores them too. - Each correction is in the activity log with what changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
34879e7310
commit
d2cd60c6a7
11 files changed
+274
-38
No files matched your search
@@ -26,6 +26,21 @@ class FlightLog < ApplicationRecord
|
||||
[ departure_location, destination_location ].compact_blank.join(" → ")
|
||||
end
|
||||
|
||||
# The meter readings that move the aircraft's and components' hours.
|
||||
METERS = %w[tach_out tach_in tach_time hobbs_out hobbs_in hobbs_time].freeze
|
||||
|
||||
# Its readings can be corrected only while it's the last flight logged and
|
||||
# nothing has changed the hours since (an hours update, an import): only
|
||||
# then is the aircraft's time just this flight's on top of the one before.
|
||||
def meters_editable?
|
||||
aircraft.flight_logs.maximum(:id) == id && (tach_in.nil? || tach_in == aircraft.tach_time)
|
||||
end
|
||||
|
||||
# Owners can correct any flight; a pilot, the flights they logged.
|
||||
def editable_by?(user, role:)
|
||||
role.in?(%w[admin owner]) || (user_id.present? && user_id == user.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Reject files the engine data parser can't read, before they're stored.
|
||||
|
||||
Reference in new issue
Block a user