The full list comes from DRS imports; the weekly search below adds what's published after.
+Last import <%= last_drs.created_at.to_date %> by <%= last_drs.user&.display_name || "—" %>: <%= last_drs.ad_count %> ADs<%= ", covering #{Array(last_drs.models_covered).to_sentence}" if Array(last_drs.models_covered).any? %>.
+ <% if last_drs.created_at < DrsImport::RENEW_AFTER.ago %>Over a year old: import again to pick up revised ADs and anything the weekly search missed.
<% end %> + <% else %> +No DRS import yet. Export the ADs for each model from drs.faa.gov and import them here.
+ <% end %> + <% if missing.any? %>Never imported for: <%= missing.join(", ") %>. Search DRS for each and import the file.
<% end %> +Refresh the AD list from FAA DRS (new ADs are found weekly, but revisions and anything missed come from a fresh import):
+Records audit due <%= @audit_due %> (AC 120-78B quality control): <%= link_to "start it", new_admin_audit_url %>.
<% end %>Based on the records in Simple Aircraft Manager. Turn these emails off on your <%= link_to "profile", edit_profile_url %>. diff --git a/app/views/reminder_mailer/weekly.text.erb b/app/views/reminder_mailer/weekly.text.erb index abbb1bd..d2ace32 100644 --- a/app/views/reminder_mailer/weekly.text.erb +++ b/app/views/reminder_mailer/weekly.text.erb @@ -16,6 +16,13 @@ Your certificates: - <%= c.expired? ? "Expired" : "Expires" %> <%= c.expires_on %>: <%= c.kind_label %> <%= c.number %> <% end %> <% end %> +<% if @drs_due.any? %> + +AD list from FAA DRS needs a refresh: +<% @drs_due.each do |a| %> +- <%= a.tail_number %>: <%= (m = DrsImport.missing_models(a)).any? ? "never imported for #{m.to_sentence}" : "last import #{a.drs_imports.latest_first.first&.created_at&.to_date || 'never'}" %> (<%= aircraft_airworthiness_directives_url(a) %>) +<% end %> +<% end %> <% if @audit_due %> Records audit due <%= @audit_due %>: <%= new_admin_audit_url %> diff --git a/db/migrate/20261111010000_create_drs_imports.rb b/db/migrate/20261111010000_create_drs_imports.rb new file mode 100644 index 0000000..9426842 --- /dev/null +++ b/db/migrate/20261111010000_create_drs_imports.rb @@ -0,0 +1,16 @@ +class CreateDrsImports < ActiveRecord::Migration[8.1] + def change + # Each FAA DRS import: when, by whom, and which of the aircraft's models + # the file covered (the baseline the weekly new-AD search builds on). + create_table :drs_imports do |t| + t.references :aircraft, null: false, foreign_key: { on_delete: :cascade } + t.references :user, foreign_key: { on_delete: :nullify } + t.string :filename + t.json :models_covered + t.integer :ad_count, null: false, default: 0 + t.integer :tracked, null: false, default: 0 + t.integer :not_applicable, null: false, default: 0 + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 86633f1..99a8643 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_11_09_010000) do +ActiveRecord::Schema[8.1].define(version: 2026_11_11_010000) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -407,6 +407,20 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_09_010000) do t.index ["document_collection_id"], name: "index_documents_on_document_collection_id" end + create_table "drs_imports", force: :cascade do |t| + t.integer "aircraft_id", null: false + t.integer "user_id" + t.string "filename" + t.json "models_covered" + t.integer "ad_count", default: 0, null: false + t.integer "tracked", default: 0, null: false + t.integer "not_applicable", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["aircraft_id"], name: "index_drs_imports_on_aircraft_id" + t.index ["user_id"], name: "index_drs_imports_on_user_id" + end + create_table "entry_signatures", force: :cascade do |t| t.integer "logbook_entry_id", null: false t.integer "user_id" @@ -854,6 +868,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_09_010000) do add_foreign_key "document_collections", "aircraft" add_foreign_key "documents", "aircraft" add_foreign_key "documents", "document_collections" + add_foreign_key "drs_imports", "aircraft", on_delete: :cascade + add_foreign_key "drs_imports", "users", on_delete: :nullify add_foreign_key "entry_signatures", "logbook_entries" add_foreign_key "entry_signatures", "users", on_delete: :nullify add_foreign_key "flight_logs", "aircraft" diff --git a/docs/guide/ads.md b/docs/guide/ads.md index 9d9b9c9..b15216c 100644 --- a/docs/guide/ads.md +++ b/docs/guide/ads.md @@ -8,6 +8,10 @@ The **ADs** tab lists the ADs and bulletins that apply to the aircraft or its co - **Link existing**: ADs are shared between aircraft; link one already entered for another aircraft. - **Import from FAA DRS**: export the ADs for the aircraft, engine and propeller from the FAA's Dynamic Regulatory System, preferably as `.xlsx` so each AD keeps its DRS link, and upload it. The preview suggests **Track**, **Not applicable** or **Skip** for each AD and flags superseded ADs, model mismatches, appliance and STC-only ADs, and recurring actions. Nothing is duplicated. +## The AD baseline + +The full list of ADs comes from DRS imports; the weekly search (below) adds what's published afterwards. The **AD baseline** panel on the ADs tab shows the last import, which of the aircraft's models it covered, and any model (airframe, engine or propeller) that was never imported. Import again at least once a year to pick up revised ADs: the weekly email and the records audit remind you when it's due. + ## Newly published ADs The app searches the Federal Register weekly for new ADs mentioning the aircraft make and model, the engine and propeller models (and their families, e.g. O-200 for an O-200A), and every other installed component by its maker, type and model, such as magnetos, the ELT and radios. ADs often name a series rather than the exact model, so "Bendix" + "magneto" is searched as well as the model. You can add your own terms (an STC, a part that isn't a component); they're searched as well. Tracking an AD found through a component makes it apply to that component. **Check now** runs it straight away. For each match, **Track** it or **Dismiss** it. Matches are only *possibly* applicable: check the AD's applicability and serial number ranges first. diff --git a/test/integration/ad_import_flow_test.rb b/test/integration/ad_import_flow_test.rb index 4241976..860a69e 100644 --- a/test/integration/ad_import_flow_test.rb +++ b/test/integration/ad_import_flow_test.rb @@ -27,6 +27,8 @@ class AdImportFlowTest < ActionDispatch::IntegrationTest } assert_redirected_to aircraft_airworthiness_directives_path(@aircraft) assert_equal %w[2008-22-18 2011-10-09], @aircraft.applicable_ads.order(:name).pluck(:name) + drs = @aircraft.drs_imports.sole # the AD baseline is recorded + assert_equal [ [ "150L" ], @owner, "AD Final Rules.csv" ], [ drs.models_covered, drs.user, drs.filename ] follow_redirect! assert_select "span", text: "N/A" # CSV exports carry no links, so the AD number isn't a link @@ -51,4 +53,31 @@ class AdImportFlowTest < ActionDispatch::IntegrationTest assert_response :redirect assert_equal 0, @aircraft.applicable_ads.count end + + test "the AD baseline: missing models, renewal, where the weekly search starts, reminders and the audit" do + create_component(@aircraft, component_type: component_type("Engine"), model: "O-200A") + assert_equal %w[150L O-200A], DrsImport.missing_models(@aircraft) + assert DrsImport.renewal_due?(@aircraft) + assert_equal 2.years.ago.to_date, AdWatch.new(@aircraft).start_date + + travel_to Time.zone.local(2026, 11, 2) do + @aircraft.drs_imports.create!(user: @owner, models_covered: [ "150L" ]) + @aircraft.drs_imports.create!(user: @owner, models_covered: [ "O-200-A" ]) # matches O-200A + end + assert_empty DrsImport.missing_models(@aircraft) + travel_to Time.zone.local(2026, 11, 20) do + refute DrsImport.renewal_due?(@aircraft) + assert_equal Date.new(2026, 9, 3), AdWatch.new(@aircraft).start_date # last import less 60 days + sign_in @owner + get aircraft_airworthiness_directives_path(@aircraft) + assert_includes response.body, "Last import 2026-11-02" + end + travel_to Time.zone.local(2027, 12, 1) do # over a year: the first Monday-of-month email and the audit flag it + assert DrsImport.renewal_due?(@aircraft) + assert ReminderMailer.anything_for?(@owner, today: Date.new(2027, 12, 6)) + refute ReminderMailer.anything_for?(@owner, today: Date.new(2027, 12, 13)) + assert_includes ReminderMailer.weekly(@owner).text_part.body.to_s, "needs a refresh" + refute RecordsAudit.new.auto_items.find { _1.key == "drs" }.passed + end + end end