Invitation codes: a link that gives an account and roles

Ported from the original (InvitationCode), adapted to configurable roles.

- Admin → Invitations: a label, optionally one email address (only it can
  use the link, and it's emailed) and a name, how many uses (or
  unlimited), an expiry (or never), and a role on any aircraft (or none,
  for an account only).
- An aircraft's Access page: whoever manages its people invites to that
  aircraft, with only the roles they can give; they see and revoke its
  invitations.
- /join/<code>: shows what it gives; create an account (when password
  sign-in is on) or sign in, then accept. Existing accounts and SSO users
  accept too. A role someone already has on an aircraft stays.
- Roles are given as the invitation's creator (AircraftAccess), and only
  while they can still manage that aircraft's people. Codes are kept as
  digests and shown once; uses are counted under a lock; account creation
  and accepting are rate-limited; any invalid link gets the same answer.
- Docs: guide (Administration, Access & sharing), README, and why /join
  isn't on the Authentik bypass list. The README's not-yet-ported list
  now names Prometheus metrics, and no longer claims oil analysis import
  as new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-15 18:50:58 -05:00
1 parent a645778f26
commit b4c7aaa3ff
34 files changed
+822 -7

No files matched your search

+32
View File
@@ -38,6 +38,38 @@
<p class="hint mt-2"><%= t(".roles_are_set_by_an_administrator") %></p>
</details>
</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 %>
<% if can?(:manage_sharing) %>