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,32 @@
|
||||
# Invitation codes for any aircraft, or none (an account only), by
|
||||
# administrators (AccessInvitation).
|
||||
class Admin::InvitationsController < ApplicationController
|
||||
before_action :require_admin!
|
||||
|
||||
def index
|
||||
@invitations = AccessInvitation.recent_first.includes(:created_by, grants: %i[aircraft role]).limit(200)
|
||||
end
|
||||
|
||||
def new
|
||||
@invitation = AccessInvitation.new(max_uses: 1, expires_at: AccessInvitation::VALID_FOR.from_now.change(sec: 0))
|
||||
end
|
||||
|
||||
def create
|
||||
roles = Role.all.index_by(&:id)
|
||||
grants = Aircraft.where(id: params.fetch(:roles, {}).keys).filter_map do |aircraft|
|
||||
role = roles[params[:roles][aircraft.id.to_s].to_i]
|
||||
[ aircraft, role ] if role
|
||||
end
|
||||
@invitation = AccessInvitation.create_for(current_user, params.require(:access_invitation).permit(:label, :email, :name, :max_uses, :expires_at), grants)
|
||||
if @invitation.persisted?
|
||||
render :created
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
AccessInvitation.find(params[:id]).update!(revoked_at: Time.current)
|
||||
redirect_to admin_invitations_path, notice: t("flash.admin_invitations.revoked")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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,6 +11,8 @@ class AircraftRolesController < ApplicationController
|
||||
@access = AircraftAccess.new(@aircraft, actor: current_user)
|
||||
@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)
|
||||
@invitations = AccessInvitation.where(id: AircraftInvitationsController.only_for(@aircraft), revoked_at: nil)
|
||||
.recent_first.includes(:created_by, grants: :role).limit(20)
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Opening an invitation link (AccessInvitation): see what it gives, then
|
||||
# create an account (when sign-in by password is on) or sign in, and accept.
|
||||
# An invitation for one email address only works for that address. An
|
||||
# invalid link (unknown, expired, used up, revoked) gets one answer for all.
|
||||
class JoinsController < ApplicationController
|
||||
allow_unauthenticated_access only: %i[show account]
|
||||
before_action :set_invitation
|
||||
rate_limit to: 10, within: 15.minutes, only: %i[account accept],
|
||||
with: -> { redirect_to join_path(params[:token]), alert: t("flash.joins.try_again_later") }
|
||||
|
||||
def show
|
||||
unless current_user
|
||||
session[:return_to_after_authenticating] = request.url
|
||||
return render(:welcome)
|
||||
end
|
||||
return redirect_to(root_path, notice: t("flash.joins.already_accepted")) if @invitation.redeemed_by?(current_user)
|
||||
return render(:wrong_account) unless @invitation.for?(current_user)
|
||||
render :accept
|
||||
end
|
||||
|
||||
# A new account, then the invitation accepted with it.
|
||||
def account
|
||||
return redirect_to(join_path(params[:token])) if current_user
|
||||
return redirect_to(join_path(params[:token]), alert: t("flash.joins.sign_in_to_continue")) unless Sso.password_login?
|
||||
email = @invitation.email || params[:email_address].to_s.strip.downcase
|
||||
if User.exists?(email_address: email)
|
||||
return redirect_to join_path(params[:token]), alert: t("flash.joins.account_exists")
|
||||
end
|
||||
user = User.new(params.permit(:name, :password, :password_confirmation).merge(email_address: email))
|
||||
results = nil
|
||||
User.transaction do
|
||||
raise ActiveRecord::Rollback unless user.save
|
||||
results = @invitation.redeem!(user)
|
||||
end
|
||||
if results
|
||||
reset_session
|
||||
start_new_session_for user
|
||||
redirect_to root_path, notice: summary(results, t("flash.joins.welcome"))
|
||||
else
|
||||
@account_errors = user.errors.full_messages
|
||||
render :welcome, status: :unprocessable_entity
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
render :invalid, layout: "public", status: :not_found
|
||||
end
|
||||
|
||||
def accept
|
||||
return redirect_to(root_path, notice: t("flash.joins.already_accepted")) if @invitation.redeemed_by?(current_user)
|
||||
return render(:wrong_account) unless @invitation.for?(current_user)
|
||||
redirect_to root_path, notice: summary(@invitation.redeem!(current_user), t("flash.joins.accepted"))
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
render :invalid, layout: "public", status: :not_found
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_invitation
|
||||
@invitation = AccessInvitation.find_by_token(params[:token])
|
||||
render :invalid, layout: "public", status: :not_found unless @invitation&.usable?
|
||||
end
|
||||
|
||||
# "Invitation accepted. N12345: Mechanic. N54321: already Owner, unchanged."
|
||||
def summary(results, lead)
|
||||
parts = results.map do |aircraft, role, message|
|
||||
"#{aircraft.tail_number}: #{[ role&.name, message ].compact.join(', ')}"
|
||||
end
|
||||
[ lead, *parts ].join(" ")
|
||||
end
|
||||
|
||||
def current_user = Current.user || (resume_session && Current.user)
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
# The link of an invitation made for one email address (AccessInvitation).
|
||||
class AccessInvitationMailer < ApplicationMailer
|
||||
def invite(invitation, token)
|
||||
@invitation = invitation
|
||||
@grants = invitation.grants.includes(:aircraft, :role).sort_by { _1.aircraft.tail_number }
|
||||
@url = join_url(token)
|
||||
mail subject: t(".subject", who: invitation.created_by&.display_name || t(".an_administrator")), to: invitation.email
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,74 @@
|
||||
# An invitation code: a link someone opens to create an account (or accept
|
||||
# with the one they have) and get roles on aircraft. Made by administrators
|
||||
# (Admin → Invitations, any aircraft) or by whoever manages an aircraft's
|
||||
# people (its Access page, that aircraft). Limited by number of uses, an
|
||||
# expiry, and optionally to one email address; it can be revoked. Only a
|
||||
# digest of the code is kept, so the link is shown once, when it's made.
|
||||
class AccessInvitation < ApplicationRecord
|
||||
VALID_FOR = 14.days
|
||||
|
||||
belongs_to :created_by, class_name: "User", optional: true
|
||||
has_many :grants, class_name: "AccessInvitationRole", dependent: :delete_all
|
||||
has_many :redemptions, class_name: "AccessInvitationRedemption", dependent: :delete_all
|
||||
has_many :aircraft, through: :grants
|
||||
|
||||
attr_reader :token
|
||||
|
||||
normalizes :email, with: ->(email) { email.strip.downcase.presence }
|
||||
normalizes :label, :name, with: ->(text) { text.squish.presence }
|
||||
validates :label, presence: true, length: { maximum: 100 }
|
||||
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_nil: true
|
||||
validates :max_uses, numericality: { only_integer: true, greater_than: 0, less_than_or_equal_to: 1000 }, allow_nil: true
|
||||
before_validation(on: :create) do
|
||||
@token = SecureRandom.urlsafe_base64(24)
|
||||
self.token_digest = self.class.digest(@token)
|
||||
end
|
||||
|
||||
scope :recent_first, -> { order(created_at: :desc) }
|
||||
scope :usable, -> {
|
||||
where(revoked_at: nil).where("expires_at IS NULL OR expires_at > ?", Time.current).where("max_uses IS NULL OR uses_count < max_uses")
|
||||
}
|
||||
|
||||
# A new invitation by creator giving roles ([[aircraft, role], …]); its
|
||||
# link is emailed when it's for one address and email is set up.
|
||||
def self.create_for(creator, attributes, grants)
|
||||
invitation = new(attributes.merge(created_by: creator))
|
||||
grants.each { |aircraft, role| invitation.grants.build(aircraft: aircraft, role: role) }
|
||||
if invitation.save && invitation.email && MailSettings.configured?
|
||||
AccessInvitationMailer.invite(invitation, invitation.token).deliver_later
|
||||
end
|
||||
invitation
|
||||
end
|
||||
|
||||
def self.digest(token) = OpenSSL::Digest::SHA256.hexdigest(token.to_s)
|
||||
def self.find_by_token(token) = token.present? ? find_by(token_digest: digest(token)) : nil
|
||||
|
||||
def usable? = !revoked? && !expired? && !used_up?
|
||||
def revoked? = revoked_at.present?
|
||||
def expired? = expires_at.present? && expires_at <= Time.current
|
||||
def used_up? = max_uses.present? && uses_count >= max_uses
|
||||
def for?(user) = email.nil? || email == user.email_address
|
||||
def redeemed_by?(user) = redemptions.exists?(user: user)
|
||||
|
||||
# Gives the person the invitation's roles, as if its creator added them
|
||||
# (AircraftAccess: so it can't give more than they could, then or now).
|
||||
# A role they already have on an aircraft stays as it is. Returns
|
||||
# [[aircraft, role or nil, message or nil], …].
|
||||
def redeem!(user)
|
||||
with_lock do
|
||||
raise ActiveRecord::RecordInvalid, self unless usable? && for?(user)
|
||||
redemptions.create!(user: user)
|
||||
increment!(:uses_count)
|
||||
grants.includes(:aircraft, :role).map do |grant|
|
||||
if (existing = grant.aircraft.roles.find_by(user: user))
|
||||
[ grant.aircraft, nil, I18n.t("models.access_invitation.already_has", role: existing.role.name) ]
|
||||
elsif created_by.nil? || created_by.disabled? || !created_by.can?(:manage_people, grant.aircraft)
|
||||
[ grant.aircraft, nil, I18n.t("models.access_invitation.creator_gone") ]
|
||||
else
|
||||
error = AircraftAccess.new(grant.aircraft, actor: created_by).add(user, grant.role)
|
||||
[ grant.aircraft, (grant.role unless error), error ]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# Who used an invitation, and when (once per person).
|
||||
class AccessInvitationRedemption < ApplicationRecord
|
||||
belongs_to :access_invitation
|
||||
belongs_to :user
|
||||
|
||||
validates :user_id, uniqueness: { scope: :access_invitation_id }
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
# A role an invitation gives on one aircraft.
|
||||
class AccessInvitationRole < ApplicationRecord
|
||||
belongs_to :access_invitation
|
||||
belongs_to :aircraft
|
||||
belongs_to :role
|
||||
|
||||
validates :aircraft_id, uniqueness: { scope: :access_invitation_id }
|
||||
end
|
||||
@@ -9,6 +9,7 @@ class Aircraft < ApplicationRecord
|
||||
end
|
||||
|
||||
has_many :roles, class_name: "AircraftRole", dependent: :destroy
|
||||
has_many :invitation_grants, class_name: "AccessInvitationRole", dependent: :delete_all
|
||||
has_many :users, through: :roles
|
||||
has_many :notes, class_name: "AircraftNote", dependent: :destroy
|
||||
has_many :events, class_name: "AircraftEvent", dependent: :delete_all
|
||||
|
||||
@@ -7,6 +7,7 @@ class Role < ApplicationRecord
|
||||
BUILT_IN = %w[owner mechanic pilot viewer].freeze
|
||||
|
||||
has_many :aircraft_roles, dependent: :restrict_with_error
|
||||
has_many :invitation_grants, class_name: "AccessInvitationRole", dependent: :delete_all
|
||||
|
||||
normalizes :name, with: ->(name) { name.squish }
|
||||
validates :name, presence: true, uniqueness: { case_sensitive: false }, length: { maximum: 40 }
|
||||
|
||||
@@ -2,6 +2,8 @@ class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_many :aircraft_roles, dependent: :destroy
|
||||
has_many :access_invitations, foreign_key: :created_by_id, dependent: :nullify, inverse_of: :created_by
|
||||
has_many :access_invitation_redemptions, dependent: :delete_all
|
||||
has_many :push_subscriptions, dependent: :delete_all
|
||||
has_many :api_tokens, dependent: :destroy
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<p><%= t(".invites_you_html", who: (@invitation.created_by&.display_name || t(".an_administrator"))) %></p>
|
||||
<% if @grants.any? %><ul><% @grants.each do |g| %><li><strong><%= g.aircraft.tail_number %></strong>: <%= g.role.name %></li><% end %></ul><% end %>
|
||||
<p><%= link_to t(".accept_the_invitation"), @url %></p>
|
||||
<% if @invitation.expires_at %><p style="color:#64748b;font-size:12px"><%= t(".expires_html", date: fmt_date(@invitation.expires_at.to_date)) %></p><% end %>
|
||||
@@ -0,0 +1,11 @@
|
||||
<%= raw t(".invites_you_text", who: (@invitation.created_by&.display_name || t(".an_administrator"))) %>
|
||||
<% @grants.each do |g| %>
|
||||
- <%= g.aircraft.tail_number %>: <%= g.role.name %>
|
||||
<% end %>
|
||||
|
||||
<%= raw t(".open_the_link_text") %>
|
||||
<%= @url %>
|
||||
<% if @invitation.expires_at %>
|
||||
|
||||
<%= raw t(".expires_text", date: fmt_date(@invitation.expires_at.to_date)) %>
|
||||
<% end %>
|
||||
@@ -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 %>
|
||||
@@ -0,0 +1,3 @@
|
||||
<% 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") %>
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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>
|
||||
@@ -50,7 +50,7 @@
|
||||
<%= link_to t(".help"), help_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||
<% if current_user.admin? %>
|
||||
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500"><%= t(".admin") %></p>
|
||||
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".invitations"), admin_invitations_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -71,7 +71,7 @@
|
||||
<%= t(".admin") %> <span aria-hidden="true" class="text-xs">▾</span>
|
||||
</summary>
|
||||
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
|
||||
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".invitations"), admin_invitations_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||
<%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<%# A just-made invitation's link: shown this once (only a digest is kept). %>
|
||||
<section class="card card-body max-w-xl space-y-3">
|
||||
<h1 class="card-title"><%= t("shared.invitation_created.title") %></h1>
|
||||
<p class="text-sm text-slate-600"><%= t("shared.invitation_created.copy_now") %></p>
|
||||
<input type="text" class="input font-mono text-xs" value="<%= join_url(invitation.token) %>" readonly data-select-on-click aria-label="<%= t("shared.invitation_created.link") %>">
|
||||
<%= render "joins/grants", invitation: invitation %>
|
||||
<p class="hint">
|
||||
<%= [ (t("shared.invitation_created.emailed", email: invitation.email) if invitation.email && MailSettings.configured?),
|
||||
(t("shared.invitation_created.only_for", email: invitation.email) if invitation.email),
|
||||
(invitation.max_uses ? t("shared.invitation_created.uses", count: invitation.max_uses) : t("shared.invitation_created.unlimited")),
|
||||
(invitation.expires_at ? t("shared.invitation_created.expires", time: l(invitation.expires_at, format: :app)) : t("shared.invitation_created.never_expires")) ].compact.join(" ") %>
|
||||
</p>
|
||||
<p><%= link_to t("shared.invitation_created.done"), back_path, class: "btn-primary" %></p>
|
||||
</section>
|
||||
Reference in new issue
Block a user