mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
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>
129 lines
7.7 KiB
ERB
129 lines
7.7 KiB
ERB
<% content_for :title, t(".access", tail_number: @aircraft.tail_number) %>
|
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
|
<h2 class="mb-4 text-lg font-semibold"><%= t(".access_sharing_html") %></h2>
|
|
<div class="grid gap-5 lg:grid-cols-2">
|
|
<% if can?(:manage_people) %>
|
|
<section class="card">
|
|
<div class="card-header"><h2 class="card-title"><%= t(".people") %></h2></div>
|
|
<% roles = @access.assignable_roles %>
|
|
<table class="table">
|
|
<tbody>
|
|
<% @roles.each do |r| %>
|
|
<tr>
|
|
<td><%= r.user.display_name %><div class="text-xs text-slate-500"><%= r.user.email_address %></div></td>
|
|
<td>
|
|
<% if roles.include?(r.role) && (r.user != current_user || current_user.admin?) %>
|
|
<%= form_with url: aircraft_aircraft_role_path(@aircraft, r), method: :patch do |f| %>
|
|
<%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: r.role_id }, class: "input w-36", "aria-label": t(".role_for", display_name: r.user.display_name), data: { submit_on_change: true } %>
|
|
<% end %>
|
|
<% else %>
|
|
<span class="badge-gray" title="<%= r.role.description %>"><%= r.role.name %></span>
|
|
<% end %>
|
|
</td>
|
|
<td class="text-right"><% if r.user != current_user && roles.include?(r.role) %><%= delete_button t(".remove"), aircraft_aircraft_role_path(@aircraft, r), confirm: t(".remove_s_access", display_name: r.user.display_name) %><% end %></td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
<%= form_with url: aircraft_aircraft_roles_path(@aircraft), class: "flex flex-wrap items-end gap-2 border-t border-slate-100 p-4" do |f| %>
|
|
<div class="w-full sm:w-auto sm:flex-1"><%= f.label :email_address, t(".add_by_email"), class: "label" %><%= f.email_field :email_address, class: "input", required: true %></div>
|
|
<%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: Role.for_key("pilot").id }, class: "input w-36", "aria-label": t(".role") %>
|
|
<%= f.submit t(".add"), class: "btn-primary" %>
|
|
<% end %>
|
|
<details class="px-4 pb-4 text-sm">
|
|
<summary class="cursor-pointer text-slate-600"><%= t(".what_each_role_can_do") %></summary>
|
|
<dl class="mt-2 space-y-1">
|
|
<% Role.ordered.each do |role| %><div><dt class="inline font-semibold"><%= role.name %>:</dt> <dd class="inline text-slate-600"><%= role.description.presence || role.permissions.map { Permission.label(_1) }.to_sentence %></dd></div><% end %>
|
|
</dl>
|
|
<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) %>
|
|
<section class="card">
|
|
<div class="card-header"><h2 class="card-title"><%= t(".share_links") %></h2></div>
|
|
<% if @share_tokens.any? %>
|
|
<ul class="divide-y divide-slate-100">
|
|
<% @share_tokens.each do |t| %>
|
|
<li class="px-4 py-3">
|
|
<div class="flex items-center justify-between gap-2">
|
|
<div>
|
|
<span class="font-medium"><%= t.label.presence || t(".untitled_link") %></span>
|
|
<%= tag.span ShareToken::PRIVILEGES[t.privilege], class: t.maintenance? ? "badge-blue" : "badge-green" %>
|
|
<% if t.expired? %><span class="badge-red"><%= t(".expired") %></span><% end %>
|
|
</div>
|
|
<%= delete_button t(".revoke"), aircraft_share_token_path(@aircraft, t), confirm: t(".revoke_this_link_anyone_using") %>
|
|
</div>
|
|
<input type="text" readonly value="<%= shared_url(t.token) %>" class="input mt-2 font-mono text-xs" data-select-on-click>
|
|
<div class="mt-1 text-xs text-slate-500"><%= t(".created_html", to_date: (fmt_date(t.created_at.to_date)), created_by: (" by #{t.created_by.display_name}" if t.created_by), expires: (t.expires_at ? "expires #{l t.expires_at, format: :short}" : t(".never_expires"))) %></div>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
<% else %>
|
|
<%= empty_state t(".no_share_links") %>
|
|
<% end %>
|
|
<%= form_with model: ShareToken.new, url: aircraft_share_tokens_path(@aircraft), class: "space-y-3 border-t border-slate-100 p-4" do |f| %>
|
|
<div class="grid gap-3 sm:grid-cols-3">
|
|
<%= f.field :label, placeholder: t(".mechanic_buyer") %>
|
|
<%= f.field :privilege, as: :select, label: t(".shows"), collection: ShareToken::PRIVILEGES.invert %>
|
|
<%= f.field :expires_at, as: :datetime, label: t(".expires_optional") %>
|
|
</div>
|
|
<p class="hint"><%= t(".current_status_overview_airworthiness_components_html") %></p>
|
|
<%= f.submit t(".create_share_link") %>
|
|
<% end %>
|
|
</section>
|
|
<% end %>
|
|
|
|
<% if can?(:export_data) %>
|
|
<section class="card lg:col-span-2">
|
|
<div class="card-header">
|
|
<div>
|
|
<h2 class="card-title"><%= t(".backup_transfer_html") %></h2>
|
|
<p class="hint"><%= t(".everything_recorded_for_with_its_html", tail_number: @aircraft.tail_number) %></p>
|
|
</div>
|
|
<%= link_to t(".download_sam_zip"), aircraft_export_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
|
|
</div>
|
|
<div class="card-header border-t border-slate-100">
|
|
<div>
|
|
<h2 class="card-title"><%= t(".records_package") %></h2>
|
|
<p class="hint"><%= t(".for_an_faa_or_ntsb") %></p>
|
|
</div>
|
|
<%= link_to t(".download_records_package"), aircraft_records_package_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
|
|
</div>
|
|
</section>
|
|
<% end %>
|
|
</div>
|