mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15: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>
33 lines
1.1 KiB
Ruby
33 lines
1.1 KiB
Ruby
# 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
|