From 464dd4266bdc433805010b5dca428f4cb75c2a81 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 31 Jul 2026 15:55:43 +0200 Subject: Group user accounts by role Replaces the two-way admin/user split with four groups ordered by capability: administration, Redaktion, editors, alumni. alumni takes precedence over capability in role_group, so a retired admin appears at the bottom rather than the top. Forms now offer the three roles as checkboxes rather than a single admin checkbox, with a trailing hidden blank so an empty set can be posted, and user_params permits roles only for admins. Three create buttons prefill the common combinations. --- test/controllers/users_controller_test.rb | 27 ++++++++++++++++++--------- test/fixtures/users.yml | 3 +-- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 67f7c053..1c5d16fc 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -9,12 +9,12 @@ class UsersControllerTest < ActionController::TestCase assert_select "a", { :count => 0, :text => "Destroy" } end - test "get index as admin user renders admin partial" do + test "get index as admin shows every group with per-row actions" do login_as :aaron get :index assert_response :success assert_select "button[type=submit]", I18n.t("admin.common.destroy") - assert_select "a", "show" + assert_select "a", I18n.t("admin.common.show") end test "get new when logged in as admin" do @@ -60,7 +60,7 @@ class UsersControllerTest < ActionController::TestCase :email => "foo@bar.com", :password => "xxxzzz", :password_confirmation => "xxxzzz", - :admin => true + :roles => ["admin", "redaktion"] } } end @@ -174,19 +174,17 @@ class UsersControllerTest < ActionController::TestCase test "admin user can promote regular users to admins" do login_as :aaron user = users(:quentin) - put :update, params: { :id => user.id, :user => {:admin => true} } + put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} } - user.reload - assert_equal true, user.is_admin? + assert_equal true, user.reload.is_admin? end test "regular users cannot promote themselves to admins" do login_as :quentin user = users(:quentin) - put :update, params: { :id => user.id, :user => {:admin => true} } + put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} } - user.reload - assert_equal false, user.is_admin? + assert_equal false, user.reload.is_admin? end test "reset_otp is admin-only and witnessed" do @@ -202,4 +200,15 @@ class UsersControllerTest < ActionController::TestCase assert_not user.reload.otp_enrolled? assert_equal "otp_reset", NodeAction.last.action end + + test "index groups a retired admin under alumni, not administration" do + login_as :aaron + user = users(:quentin) + user.update_column(:roles, ["admin", "alumni"]) + + get :index + + assert_response :success + assert_select "h2", :text => /#{I18n.t("users.index.group_alumni")}/ + end end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 7276bcb4..f8d32d3c 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -13,5 +13,4 @@ aaron: salt: 5be6f9cdd04fd7ab3c91cd32a5334ba2339b8005 crypted_password: 740a48caf7dd5ff11318d812d57c0a0928cfbc12 # 'monkey' created_at: 2024-01-02 00:00:00 - admin: true - + roles: ["admin", "redaktion"] -- cgit v1.3