New accounts only from an administrator or an administrator's invitation

Anyone can add an aircraft and so manage its people, so invitations from
non-administrators could bring in new accounts without an administrator.

- An invitation makes a new account only if whoever made it is still an
  administrator when it's used; an aircraft's Access page invitations are
  for people who already have an account (its welcome page says so).
- Signing invitations no longer make accounts: the mechanic needs one
  first, and the owner is told when they don't have one.
- With SSO, "Continue with <provider>" on an administrator's invitation
  makes the account and accepts the invitation (only for its address when
  it has one), so invitations work without OIDC_AUTO_CREATE_USERS. That
  setting stays, documented as giving accounts without an invitation; the
  Authentik example now leaves it off.
- Docs: who makes accounts (guide, README, Authentik, .env.example, API).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-15 19:00:45 -05:00
1 parent b4c7aaa3ff
commit 19bc3efa19
19 files changed
+159 -85

No files matched your search

+10 -1
View File
@@ -159,6 +159,7 @@ class ElectronicSignaturesTest < ActionDispatch::IntegrationTest
post aircraft_logbook_entry_signing_invitations_path(@a, @entry), params: { signing_invitation: { email: "Outside@Example.com", message: "Thanks!" } }
end
end
assert_match "They don't have an account here yet", flash[:notice]
mail = ActionMailer::Base.deliveries.last
assert_equal [ "outside@example.com" ], mail.to
path = mail.text_part.body.to_s[%r{http://example\.com(/sign/[\w-]+)}, 1]
@@ -166,8 +167,16 @@ class ElectronicSignaturesTest < ActionDispatch::IntegrationTest
get path
assert_includes response.body, "sign in as <strong>outside@example.com</strong>"
assert_includes response.body, "no account for outside@example.com yet" # a signing link doesn't make accounts
post "#{path}/account", params: { name: "Olive Outside", password: "longpassword1", password_confirmation: "longpassword1" }
assert_redirected_to path
assert_response :not_found
assert_not User.exists?(email_address: "outside@example.com")
# The administrator adds their account; they sign in and come back to the link.
User.create!(email_address: "outside@example.com", name: "Olive Outside", password: "longpassword1")
get path
post session_path, params: { email_address: "outside@example.com", password: "longpassword1" }
assert_redirected_to "http://www.example.com#{path}"
follow_redirect!
assert_select "form[action='#{certificates_path(return_to: path)}']" # add a certificate first
post certificates_path(return_to: path), params: { user_certificate: { kind: "IA", number: "2222222" } }
+22
View File
@@ -166,4 +166,26 @@ class InvitationsTest < ActionDispatch::IntegrationTest
assert_response :not_found
assert_not inv.reload.revoked?
end
test "only an administrator's invitation makes new accounts; an owner's is for existing accounts" do
owners = invitation(creator: @owner, grants: [ [ @a, "pilot" ] ])
get join_path(owners.token)
assert_select "form[action=?]", account_join_path(owners.token), 0
assert_includes response.body, "This invitation is for an existing account"
post account_join_path(owners.token), params: { email_address: "new@example.com", name: "X", password: PASSWORD, password_confirmation: PASSWORD }
assert_not User.exists?(email_address: "new@example.com")
assert_equal 0, owners.reload.uses_count
existing = create_user("existing@example.com")
sign_in existing
post accept_join_path(owners.token)
assert_equal "pilot", existing.role_for(@a).key
end
test "an administrator's invitation stops making accounts once its creator isn't an administrator" do
inv = invitation
@admin.update!(admin: false)
post account_join_path(inv.token), params: { email_address: "new@example.com", name: "X", password: PASSWORD, password_confirmation: PASSWORD }
assert_not User.exists?(email_address: "new@example.com")
end
end
+39
View File
@@ -130,4 +130,43 @@ class SsoTest < ActionDispatch::IntegrationTest
get "/auth/oidc/callback"
assert_response :not_found
end
test "signing in with SSO makes an account only from an administrator's invitation" do
ENV.delete("OIDC_AUTO_CREATE_USERS")
mock(uid: "sub-new", email: "newbie@example.com", name: "New Bie")
sso_sign_in
assert_redirected_to new_session_path
assert_not User.exists?(email_address: "newbie@example.com")
owner = create_user("owner2@example.com")
aircraft = create_aircraft(owner: owner, tail_number: "N777AB")
owners = AccessInvitation.create_for(owner, { label: "From the owner", max_uses: 1 }, [ [ aircraft, Role.for_key("pilot") ] ])
get join_path(owners.token)
assert_select "form[action='/auth/oidc']", 0
sso_sign_in
assert_not User.exists?(email_address: "newbie@example.com")
admin = create_user("boss@example.com", admin: true)
invitation = AccessInvitation.create_for(admin, { label: "Club", max_uses: 1 }, [ [ aircraft, Role.for_key("pilot") ] ])
get join_path(invitation.token)
assert_select "form[action='/auth/oidc'] button", text: "Continue with Authentik"
sso_sign_in
assert_redirected_to root_url
assert_match "Welcome! Your account is ready. N777AB: Pilot", flash[:notice]
newbie = User.find_by!(email_address: "newbie@example.com")
assert_equal "sub-new", newbie.sso_uid
assert_equal "pilot", newbie.role_for(aircraft).key
assert_equal 1, invitation.reload.uses_count
end
test "an administrator's invitation for one address makes an account only for that address" do
ENV.delete("OIDC_AUTO_CREATE_USERS")
admin = create_user("boss@example.com", admin: true)
invitation = AccessInvitation.create_for(admin, { label: "For Kim", email: "kim@example.com", max_uses: 1 }, [])
get join_path(invitation.token)
mock(uid: "sub-x", email: "someone.else@example.com")
sso_sign_in
assert_not User.exists?(email_address: "someone.else@example.com")
assert_equal 0, invitation.reload.uses_count
end
end