One way to add people on an aircraft

Since invitations from an aircraft's Access page only worked for existing
accounts, they did almost what "Add by email" does. The Access page keeps
adding people by email; new people come through the administrator (Admin
→ Users or Admin → Invitations), and outside mechanics through an Owner's
signing invitation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-15 19:18:19 -05:00
1 parent 9a20c91f5e
commit c360edfce0
10 files changed
+20 -131

No files matched your search

+2 -2
View File
@@ -160,7 +160,7 @@ To back up or move a single aircraft with all its files, use **More → Download
| Reminders | A Monday email to those whose role gets reminders (Owners and Mechanics by default) when something is overdue or coming due, plus push alerts when something becomes overdue, and to anyone whose certificate (e.g. an IA) is about to expire; admins also get the records audit due date (needs SMTP; users can turn it off). | | Reminders | A Monday email to those whose role gets reminders (Owners and Mechanics by default) when something is overdue or coming due, plus push alerts when something becomes overdue, and to anyone whose certificate (e.g. an IA) is about to expire; admins also get the records audit due date (needs SMTP; users can turn it off). |
| Oil and fuel | Records, trend charts, and averages (last 20 intervals, IQR outlier filtering, manual exclusion). | | Oil and fuel | Records, trend charts, and averages (last 20 intervals, IQR outlier filtering, manual exclusion). |
| Activity log | Every write is recorded as an `AircraftEvent`; the Activity tab loads them as you scroll. | | Activity log | Every write is recorded as an `AircraftEvent`; the Activity tab loads them as you scroll. |
| Access | Configurable roles per aircraft (see [Roles](#roles)), invitation links (from Admin → Invitations or an aircraft's Access page; limited uses, expiry, optionally one email address) that give an account and roles, plus share links (Current Status or Maintenance Detail, optional expiry, at most 10 per aircraft). Admins can disable accounts; a disabled account can't sign in or sign entries, and its past signatures stay. | | Access | Configurable roles per aircraft (see [Roles](#roles)), admins' invitation links (limited uses, expiry, optionally one email address) that give an account and roles, plus share links (Current Status or Maintenance Detail, optional expiry, at most 10 per aircraft). Admins can disable accounts; a disabled account can't sign in or sign entries, and its past signatures stay. |
| Sign-in security | Passwords of at least 12 characters, checked against known breaches (Have I Been Pwned, k-anonymity). 10 failed sign-ins in a row lock an account for 15 minutes from any address, and the user is emailed; admins can unlock. Optional authenticator-app (TOTP) codes with recovery codes for password and emailed-link sign-in and for signing entries; admins can reset them. Rate limits per address on every sign-in form. | | Sign-in security | Passwords of at least 12 characters, checked against known breaches (Have I Been Pwned, k-anonymity). 10 failed sign-ins in a row lock an account for 15 minutes from any address, and the user is emailed; admins can unlock. Optional authenticator-app (TOTP) codes with recovery codes for password and emailed-link sign-in and for signing entries; admins can reset them. Rate limits per address on every sign-in form. |
| Phones and offline | Installable (PWA). Flights and squawks logged without signal, or with one too weak to answer within 10 seconds, are kept on the device and sent later, never twice. The Fleet, Overview, W&B, Log Flight and Report Squawk pages are saved ahead of time; any other page falls back to an offline page. The top bar turns red when the server can't be reached, and a ring shows saving and sending progress. | | Phones and offline | Installable (PWA). Flights and squawks logged without signal, or with one too weak to answer within 10 seconds, are kept on the device and sent later, never twice. The Fleet, Overview, W&B, Log Flight and Report Squawk pages are saved ahead of time; any other page falls back to an offline page. The top bar turns red when the server can't be reached, and a ring shows saving and sending progress. |
| REST API | Personal and integration tokens with scopes, read endpoints, squawks, draft logbook entries for signing in the app, and signed webhooks ([docs](docs/guide/api.md)). Follows the person's role. | | REST API | Personal and integration tokens with scopes, read endpoints, squawks, draft logbook entries for signing in the app, and signed webhooks ([docs](docs/guide/api.md)). Follows the person's role. |
@@ -202,7 +202,7 @@ Users who aren't on an aircraft get a 404 for it, identical to a missing record.
Differences from the original: Differences from the original:
- Integer primary keys instead of UUIDs. Share tokens are 32-character random strings. - Integer primary keys instead of UUIDs. Share tokens are 32-character random strings.
- Logbook entries and inspection records don't keep many-to-many links to components. An inspection record or AD compliance can reference one component. - Logbook entries and inspection records don't keep many-to-many links to components. An inspection record or AD compliance can reference one component.
- Accounts are created only by an admin, by the first-run setup, by someone opening an admin's invitation link (with a password, or SSO), by an outside mechanic from an Owner's signing invitation (for its address), or at first SSO sign-in when `OIDC_AUTO_CREATE_USERS` is on. Invitations from an aircraft's Access page are for existing accounts. Who can add aircraft, and so become an Owner, is an admin setting (administrators only by default). - Accounts are created only by an admin, by the first-run setup, by someone opening an admin's invitation link (with a password, or SSO), by an outside mechanic from an Owner's signing invitation (for its address), or at first SSO sign-in when `OIDC_AUTO_CREATE_USERS` is on. Who can add aircraft, and so become an Owner, is an admin setting (administrators only by default).
### Not yet ported ### Not yet ported
@@ -1,34 +0,0 @@
# Invitation codes for one aircraft (AccessInvitation), from its Access page,
# by whoever manages its people: only the roles they can give (AircraftAccess).
class AircraftInvitationsController < ApplicationController
include AircraftScoped
requires_permission :manage_people
def create
role = AircraftAccess.new(@aircraft, actor: current_user).assignable_roles.find { _1.id == params[:role_id].to_i }
return back(alert: t("services.aircraft_access.owner_only")) unless role
attributes = params.permit(:label, :email, :name, :max_uses, :expires_at).to_h.symbolize_keys
attributes[:label] = t("flash.aircraft_invitations.default_label", tail_number: @aircraft.tail_number) if attributes[:label].blank?
@invitation = AccessInvitation.create_for(current_user, attributes, [ [ @aircraft, role ] ])
return back(alert: @invitation.errors.full_messages.to_sentence) unless @invitation.persisted?
log_event("role", t("flash.aircraft_invitations.created_event", role: role.name), notes: @invitation.label)
render :created
end
# Only invitations for this aircraft alone; others are managed in Admin → Invitations.
def destroy
invitation = AccessInvitation.where(id: self.class.only_for(@aircraft)).find(params[:id])
invitation.update!(revoked_at: Time.current)
log_event("role", t("flash.aircraft_invitations.revoked_event"), notes: invitation.label)
back(notice: t("flash.aircraft_invitations.revoked"))
end
# Ids of the invitations that give a role on this aircraft and no other.
def self.only_for(aircraft)
AccessInvitationRole.group(:access_invitation_id).having("COUNT(*) = 1 AND MAX(aircraft_id) = ?", aircraft.id).select(:access_invitation_id)
end
private
def back(flash) = redirect_to(aircraft_aircraft_roles_path(@aircraft, anchor: "invitations"), flash)
end
@@ -11,8 +11,6 @@ class AircraftRolesController < ApplicationController
@access = AircraftAccess.new(@aircraft, actor: current_user) @access = AircraftAccess.new(@aircraft, actor: current_user)
@roles = @aircraft.roles.includes(:user, :role).joins(:role).order("roles.position", :created_at) @roles = @aircraft.roles.includes(:user, :role).joins(:role).order("roles.position", :created_at)
@share_tokens = @aircraft.share_tokens.order(created_at: :desc).includes(:created_by) @share_tokens = @aircraft.share_tokens.order(created_at: :desc).includes(:created_by)
@invitations = AccessInvitation.where(id: AircraftInvitationsController.only_for(@aircraft), revoked_at: nil)
.recent_first.includes(:created_by, grants: :role).limit(20)
end end
def create def create
@@ -1,3 +0,0 @@
<% content_for :title, t("shared.invitation_created.title") %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<%= render "shared/invitation_created", invitation: @invitation, back_path: aircraft_aircraft_roles_path(@aircraft, anchor: "invitations") %>
-31
View File
@@ -39,37 +39,6 @@
</details> </details>
</section> </section>
<%# Invitation codes for this aircraft (AircraftInvitationsController). %>
<section class="card" id="invitations">
<div class="card-header"><h2 class="card-title"><%= t(".invitations") %></h2></div>
<% if @invitations.any? %>
<ul class="divide-y divide-slate-100">
<% @invitations.each do |inv| %>
<li class="flex flex-wrap items-center justify-between gap-2 px-4 py-3 text-sm">
<div>
<span class="font-medium"><%= inv.label %></span>
<span class="badge-blue"><%= inv.grants.first&.role&.name %></span>
<% if inv.expired? %><span class="badge-red"><%= t(".expired") %></span><% elsif inv.used_up? %><span class="badge-gray"><%= t(".used") %></span><% end %>
<div class="text-xs text-slate-500"><%= [ inv.email, t(".uses_html", used: inv.uses_count, max: inv.max_uses || "∞"), (inv.expires_at ? t(".until", time: l(inv.expires_at, format: :app)) : t(".never_expires")), inv.created_by&.display_name ].compact.join(" · ") %></div>
</div>
<% if inv.usable? %><%= delete_button t(".revoke"), aircraft_invitation_path(@aircraft, inv), confirm: t(".revoke_invitation") %><% end %>
</li>
<% end %>
</ul>
<% else %>
<%= empty_state t(".no_invitations") %>
<% end %>
<%= form_with url: aircraft_invitations_path(@aircraft), class: "space-y-3 border-t border-slate-100 p-4" do |f| %>
<div class="grid gap-3 sm:grid-cols-2">
<div><%= f.label :email, t(".invite_email"), class: "label" %><%= f.email_field :email, class: "input", placeholder: t(".optional") %></div>
<div><%= f.label :role_id, t(".role"), class: "label" %><%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: Role.for_key("pilot").id }, class: "input" %></div>
<div><%= f.label :max_uses, t(".max_uses"), class: "label" %><%= f.number_field :max_uses, value: 1, min: 1, max: 1000, class: "input" %></div>
<div><%= f.label :expires_at, t(".expires"), class: "label" %><%= f.datetime_field :expires_at, value: AccessInvitation::VALID_FOR.from_now.strftime("%Y-%m-%dT%H:%M"), class: "input" %></div>
</div>
<p class="hint"><%= t(".invitation_hint") %></p>
<%= f.submit t(".create_invitation"), class: "btn-primary" %>
<% end %>
</section>
<% end %> <% end %>
<% if can?(:manage_sharing) %> <% if can?(:manage_sharing) %>
+1 -21
View File
@@ -887,11 +887,6 @@ en:
account_exists: There's already an account for that email address. Sign in, then open the link again. account_exists: There's already an account for that email address. Sign in, then open the link again.
welcome: Welcome! Your account is ready. welcome: Welcome! Your account is ready.
accepted: Invitation accepted. accepted: Invitation accepted.
aircraft_invitations:
default_label: Invitation to %{tail_number}
created_event: Invitation made (%{role})
revoked_event: Invitation revoked
revoked: Invitation revoked.
admin_invitations: admin_invitations:
revoked: Invitation revoked. revoked: Invitation revoked.
aircraft_roles: aircraft_roles:
@@ -1248,7 +1243,7 @@ en:
index: index:
invitations: Invitations invitations: Invitations
new_invitation: New invitation new_invitation: New invitation
intro: An invitation is a link someone opens to create an account, or accept with the one they have, and get roles on aircraft. New accounts come only from administrators and their invitations; an aircraft's Owner can invite people who already have an account from its Access page. intro: An invitation is a link someone opens to create an account, or accept with the one they have, and get roles on aircraft. An aircraft's Owner adds people who already have an account from its Access page (by email), and invites outside mechanics to sign an entry.
label: Invitation label: Invitation
gives: Gives gives: Gives
uses: Used uses: Used
@@ -1962,21 +1957,6 @@ en:
role_for: Role for %{display_name} role_for: Role for %{display_name}
role: Role role: Role
what_each_role_can_do: What each role can do what_each_role_can_do: What each role can do
invitations: Invitations
expired: Expired
used: Used
uses_html: "%{used} of %{max} used"
until: until %{time}
never_expires: never expires
revoke: Revoke
revoke_invitation: Revoke this invitation? Its link stops working; people who already used it keep their access.
no_invitations: No open invitations.
invite_email: Email
optional: Optional
max_uses: Uses
expires: Expires
invitation_hint: A link that gives the role on this aircraft to whoever opens it and signs in. It's for people who already have an account (only the administrator makes new ones). With an email, it only works for that address (and is emailed to it when email is set up). Leave the expiry empty for never, or the uses empty for unlimited.
create_invitation: Create invitation
roles_are_set_by_an_administrator: An administrator sets what each role can do, and can add roles (Admin → Roles). Only an Owner can give or take away the Owner role. roles_are_set_by_an_administrator: An administrator sets what each role can do, and can add roles (Admin → Roles). Only an Owner can give or take away the Owner role.
share_links: Share Links share_links: Share Links
expired: Expired expired: Expired
-1
View File
@@ -112,7 +112,6 @@ Rails.application.routes.draw do
resource :loading_setup, path: "weight_balance/loading", only: %i[edit update] # before the records' :id routes resource :loading_setup, path: "weight_balance/loading", only: %i[edit update] # before the records' :id routes
resources :weight_balance_records, path: "weight_balance", except: :show resources :weight_balance_records, path: "weight_balance", except: :show
resources :aircraft_roles, path: "access", only: %i[index create update destroy] resources :aircraft_roles, path: "access", only: %i[index create update destroy]
resources :invitations, controller: "aircraft_invitations", only: %i[create destroy]
resources :share_tokens, only: %i[create destroy] resources :share_tokens, only: %i[create destroy]
resource :export, controller: "aircraft_exports", only: :show resource :export, controller: "aircraft_exports", only: :show
resource :report, controller: "maintenance_reports", only: :show resource :report, controller: "maintenance_reports", only: :show
+1 -1
View File
@@ -28,7 +28,7 @@ To give someone a role on any aircraft, open them in **Admin → Users**: **Airc
## Invitations ## Invitations
**Admin → Invitations → New invitation** makes a link someone opens to create their own account (or accept with the one they have) and get roles on aircraft. New accounts are made by an administrator (here, or from **Users**), by an administrator's invitation, or by an outside mechanic from an Owner's signing invitation (**Ask someone to sign**). Invitations from an aircraft's Access page are for people who already have an account. Since Owners can bring in mechanics, **Settings → Who can add aircraft** decides who can become one. An invitation has a label for you, optionally an email address (then only that address can use it, and the link is emailed to it when email is set up) and a name, how many times it works (empty for unlimited, e.g. for a flying club), when it expires (empty for never), and a role on any of the aircraft (none at all gives just an account). The link is shown once, when it's made; copy it then. **Admin → Invitations → New invitation** makes a link someone opens to create their own account (or accept with the one they have) and get roles on aircraft. New accounts are made by an administrator (here, or from **Users**), by an administrator's invitation, or by an outside mechanic from an Owner's signing invitation (**Ask someone to sign**). Since Owners can bring in mechanics, **Settings → Who can add aircraft** decides who can become one. An invitation has a label for you, optionally an email address (then only that address can use it, and the link is emailed to it when email is set up) and a name, how many times it works (empty for unlimited, e.g. for a flying club), when it expires (empty for never), and a role on any of the aircraft (none at all gives just an account). The link is shown once, when it's made; copy it then.
Where someone already has a role on an aircraft, an invitation leaves it as it is. An invitation never gives more than whoever made it can give when it's used. **Revoke** stops a link working; people who already used it keep their access. With single sign-on, **Continue with** on the invitation page signs them in and makes their account. `OIDC_AUTO_CREATE_USERS=true` in the server's settings instead gives an account to anyone the provider lets in, without an invitation; leave it off to keep accounts to administrators and their invitations. Where someone already has a role on an aircraft, an invitation leaves it as it is. An invitation never gives more than whoever made it can give when it's used. **Revoke** stops a link working; people who already used it keep their access. With single sign-on, **Continue with** on the invitation page signs them in and makes their account. `OIDC_AUTO_CREATE_USERS=true` in the server's settings instead gives an account to anyone the provider lets in, without an invitation; leave it off to keep accounts to administrators and their invitations.
+2 -2
View File
@@ -8,9 +8,9 @@ Add people by email with a role: **Owner**, **Mechanic**, **Pilot**, **Viewer**,
Only an Owner can give or take away the Owner role, nobody can change their own, and an aircraft always keeps at least one Owner. An administrator can also give people roles on any aircraft from **Admin → Users**. Only an Owner can give or take away the Owner role, nobody can change their own, and an aircraft always keeps at least one Owner. An administrator can also give people roles on any aircraft from **Admin → Users**.
## Invitations ## Someone without an account
To bring in someone who has an account, without knowing their email, use **Invitations** on the same page (new accounts are made only by the administrator or an administrator's invitation, so ask the administrator for someone who has no account yet): choose the role, optionally their email (then only they can use it, and it's emailed to them when email is set up), how many times it works and when it expires, then **Create invitation**. Copy the link shown and send it; it isn't shown again. Whoever opens it creates an account, or signs in, and gets the role on this aircraft. **Revoke** stops a link that hasn't been used. Administrators can also make invitations for several aircraft at once (Admin → Invitations). For someone who doesn't have an account yet, ask the administrator: they add the account, or send an invitation link that makes it and gives the role (Admin → Invitations). An outside mechanic who only needs to sign an entry can create their own account from your signing invitation (**Ask someone to sign** on the entry; see [Electronic records and signing](records.md)).
## Share links ## Share links
+14 -34
View File
@@ -112,37 +112,25 @@ class InvitationsTest < ActionDispatch::IntegrationTest
assert_equal 0, inv.reload.uses_count assert_equal 0, inv.reload.uses_count
end end
test "an aircraft's manager invites to it from its Access page, emailed, with only roles they can give" do test "an administrator's invitation for one address is emailed to it" do
sign_in @owner sign_in @admin
assert_emails 1 do assert_emails 1 do
perform_enqueued_jobs do perform_enqueued_jobs do
post aircraft_invitations_path(@a), params: { email: "Mech@Example.com", role_id: Role.for_key("mechanic").id, max_uses: 1, expires_at: "" } post admin_invitations_path, params: { access_invitation: { label: "Mechanic", email: "Mech@Example.com", max_uses: 1 }, roles: { @a.id => Role.for_key("mechanic").id } }
end end
end end
assert_response :success
link = join_link_in(response.body) link = join_link_in(response.body)
assert_includes ActionMailer::Base.deliveries.last.text_part.body.to_s, link mail = ActionMailer::Base.deliveries.last
assert_equal [ "mech@example.com" ], ActionMailer::Base.deliveries.last.to assert_equal [ "mech@example.com" ], mail.to
inv = AccessInvitation.last assert_includes mail.text_part.body.to_s, link
assert_equal "Invitation to N12345", inv.label end
test "an aircraft's Access page adds people by email, without invitation links" do
sign_in @owner
get aircraft_aircraft_roles_path(@a) get aircraft_aircraft_roles_path(@a)
assert_select "#invitations li", 1 assert_select "form[action=?]", aircraft_aircraft_roles_path(@a)
assert_select "#invitations select[name=role_id] option", text: "Owner" assert_select "#invitations", 0
assert_not_includes response.body, "Create invitation"
partner_role = Role.create!(name: "Partner", permissions: %w[manage_people])
partner = create_user("partner@example.com")
@a.roles.create!(user: partner, role: partner_role)
sign_in partner
post aircraft_invitations_path(@a), params: { role_id: Role.owner.id, max_uses: 1 }
assert_equal 1, AccessInvitation.count
delete aircraft_invitation_path(@a, inv)
assert inv.reload.revoked?
viewer = create_user("viewer@example.com")
@a.roles.create!(user: viewer, role: "viewer")
sign_in viewer
post aircraft_invitations_path(@a), params: { role_id: Role.for_key("viewer").id, max_uses: 1 }
assert_equal 1, AccessInvitation.count
end end
test "an invitation can't give more than its creator can when it's used" do test "an invitation can't give more than its creator can when it's used" do
@@ -159,15 +147,7 @@ class InvitationsTest < ActionDispatch::IntegrationTest
assert_match "N12345:", flash[:notice] assert_match "N12345:", flash[:notice]
end end
test "an invitation of someone else's aircraft can't be revoked from another aircraft's page" do test "only an administrator's invitation makes new accounts; others' are for existing accounts" do
inv = invitation(grants: [ [ @b, "pilot" ] ])
sign_in @owner
delete aircraft_invitation_path(@a, inv)
assert_response :not_found
assert_not inv.reload.revoked?
end
test "only an administrator's invitation makes new accounts; an owner's is for existing accounts" do
owners = invitation(creator: @owner, grants: [ [ @a, "pilot" ] ]) owners = invitation(creator: @owner, grants: [ [ @a, "pilot" ] ])
get join_path(owners.token) get join_path(owners.token)
assert_select "form[action=?]", account_join_path(owners.token), 0 assert_select "form[action=?]", account_join_path(owners.token), 0