mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user