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

+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