Make first user of instance automatically super_admin (#655)

* Implement dynamic role assignment for new family creators.

Introduced `User.role_for_new_family_creator` to assign `super_admin` to the first user of an instance and a configurable fallback role (e.g., `admin`) to subsequent users. Updated controllers and tests accordingly.

* Update default fallback role for family creators to admin.

---------

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
LPW
2026-01-16 15:27:55 -05:00
committed by GitHub
parent 0c2026680c
commit 9792ab838f
7 changed files with 61 additions and 6 deletions

View File

@@ -14,6 +14,35 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to root_url
end
test "first user of instance becomes super_admin" do
# Clear all users to simulate fresh instance
User.destroy_all
assert_difference "User.count", +1 do
post registration_url, params: { user: {
email: "firstuser@example.com",
password: "Password1!" } }
end
first_user = User.find_by(email: "firstuser@example.com")
assert first_user.super_admin?, "First user should be super_admin"
end
test "subsequent users become admin not super_admin" do
# Ensure users exist from fixtures
assert User.exists?
assert_difference "User.count", +1 do
post registration_url, params: { user: {
email: "seconduser@example.com",
password: "Password1!" } }
end
new_user = User.find_by(email: "seconduser@example.com")
assert new_user.admin?, "Subsequent user should be admin"
assert_not new_user.super_admin?, "Subsequent user should not be super_admin"
end
test "create when hosted requires an invite code" do
with_env_overrides REQUIRE_INVITE_CODE: "true" do
assert_no_difference "User.count" do