mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23: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,11 @@
|
||||
<%# What the invitation gives: a role on each of its aircraft (or just an account). %>
|
||||
<% grants = invitation.grants.includes(:aircraft, :role).sort_by { _1.aircraft.tail_number } %>
|
||||
<% if grants.any? %>
|
||||
<ul class="space-y-1 text-sm">
|
||||
<% grants.each do |g| %>
|
||||
<li class="flex items-baseline gap-2"><span class="font-semibold"><%= g.aircraft.tail_number %></span> <span class="text-slate-500"><%= [ g.aircraft.make, g.aircraft.model ].compact_blank.join(" ") %></span> <span class="badge-blue" title="<%= g.role.description %>"><%= g.role.name %></span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p class="text-sm text-slate-600"><%= t("joins.grants.account_only") %></p>
|
||||
<% end %>
|
||||
@@ -0,0 +1,11 @@
|
||||
<% content_for :title, t(".invitation") %>
|
||||
<div class="mx-auto max-w-md space-y-4">
|
||||
<h1 class="text-2xl font-bold"><%= t(".youre_invited") %></h1>
|
||||
<div class="card card-body space-y-3">
|
||||
<p class="text-sm text-slate-600"><%= t(".invited_by_html", who: (@invitation.created_by&.display_name || t(".an_administrator")), label: @invitation.label) %></p>
|
||||
<%= render "joins/grants", invitation: @invitation %>
|
||||
<p class="hint"><%= t(".existing_roles_stay") %></p>
|
||||
<%= button_to t(".accept"), accept_join_path(params[:token]), class: "btn-primary w-full justify-center", form: { class: "pt-1" } %>
|
||||
</div>
|
||||
<p class="text-center text-sm text-slate-500"><%= t(".signed_in_as", email: current_user.email_address) %></p>
|
||||
</div>
|
||||
@@ -0,0 +1,5 @@
|
||||
<% content_for :title, t(".invitation") %>
|
||||
<div class="mx-auto max-w-md card card-body">
|
||||
<h1 class="card-title"><%= t(".not_valid") %></h1>
|
||||
<p class="mt-1 text-sm text-slate-600"><%= t(".ask_for_a_new_one") %></p>
|
||||
</div>
|
||||
@@ -0,0 +1,27 @@
|
||||
<% content_for :title, t(".invitation") %>
|
||||
<div class="mx-auto max-w-md space-y-4">
|
||||
<h1 class="text-2xl font-bold"><%= t(".youre_invited") %></h1>
|
||||
<div class="card card-body space-y-3">
|
||||
<p class="text-sm text-slate-600"><%= t(".invited_by_html", who: (@invitation.created_by&.display_name || t(".an_administrator")), label: @invitation.label) %></p>
|
||||
<%= render "joins/grants", invitation: @invitation %>
|
||||
</div>
|
||||
<div class="card card-body space-y-3">
|
||||
<%= link_to t(".i_have_an_account"), new_session_path, class: "btn-primary w-full justify-center" %>
|
||||
<% if @invitation.email %><p class="hint"><%= t(".for_email", email: @invitation.email) %></p><% end %>
|
||||
</div>
|
||||
<% if Sso.password_login? && !(@invitation.email && User.exists?(email_address: @invitation.email)) %>
|
||||
<%= form_with url: account_join_path(params[:token]), class: "card card-body space-y-3" do %>
|
||||
<h2 class="card-title"><%= t(".or_create_an_account") %></h2>
|
||||
<% if @account_errors.present? %><div class="rounded-md bg-red-50 p-2 text-sm text-red-700" role="alert"><%= @account_errors.to_sentence %></div><% end %>
|
||||
<% if @invitation.email %>
|
||||
<div><label class="label" for="invited_email"><%= t(".email") %></label><input id="invited_email" class="input" value="<%= @invitation.email %>" disabled></div>
|
||||
<% else %>
|
||||
<div><%= label_tag :email_address, t(".email"), class: "label" %><%= email_field_tag :email_address, params[:email_address], class: "input", required: true, autocomplete: "username" %></div>
|
||||
<% end %>
|
||||
<div><%= label_tag :name, t(".your_name"), class: "label" %><%= text_field_tag :name, params[:name] || @invitation.name, class: "input", required: true, autocomplete: "name" %></div>
|
||||
<div><%= label_tag :password, t(".password"), class: "label" %><%= password_field_tag :password, nil, class: "input", required: true, autocomplete: "new-password", minlength: User::PASSWORD_MIN, maxlength: 72 %><p class="hint"><%= t(".password_hint", min: User::PASSWORD_MIN) %></p></div>
|
||||
<div><%= label_tag :password_confirmation, t(".confirm_password"), class: "label" %><%= password_field_tag :password_confirmation, nil, class: "input", required: true, autocomplete: "new-password" %></div>
|
||||
<%= submit_tag t(".create_account"), class: "btn-secondary", data: { turbo_submits_with: t(".creating") } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
<% content_for :title, t(".invitation") %>
|
||||
<div class="mx-auto max-w-md card card-body space-y-3">
|
||||
<h1 class="card-title"><%= t(".wrong_account") %></h1>
|
||||
<p class="text-sm text-slate-600"><%= t(".for_another_email_html", email: @invitation.email, email_address: current_user.email_address) %></p>
|
||||
<%= button_to t(".sign_out"), session_path, method: :delete, class: "btn-secondary" %>
|
||||
</div>
|
||||
Reference in new issue
Block a user