mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
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:
1 parent
a645778f26
commit
b4c7aaa3ff
34 files changed
+822
-7
No files matched your search
@@ -0,0 +1,2 @@
|
||||
<% content_for :title, t("shared.invitation_created.title") %>
|
||||
<%= render "shared/invitation_created", invitation: @invitation, back_path: admin_invitations_path %>
|
||||
@@ -0,0 +1,28 @@
|
||||
<% content_for :title, t(".invitations") %>
|
||||
<div class="mb-2 flex items-center justify-between"><h1 class="text-2xl font-bold"><%= t(".invitations") %></h1><%= link_to t(".new_invitation"), new_admin_invitation_path, class: "btn-primary" %></div>
|
||||
<p class="mb-4 text-sm text-slate-600"><%= t(".intro") %></p>
|
||||
<section class="card">
|
||||
<% if @invitations.any? %>
|
||||
<table class="table">
|
||||
<thead><tr><th><%= t(".label") %></th><th><%= t(".gives") %></th><th><%= t(".uses") %></th><th><%= t(".status") %></th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<% @invitations.each do |inv| %>
|
||||
<tr class="invitation-row">
|
||||
<td><span class="font-medium"><%= inv.label %></span><div class="text-xs text-slate-500"><%= [ inv.email, inv.created_by&.display_name, fmt_date(inv.created_at) ].compact.join(" · ") %></div></td>
|
||||
<td class="text-xs" data-label="<%= t(".gives") %>"><%= inv.grants.map { "#{_1.aircraft.tail_number} (#{_1.role.name})" }.join(", ").presence || t(".account_only") %></td>
|
||||
<td class="tabular-nums" data-label="<%= t(".uses") %>"><%= inv.uses_count %> / <%= inv.max_uses || "∞" %></td>
|
||||
<td data-label="<%= t(".status") %>">
|
||||
<% if inv.revoked? %><span class="badge-gray"><%= t(".revoked") %></span>
|
||||
<% elsif inv.expired? %><span class="badge-red"><%= t(".expired") %></span>
|
||||
<% elsif inv.used_up? %><span class="badge-gray"><%= t(".used") %></span>
|
||||
<% else %><span class="badge-green"><%= t(".active") %></span><span class="block text-xs text-slate-500"><%= inv.expires_at ? t(".until", time: l(inv.expires_at, format: :app)) : t(".never_expires") %></span><% end %>
|
||||
</td>
|
||||
<td class="text-right"><% if inv.usable? %><%= delete_button t(".revoke"), admin_invitation_path(inv), confirm: t(".revoke_invitation") %><% end %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<%= empty_state t(".no_invitations") %>
|
||||
<% end %>
|
||||
</section>
|
||||
@@ -0,0 +1,29 @@
|
||||
<% content_for :title, t(".new_invitation") %>
|
||||
<h1 class="mb-4 text-2xl font-bold"><%= t(".new_invitation") %></h1>
|
||||
<%= form_with model: @invitation, url: admin_invitations_path, method: :post, class: "card card-body max-w-3xl space-y-5" do |f| %>
|
||||
<%= f.errors_summary %>
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<%= f.field :label, required: true, hint: t(".label_hint") %>
|
||||
<%= f.field :email, as: :email, label: t(".email"), hint: t(".email_hint") %>
|
||||
<%= f.field :name, label: t(".name"), hint: t(".name_hint") %>
|
||||
<%= f.field :max_uses, as: :number, label: t(".max_uses"), hint: t(".max_uses_hint"), min: 1, max: 1000 %>
|
||||
<%= f.field :expires_at, as: :datetime, label: t(".expires"), hint: t(".expires_hint") %>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend class="mb-2 text-sm font-semibold"><%= t(".roles") %></legend>
|
||||
<% aircraft = Aircraft.ordered.to_a %>
|
||||
<% if aircraft.any? %>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<% roles = Role.ordered.map { [ _1.name, _1.id ] } %>
|
||||
<% aircraft.each do |a| %>
|
||||
<label class="flex items-center justify-between gap-3 text-sm">
|
||||
<span><span class="font-medium"><%= a.tail_number %></span> <span class="text-xs text-slate-500"><%= [ a.make, a.model ].compact_blank.join(" ") %></span></span>
|
||||
<%= select_tag "roles[#{a.id}]", options_for_select([ [ t(".no_access"), "" ] ] + roles, params.dig(:roles, a.id.to_s)), class: "input w-36" %>
|
||||
</label>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<p class="hint mt-2"><%= t(".roles_hint") %></p>
|
||||
</fieldset>
|
||||
<div class="flex flex-wrap gap-2"><%= f.submit t(".create") %><%= link_to t(".cancel"), admin_invitations_path, class: "btn-secondary" %></div>
|
||||
<% end %>
|
||||
Reference in new issue
Block a user