Certificates on user profiles, with "Sign as"

- Users add their FAA certificates (kind, number, optional expiry) on
  their profile; admins see them on the Users list
- "Sign as" on new/edited logbook entries and the squawk Resolve page
  fills the signer's name, kind of certificate and number (expired
  certificates aren't offered); deferrals default to mechanic for users
  with a mechanic certificate
- Weekly reminder lists certificates expiring within 60 days (or lapsed
  in the last 30), even when nothing else is due
- Preventive maintenance templates keep a certificate already chosen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 11:08:21 -05:00
1 parent 5584ad59c5
commit aa262065b2
21 files changed
+253 -22

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@
<thead><tr><th>Name</th><th>Email</th><th>Aircraft</th><th>Last sign-in</th><th></th></tr></thead>
<tbody><% @users.each do |u| %><tr>
<td><%= u.name %> <% if u.admin? %><span class="badge-blue">Admin</span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %></td>
<td><%= u.email_address %></td>
<td><%= u.email_address %><% if u.certificates.any? %><div class="text-xs text-slate-500"><%= u.certificates.map { "#{_1.short_label} #{_1.number}" }.join(", ") %></div><% end %></td>
<td class="text-xs"><%= u.aircraft_roles.map { "#{_1.aircraft.tail_number} (#{_1.role})" }.join(", ").presence || "—" %></td>
<td class="text-xs text-slate-500"><%= u.last_signed_in_at ? "#{time_ago_in_words(u.last_signed_in_at)} ago" : "never" %></td>
<td class="text-right"><%= link_to "Edit", edit_admin_user_path(u), class: "btn-secondary btn-sm" %></td>
+5 -4
View File
@@ -1,4 +1,4 @@
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template" } do |f| %>
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template signer" } do |f| %>
<%= f.errors_summary %>
<% if entry.new_record? %>
<div>
@@ -20,11 +20,12 @@
</div>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
<p class="hint !mt-1">A maintenance entry needs a description of the work, the date, and the name, signature, certificate number and kind of certificate of whoever approved the return to service (14 CFR 43.9). An inspection entry also needs the type and extent of the inspection, the aircraft's time in service, and the result (43.11).</p>
<%= render "shared/sign_as" %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :signoff_person, label: "Signed off by", placeholder: "Name" %>
<%= f.field :signoff_person, label: "Signed off by", placeholder: "Name", data: { signer_target: "name" } %>
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—",
collection: LogbookEntry::CERTIFICATE_TYPES.invert, data: { entry_template_target: "certificate" } %>
<%= f.field :signoff_certificate_number, label: "Certificate number", placeholder: "e.g. 1234567" %>
collection: LogbookEntry::CERTIFICATE_TYPES.invert, data: { entry_template_target: "certificate", signer_target: "kind" } %>
<%= f.field :signoff_certificate_number, label: "Certificate number", placeholder: "e.g. 1234567", data: { signer_target: "number" } %>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<%= f.field :inspection_result, as: :select, label: "Inspection result", include_blank: "— Not an inspection —",
+26 -1
View File
@@ -4,7 +4,7 @@
<%= f.field :name %>
<%= f.field :email_address, as: :email, label: "Email" %>
<%= f.field :reminder_emails, as: :checkbox, label: "Weekly maintenance reminders",
hint: "A Monday email about overdue and upcoming inspections, ADs, parts and documents on aircraft you own. Only sent when something needs attention#{' (once email is set up)' unless MailSettings.configured?}." %>
hint: "A Monday email about overdue and upcoming inspections, ADs, parts and documents on aircraft you own, and certificates of yours about to expire. Only sent when something needs attention#{' (once email is set up)' unless MailSettings.configured?}." %>
<%= f.field :password, as: :password, label: "New password", hint: "Leave blank to keep your current password.", autocomplete: "new-password" %>
<%= f.field :password_confirmation, as: :password, label: "Confirm new password", autocomplete: "new-password" %>
<div>
@@ -31,6 +31,31 @@
</section>
<% end %>
<section class="card card-body mt-5 max-w-md" id="certificates">
<h2 class="card-title">Certificates</h2>
<p class="mt-1 text-sm text-slate-600">Your FAA certificates, for signing logbook entries: “Sign as” fills in your name, the kind of certificate and its number.</p>
<% if @user.certificates.any? %>
<ul class="mt-3 divide-y divide-slate-100 rounded-md ring-1 ring-slate-200">
<% @user.certificates.each do |c| %>
<li class="flex flex-wrap items-center justify-between gap-2 px-3 py-2 text-sm">
<span><span class="font-medium"><%= c.kind_label %></span> · <%= c.number %>
<% if c.expires_on %><span class="ml-1 <%= c.expired? ? 'badge-red' : (Date.current + UserCertificate::EXPIRY_WARNING_DAYS >= c.expires_on ? 'badge-orange' : 'badge-gray') %>"><%= c.expired? ? "Expired" : "Expires" %> <%= c.expires_on %></span><% end %></span>
<%= button_to "Remove", certificate_path(c), method: :delete, class: "btn-secondary btn-sm", form: { data: { turbo_confirm: "Remove your #{c.kind_label} certificate?" } } %>
</li>
<% end %>
</ul>
<% end %>
<%= form_with model: UserCertificate.new, url: certificates_path, class: "mt-3 grid gap-2 sm:grid-cols-[1fr_8rem]" do |f| %>
<%= f.select :kind, UserCertificate::KINDS.invert, {}, class: "input", "aria-label": "Kind of certificate" %>
<%= f.text_field :number, class: "input", placeholder: "Number", required: true, maxlength: 40, "aria-label": "Certificate number" %>
<div class="sm:col-span-2 flex flex-wrap items-end gap-2">
<div><%= f.label :expires_on, "Expires (optional)", class: "label" %><%= f.date_field :expires_on, class: "input" %></div>
<%= f.submit "Add certificate", class: "btn-secondary" %>
</div>
<p class="hint sm:col-span-2">An Inspection Authorization expires on March 31 of each odd-numbered year unless renewed; you'll be reminded 60 days ahead in the weekly email.</p>
<% end %>
</section>
<section class="card card-body mt-5 max-w-md">
<h2 class="card-title">Sessions</h2>
<% others = @user.sessions.where.not(id: Current.session.id).count %>
+7 -1
View File
@@ -1,4 +1,4 @@
<p>Here's what needs attention on your aircraft.</p>
<p>Here's what needs attention<%= " on your aircraft" if @items.any? %>.</p>
<% @items.each do |aircraft, issues, alerts| %>
<h3 style="margin: 16px 0 4px;"><%= link_to aircraft.tail_number, aircraft_url(aircraft) %> <span style="font-weight: normal; color: #64748b;"><%= aircraft.airworthiness.label %></span></h3>
<ul style="margin: 0; padding-left: 20px;">
@@ -12,6 +12,12 @@
<%= alerts.map { _1.ad_number || _1.fr_document_number }.to_sentence %>. <%= link_to "Review them", aircraft_airworthiness_directives_url(aircraft, anchor: "new-ads") %>.</p>
<% end %>
<% end %>
<% if @certificates.any? %>
<h3 style="margin: 16px 0 4px;">Your certificates</h3>
<ul style="margin: 0; padding-left: 20px;">
<% @certificates.each do |c| %><li><strong><%= c.expired? ? "Expired" : "Expires" %> <%= c.expires_on %>:</strong> <%= c.kind_label %> <%= c.number %></li><% end %>
</ul>
<% end %>
<p style="color: #64748b; font-size: 12px; margin-top: 20px;">
Based on the records in Simple Aircraft Manager. Turn these emails off on your <%= link_to "profile", edit_profile_url %>.
</p>
+8 -1
View File
@@ -1,4 +1,4 @@
Here's what needs attention on your aircraft.
Here's what needs attention<%= " on your aircraft" if @items.any? %>.
<% @items.each do |aircraft, issues, alerts| %>
<%= aircraft.tail_number %> (<%= aircraft.airworthiness.label %>): <%= aircraft_url(aircraft) %>
@@ -9,5 +9,12 @@ Here's what needs attention on your aircraft.
- New ADs that may apply: <%= alerts.map { _1.ad_number || _1.fr_document_number }.to_sentence %>. Review: <%= aircraft_airworthiness_directives_url(aircraft, anchor: "new-ads") %>
<% end %>
<% end %>
<% if @certificates.any? %>
Your certificates:
<% @certificates.each do |c| %>
- <%= c.expired? ? "Expired" : "Expires" %> <%= c.expires_on %>: <%= c.kind_label %> <%= c.number %>
<% end %>
<% end %>
Based on the records in Simple Aircraft Manager. Turn these emails off on your profile: <%= edit_profile_url %>
+14
View File
@@ -0,0 +1,14 @@
<%# "Sign as" picker for the current user's certificates (signer controller). %>
<% certificates = current_user.certificates.reject(&:expired?) %>
<% if certificates.any? %>
<div class="flex flex-wrap items-center gap-2 text-sm">
<%= label_tag :sign_as, "Sign as", class: "text-slate-600" %>
<select id="sign_as" class="input w-auto" data-signer-target="choice" data-action="signer#fill">
<option value="">— Someone else —</option>
<% certificates.each do |c| %>
<option value="<%= c.id %>" data-name="<%= current_user.display_name %>" data-kind="<%= c.kind %>" data-number="<%= c.number %>">
<%= current_user.display_name %>, <%= c.kind_label %> <%= c.number %></option>
<% end %>
</select>
</div>
<% end %>
+2 -1
View File
@@ -33,7 +33,8 @@
</div>
<div>
<%= label_tag :deferred_by_role, "As", class: "label" %>
<%= select_tag :deferred_by_role, options_for_select(Squawk::DEFERRAL_ROLES.invert, params[:deferred_by_role]), class: "input" %>
<%= select_tag :deferred_by_role, options_for_select(Squawk::DEFERRAL_ROLES.invert,
params[:deferred_by_role] || (current_user.certificates.any?(&:mechanic?) ? "mechanic" : "pilot")), class: "input" %>
</div>
</div>
</div>
+6 -4
View File
@@ -19,8 +19,9 @@
<label class="flex items-center gap-2"><%= radio_button_tag :logbook, "none", choice == "none" %> No logbook entry (e.g. it wasn't a defect)</label>
</fieldset>
<div class="space-y-4 rounded-md border border-slate-200 p-3">
<div class="space-y-4 rounded-md border border-slate-200 p-3" data-controller="signer">
<p class="text-xs text-slate-500">For a new entry. 14 CFR 43.9: what was done, the date, and the name, certificate number and kind of certificate of whoever approved the return to service.</p>
<%= render "shared/sign_as" %>
<%= fields_for :logbook_entry, @entry do |f| %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :date, as: :date %>
@@ -29,9 +30,10 @@
</div>
<%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :signoff_person, label: "Signed off by" %>
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—", collection: LogbookEntry::CERTIFICATE_TYPES.invert %>
<%= f.field :signoff_certificate_number, label: "Certificate number" %>
<%= f.field :signoff_person, label: "Signed off by", data: { signer_target: "name" } %>
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—", collection: LogbookEntry::CERTIFICATE_TYPES.invert,
data: { signer_target: "kind" } %>
<%= f.field :signoff_certificate_number, label: "Certificate number", data: { signer_target: "number" } %>
</div>
<% end %>
</div>