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>
35 lines
1.4 KiB
Ruby
35 lines
1.4 KiB
Ruby
# Invitation codes (AccessInvitation): a link someone opens to create an
|
|
# account, or accept with the one they have, and get roles on aircraft.
|
|
class CreateAccessInvitations < ActiveRecord::Migration[8.1]
|
|
def change
|
|
create_table :access_invitations do |t|
|
|
t.string :label, null: false
|
|
t.string :email
|
|
t.string :name
|
|
t.string :token_digest, null: false
|
|
t.integer :max_uses
|
|
t.integer :uses_count, null: false, default: 0
|
|
t.datetime :expires_at
|
|
t.datetime :revoked_at
|
|
t.references :created_by, foreign_key: { to_table: :users }
|
|
t.timestamps
|
|
end
|
|
add_index :access_invitations, :token_digest, unique: true
|
|
|
|
create_table :access_invitation_roles do |t|
|
|
t.references :access_invitation, null: false, foreign_key: true
|
|
t.references :aircraft, null: false, foreign_key: true
|
|
t.references :role, null: false, foreign_key: true
|
|
t.timestamps
|
|
end
|
|
add_index :access_invitation_roles, %i[access_invitation_id aircraft_id], unique: true, name: "index_access_invitation_roles_unique"
|
|
|
|
create_table :access_invitation_redemptions do |t|
|
|
t.references :access_invitation, null: false, foreign_key: true
|
|
t.references :user, null: false, foreign_key: true
|
|
t.timestamps
|
|
end
|
|
add_index :access_invitation_redemptions, %i[access_invitation_id user_id], unique: true, name: "index_access_invitation_redemptions_unique"
|
|
end
|
|
end
|