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:
rickyandClaude Opus 5.5 committed 2026-11-05 18:35:38 -05:00
1 parent f94ccee99b
commit b75fd7cf62
31 files changed
+817 -57

No files matched your search

+66
View File
@@ -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
+15
View File
@@ -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)