mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Import ADs from FAA DRS exports; N/A determinations and DRS links
AD import (owners, ADs tab → Import from FAA DRS): - Upload a DRS export (.xlsx recommended, .csv works), preview, confirm. - Per AD: track, not applicable, or skip, with suggestions and flags for superseded/non-current ADs, model mismatches, appliance and STC-only ADs, repetitive actions, and older ADs this one supersedes. - ADs are matched by number; re-importing updates existing ADs from the FAA data (preview lists what will change) without touching compliance records, recurrence or applicability. Superseded tracked ADs are updated and flagged rather than skipped. - DRS's Excel export hyperlinks each AD number to its DRS page; those links are kept (http(s) only). DRS ids aren't derivable from the AD number, so no links are guessed. Also: - Per-aircraft "not applicable" AD determinations (N/A badge, quick action, excluded from airworthiness). - AD numbers link to their DRS document in the AD list, compliance history (now with description, logbook/inspection links) and share page. - Saved DRS search link per aircraft with an "Open in DRS" button. - Upload storage extracted to a StoredUpload concern shared with the flight import. - document_url / drs_search_url added in their own guarded migration (they were briefly in an already-applied migration). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f94ccee99b
commit
b75fd7cf62
31 files changed
+817
-57
No files matched your search
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
AD Number,Subject Heading,Subject,Status,CFR Part Reference,Effective Date,Service/Office,Office of Primary Responsibility,Docket Number,Citation,Citation Publish Date,Make,Model,Product Type,Product Subtype,Affected AD,Superseded AD,Affected By,Superseded By,AC Reference,AIR Policy Reference,Additional Reference,Summary,Comments
|
||||
2011-10-09,"Airworthiness Directives; Cessna Aircraft Company Models 150, 152 Airplanes",Seat Rails and Roller Housing Inspections,Current,Part 39,06/17/2011,,,FAA-2010-1101,"(Federal Register Volume 76, Number 93 (Friday, May 13, 2011))",05/13/2011,Cessna Aircraft Company,150L | 150M | 152,Aircraft,Small Airplane,,87-20-03 R2,,,,,,"We are superseding an existing airworthiness directive (AD). That AD currently requires repetitive inspections and replacement of parts, if necessary, \n\n((Page 27866)) \n\nof the seat rail and seat rail holes.",
|
||||
2008-22-18,Airworthiness Directives; Cessna Aircraft Company 150 Series Airplanes,"Ballistic Recovery Systems, Inc. (BRS)",Current,Part 39,12/09/2008,,,FAA-2008-0790,"Federal Register: November 4, 2008",11/04/2008,Cessna Aircraft Company,150L | 150M | 152,Aircraft,Small Airplane,,,,,,,,"This AD applies to airplanes with the BRS-150 Parachute System installed via Supplemental Type Certificate (STC) SA64CH.",
|
||||
96-12-22,Airworthiness Directives; Cessna Aircraft Company Engine Oil Filter Adapter Assemblies Installed on Aircraft,Full Flow Engine Oil Adapter,Current,Part 39,07/31/1996,AIR-700,AIR-720,93-CE-54-AD,"(Federal Register: June 17, 1996)",06/17/1996,Cessna Aircraft Company | Continental Motors,150L | 150M | O-200-A,Appliance,,,,,,,,,"This action requires inspecting the oil filter adapter and repetitively inspecting the torque putty.",
|
||||
75-15-08,"Airworthiness Directives; BEECH AND CESSNA Models 35, 150",Engine Lubrication,Current,Part 39,09/10/1975,,,Unknown,This information is not available.,,Cessna Aircraft Company,150K | 150L | A150L,Aircraft,Small Airplane,,,,,,,,,
|
||||
87-20-03 R2,Airworthiness Directives; Cessna Aircraft Company Airplanes,Seat Rails,Historical,Part 39,11/02/1987,,,Unknown,This information is not available.,,Cessna Aircraft Company,150L | 150M,Aircraft,Small Airplane,,,,2011-10-09,,,,,
|
||||
|
@@ -0,0 +1,66 @@
|
||||
require "test_helper"
|
||||
|
||||
class AdImportFlowTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@owner = create_user
|
||||
@pilot = create_user
|
||||
@aircraft = create_aircraft(owner: @owner, pilot: @pilot, model: "150L")
|
||||
end
|
||||
|
||||
test "owner uploads, reviews, and imports" do
|
||||
sign_in @owner
|
||||
get aircraft_airworthiness_directives_path(@aircraft)
|
||||
assert_select "a[href='#{new_aircraft_ad_import_path(@aircraft)}']"
|
||||
|
||||
post aircraft_ad_import_path(@aircraft), params: { file: fixture_file_upload("drs_ads.csv", "text/csv") }
|
||||
assert_response :redirect
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
assert_select "select[name='decisions[2011-10-09]'] option[selected][value='track']"
|
||||
assert_select "select[name='decisions[87-20-03 R2]'] option[selected][value='skip']"
|
||||
assert_match "Excel</strong> export includes them", response.body
|
||||
token = response.body[/name="token"[^>]*value="([^"]+)"/, 1]
|
||||
|
||||
post confirm_aircraft_ad_import_path(@aircraft), params: {
|
||||
token: token, filename: "AD Final Rules.csv",
|
||||
decisions: { "2011-10-09" => "track", "2008-22-18" => "na", "96-12-22" => "skip", "75-15-08" => "skip", "87-20-03 R2" => "skip" }
|
||||
}
|
||||
assert_redirected_to aircraft_airworthiness_directives_path(@aircraft)
|
||||
assert_equal %w[2008-22-18 2011-10-09], @aircraft.applicable_ads.order(:name).pluck(:name)
|
||||
follow_redirect!
|
||||
assert_select "span", text: "N/A"
|
||||
# CSV exports carry no links, so the AD number isn't a link
|
||||
assert_select "a", text: "2011-10-09", count: 0
|
||||
end
|
||||
|
||||
test "N/A quick action records a not-applicable determination" do
|
||||
ad = AirworthinessDirective.create!(name: "2008-22-18", short_description: "BRS")
|
||||
ad.aircraft << @aircraft
|
||||
sign_in @owner
|
||||
get new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id, not_applicable: 1)
|
||||
assert_select "input[name='ad_compliance[not_applicable]'][checked]"
|
||||
post aircraft_ad_compliances_path(@aircraft), params: { ad_compliance: {
|
||||
airworthiness_directive_id: ad.id, date_complied: Date.current, not_applicable: "1",
|
||||
compliance_notes: "Not applicable: no BRS parachute installed" } }
|
||||
assert_equal "GREEN", @aircraft.reload.airworthiness.status
|
||||
end
|
||||
|
||||
test "saved DRS search link shows an Open in DRS button; only drs.faa.gov links allowed" do
|
||||
sign_in @owner
|
||||
url = "https://drs.faa.gov/browse/ADFRAWD/doctypeDetails?Status=Current&Make=Cessna%20Aircraft%20Company&Model=150L#:~:text=Save-,Results"
|
||||
patch aircraft_path(@aircraft), params: { aircraft: { drs_search_url: url } }
|
||||
assert_equal url.sub(/#.*/, ""), @aircraft.reload.drs_search_url
|
||||
get aircraft_airworthiness_directives_path(@aircraft)
|
||||
assert_select "a[href='#{@aircraft.drs_search_url}']", text: "Open in DRS ↗"
|
||||
|
||||
patch aircraft_path(@aircraft), params: { aircraft: { drs_search_url: "https://evil.example/drs.faa.gov" } }
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "pilots cannot import ADs" do
|
||||
sign_in @pilot
|
||||
post aircraft_ad_import_path(@aircraft), params: { file: fixture_file_upload("drs_ads.csv", "text/csv") }
|
||||
assert_response :redirect
|
||||
assert_equal 0, @aircraft.applicable_ads.count
|
||||
end
|
||||
end
|
||||
@@ -67,6 +67,21 @@ class PagesTest < ActionDispatch::IntegrationTest
|
||||
assert_select "form[data-controller='next-due'][data-next-due-rules-value*='\"months\":12']"
|
||||
end
|
||||
|
||||
test "compliance history shows the AD's description and links" do
|
||||
@ad.update!(document_url: "https://drs.faa.gov/browse/excelExternalWindow/ABC.0001")
|
||||
@adc.update!(logbook_entry: @entry)
|
||||
get aircraft_airworthiness_directives_path(@a)
|
||||
assert_select "section", text: /Compliance History/ do
|
||||
assert_select "a[href='https://drs.faa.gov/browse/excelExternalWindow/ABC.0001'][target='_blank']", text: "2020-01-01"
|
||||
assert_select "div", text: "Check"
|
||||
assert_select "a[href='#{aircraft_logbook_entry_path(@a, @entry)}']"
|
||||
end
|
||||
|
||||
delete session_path
|
||||
get shared_path(@token.token)
|
||||
assert_select "a[href='https://drs.faa.gov/browse/excelExternalWindow/ABC.0001']", minimum: 2 # status + history
|
||||
end
|
||||
|
||||
test "maintenance share link renders without login and shows history" do
|
||||
delete session_path
|
||||
get shared_path(@token.token)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
require "test_helper"
|
||||
|
||||
class AirworthinessDirectiveTest < ActiveSupport::TestCase
|
||||
def ad(**attrs) = AirworthinessDirective.new({ name: "2011-10-09", short_description: "x" }.merge(attrs))
|
||||
|
||||
test "stored link wins" do
|
||||
assert_equal [ "https://drs.faa.gov/x", "View AD" ], ad(document_url: "https://drs.faa.gov/x", docket_number: "FAA-2010-1101").reference_link
|
||||
end
|
||||
|
||||
test "no guessed links: DRS document ids can't be derived from the AD number" do
|
||||
assert_nil ad(docket_number: "FAA-2010-1101").reference_link
|
||||
end
|
||||
|
||||
test "only http(s) links are accepted" do
|
||||
assert_not ad(document_url: "javascript:alert(1)").valid?
|
||||
assert ad(document_url: " https://drs.faa.gov/x ").tap(&:valid?).document_url == "https://drs.faa.gov/x"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,193 @@
|
||||
require "test_helper"
|
||||
|
||||
class AdImportTest < ActiveSupport::TestCase
|
||||
FILE = Rails.root.join("test/fixtures/files/drs_ads.csv")
|
||||
|
||||
setup do
|
||||
@user = create_user
|
||||
@aircraft = create_aircraft(owner: @user, make: "Cessna", model: "150L", tach_time: 7290.3)
|
||||
end
|
||||
|
||||
def import = AdImport.new(@aircraft, path: FILE, filename: "AD Final Rules.csv")
|
||||
def row(number) = import.rows.find { _1.number == number }
|
||||
|
||||
test "parses the DRS export and cleans the Federal Register text" do
|
||||
rows = import.rows
|
||||
assert_equal [ "2011-10-09", "2008-22-18", "96-12-22", "75-15-08", "87-20-03 R2" ], rows.map(&:number)
|
||||
seat = rows.first
|
||||
assert_equal "Seat Rails and Roller Housing Inspections", seat.subject
|
||||
assert_equal Date.new(2011, 6, 17), seat.effective_date
|
||||
assert_equal "FAA-2010-1101", seat.docket
|
||||
assert_equal [ "87-20-03 R2" ], seat.supersedes
|
||||
assert_not_includes seat.summary, "((Page"
|
||||
assert_not_includes seat.summary, "\\n"
|
||||
assert_nil rows[3].docket # "Unknown"
|
||||
end
|
||||
|
||||
test "suggests an action and flags things to check" do
|
||||
assert_equal "track", row("2011-10-09").suggested
|
||||
assert_match "repetitive", row("2011-10-09").notes.join
|
||||
|
||||
assert_match "STC", row("2008-22-18").notes.join
|
||||
assert_match "Appliance", row("96-12-22").notes.join
|
||||
|
||||
old = row("87-20-03 R2")
|
||||
assert_equal "skip", old.suggested
|
||||
assert_match "Historical", old.notes.join
|
||||
assert_match "Superseded by 2011-10-09", old.notes.join
|
||||
end
|
||||
|
||||
test "skips ADs whose model list doesn't include the aircraft" do
|
||||
@aircraft.update!(model: "150M")
|
||||
assert_equal "skip", row("75-15-08").suggested
|
||||
assert_match "150M", row("75-15-08").notes.join
|
||||
end
|
||||
|
||||
test "model written with the make still matches" do
|
||||
@aircraft.update!(model: "Cessna 150L")
|
||||
assert_equal "track", row("75-15-08").suggested
|
||||
end
|
||||
|
||||
test "imports with per-AD decisions; tracked ADs need compliance, N/A ones don't" do
|
||||
result = import.import!(decisions: { "2008-22-18" => "na", "96-12-22" => "skip" }, user: @user)
|
||||
assert_equal({ tracked: 2, not_applicable: 1, skipped: 2, updated: 0 }, result)
|
||||
assert_equal %w[2008-22-18 2011-10-09 75-15-08], @aircraft.applicable_ads.order(:name).pluck(:name)
|
||||
|
||||
rows = Compliance.ad_rows(@aircraft).index_by { _1.ad.name }
|
||||
assert_equal "not_applicable", rows["2008-22-18"].status
|
||||
assert_equal "no_compliance", rows["2011-10-09"].status
|
||||
|
||||
issues = Airworthiness.new(@aircraft).call.issues.map(&:title)
|
||||
assert_includes issues, "AD 2011-10-09 - Overdue"
|
||||
assert_not issues.any? { _1.include?("2008-22-18") }
|
||||
|
||||
ad = AirworthinessDirective.find_by(name: "2011-10-09")
|
||||
assert_equal "87-20-03 R2", ad.supersedes
|
||||
assert_includes ad.applicable_models, "150L"
|
||||
end
|
||||
|
||||
test "re-import updates existing ADs from the FAA data and says what changes" do
|
||||
mine = AirworthinessDirective.create!(name: "2011-10-09", short_description: "My seat rail notes", recurring: true, recurring_hours: 100)
|
||||
mine.aircraft << @aircraft
|
||||
mine.ad_compliances.create!(aircraft: @aircraft, date_complied: Date.current, compliance_notes: "Done", next_due_at_time: 7390.3)
|
||||
r = row("2011-10-09")
|
||||
assert_equal "track", r.suggested
|
||||
assert_match "Already tracked. Will update: Subject, Summary, Effective date, Docket, Supersedes, Models, Product type", r.notes.first
|
||||
|
||||
result = import.import!(decisions: {}, user: @user)
|
||||
assert_equal 1, result[:updated]
|
||||
assert_equal 1, AirworthinessDirective.where(name: "2011-10-09").count
|
||||
mine.reload
|
||||
assert_equal "Seat Rails and Roller Housing Inspections", mine.short_description
|
||||
assert_equal Date.new(2011, 6, 17), mine.effective_date
|
||||
# owner-managed settings and compliance untouched
|
||||
assert mine.recurring?
|
||||
assert_equal 100, mine.recurring_hours
|
||||
assert_equal BigDecimal("7390.3"), mine.ad_compliances.first.next_due_at_time
|
||||
|
||||
assert_match "Up to date", row("2011-10-09").notes.first
|
||||
end
|
||||
|
||||
test "a tracked AD that's now superseded is updated and flagged, not skipped" do
|
||||
old = AirworthinessDirective.create!(name: "87-20-03 R2", short_description: "Old seat rail AD")
|
||||
old.aircraft << @aircraft
|
||||
r = row("87-20-03 R2")
|
||||
assert_equal "track", r.suggested
|
||||
assert_match "Superseded by 2011-10-09: review whether it still applies", r.notes.join
|
||||
|
||||
import.import!(decisions: { "87-20-03 R2" => "track" }, user: @user)
|
||||
assert_equal "2011-10-09", old.reload.superseded_by
|
||||
end
|
||||
|
||||
test "skip leaves an existing AD exactly as it is" do
|
||||
mine = AirworthinessDirective.create!(name: "2011-10-09", short_description: "Mine")
|
||||
mine.aircraft << @aircraft
|
||||
import.import!(decisions: { "2011-10-09" => "skip" }, user: @user)
|
||||
assert_equal "Mine", mine.reload.short_description
|
||||
assert_nil mine.effective_date
|
||||
end
|
||||
|
||||
test "a later Excel import adds DRS links to ADs imported from CSV" do
|
||||
import.import!(decisions: {}, user: @user)
|
||||
assert_nil AirworthinessDirective.find_by(name: "2011-10-09").document_url
|
||||
path = Rails.root.join("tmp/drs-#{SecureRandom.hex(4)}.xlsx")
|
||||
pkg = Axlsx::Package.new
|
||||
pkg.workbook.add_worksheet(name: "ADs") do |ws|
|
||||
ws.add_row [ "AD Number", "Subject", "Status", "Model" ]
|
||||
ws.add_row [ "2011-10-09", "Seat Rails and Roller Housing Inspections", "Current", "150L" ]
|
||||
ws.add_hyperlink(location: "https://drs.faa.gov/browse/excelExternalWindow/XYZ.0001", ref: "A2")
|
||||
end
|
||||
pkg.serialize(path.to_s)
|
||||
xlsx = AdImport.new(@aircraft, path: path, filename: "ads.xlsx")
|
||||
assert_match "DRS link", xlsx.rows.first.notes.first
|
||||
xlsx.import!(decisions: {}, user: @user)
|
||||
ad = AirworthinessDirective.find_by(name: "2011-10-09")
|
||||
assert_equal "https://drs.faa.gov/browse/excelExternalWindow/XYZ.0001", ad.document_url
|
||||
assert_equal Date.new(2011, 6, 17), ad.effective_date # not blanked by the sparser file
|
||||
ensure
|
||||
FileUtils.rm_f(path) if path
|
||||
end
|
||||
|
||||
test "warns when a new AD supersedes one the aircraft still tracks" do
|
||||
AirworthinessDirective.create!(name: "87-20-03 R2", short_description: "Old seat rail AD").aircraft << @aircraft
|
||||
assert_match "Supersedes 87-20-03 R2", row("2011-10-09").notes.join
|
||||
end
|
||||
|
||||
test "re-import is idempotent and N/A isn't recorded twice" do
|
||||
2.times { import.import!(decisions: { "2008-22-18" => "na" }, user: @user) }
|
||||
assert_equal 1, AdCompliance.where(not_applicable: true).count
|
||||
assert_equal 4, @aircraft.applicable_ads.count
|
||||
end
|
||||
|
||||
test "keeps hyperlinks from an Excel export" do
|
||||
path = Rails.root.join("tmp/drs-#{SecureRandom.hex(4)}.xlsx")
|
||||
pkg = Axlsx::Package.new
|
||||
pkg.workbook.add_worksheet(name: "ADs") do |ws|
|
||||
ws.add_row [ "AD Number", "Subject", "Status", "Effective Date", "Model" ]
|
||||
ws.add_row [ "2011-10-09", "Seat Rails", "Current", "06/17/2011", "150L" ]
|
||||
ws.add_row [ "67-03-01", "Exhaust Gas Heat Exchangers", "Current", "01/14/1967", "150L" ]
|
||||
ws.add_hyperlink(location: "https://drs.faa.gov/browse/excelExternalWindow/ABC123.0001", ref: "A2")
|
||||
end
|
||||
pkg.serialize(path.to_s)
|
||||
|
||||
imp = AdImport.new(@aircraft, path: path, filename: "ads.xlsx")
|
||||
assert_equal "https://drs.faa.gov/browse/excelExternalWindow/ABC123.0001", imp.rows.first.url
|
||||
assert_nil imp.rows.last.url
|
||||
imp.import!(decisions: {}, user: @user)
|
||||
assert_equal [ "https://drs.faa.gov/browse/excelExternalWindow/ABC123.0001", "View AD" ],
|
||||
AirworthinessDirective.find_by(name: "2011-10-09").reference_link
|
||||
ensure
|
||||
FileUtils.rm_f(path)
|
||||
end
|
||||
|
||||
test "keeps a link column from a CSV, but never non-http links" do
|
||||
path = Rails.root.join("tmp/drs-#{SecureRandom.hex(4)}.csv")
|
||||
File.write(path, <<~CSV)
|
||||
AD Number,Subject,Status,Model,Link
|
||||
2011-10-09,Seat Rails,Current,150L,https://example.gov/ad/2011-10-09.pdf
|
||||
2008-22-18,BRS,Current,150L,javascript:alert(1)
|
||||
CSV
|
||||
rows = AdImport.new(@aircraft, path: path, filename: "x.csv").rows
|
||||
assert_equal "https://example.gov/ad/2011-10-09.pdf", rows.first.url
|
||||
assert_nil rows.last.url
|
||||
ensure
|
||||
FileUtils.rm_f(path)
|
||||
end
|
||||
|
||||
# Guards against a field only existing in memory (e.g. via `normalizes`)
|
||||
# and silently not being saved.
|
||||
test "every FAA field the import writes is a real database column" do
|
||||
AdImport::FAA_FIELDS.each_key do |attr|
|
||||
assert_includes AirworthinessDirective.column_names, attr.to_s
|
||||
end
|
||||
assert_includes Aircraft.column_names, "drs_search_url"
|
||||
end
|
||||
|
||||
test "rejects files that aren't DRS exports" do
|
||||
path = Rails.root.join("tmp/not-drs-#{SecureRandom.hex(4)}.csv")
|
||||
File.write(path, "Name,Value\na,1\n")
|
||||
assert_raises(AdImport::Error) { AdImport.new(@aircraft, path: path, filename: "x.csv").rows }
|
||||
ensure
|
||||
FileUtils.rm_f(path)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user