summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-31 15:55:43 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-31 15:55:43 +0200
commit464dd4266bdc433805010b5dca428f4cb75c2a81 (patch)
tree47fdf4f065960d49da015eafdf56cb817dcf9ea4 /app/controllers
parent5f17f421b176d48ef556fb379f59bbb7d284b48e (diff)
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.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/users_controller.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index cb71db23..95dff220 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -9,14 +9,20 @@ class UsersController < ApplicationController
9 9
10 layout 'admin' 10 layout 'admin'
11 11
12 ROLE_PRESETS = {
13 "editor" => [],
14 "redaktion" => ["redaktion"],
15 "admin" => ["admin", "redaktion"]
16 }.freeze
17
18 GROUP_ORDER = [:admin, :redaktion, :editor, :alumni].freeze
19
12 def index 20 def index
13 @users = User.order("login ASC").all.group_by do |user| 21 @users = User.order("login ASC").all.group_by(&:role_group)
14 user.admin? ? :admin : :user
15 end
16 end 22 end
17 23
18 def new 24 def new
19 @user = User.new(admin: params[:admin].present?) 25 @user = User.new(:roles => ROLE_PRESETS.fetch(params[:preset], []))
20 end 26 end
21 27
22 def create 28 def create
@@ -35,8 +41,7 @@ class UsersController < ApplicationController
35 41
36 def update 42 def update
37 permitted = user_params 43 permitted = user_params
38 permitted.delete(:admin) unless current_user.is_admin? 44
39
40 if @user.update(permitted) 45 if @user.update(permitted)
41 flash[:notice] = t("flash.users.updated", :login => @user.login) 46 flash[:notice] = t("flash.users.updated", :login => @user.login)
42 redirect_to user_path(@user) 47 redirect_to user_path(@user)
@@ -63,9 +68,13 @@ class UsersController < ApplicationController
63 private 68 private
64 69
65 def user_params 70 def user_params
66 allowed = [:login, :email, :password, :password_confirmation] 71 permitted = params.fetch(:user, {})
67 allowed << :admin if current_user.admin? 72 .permit(:login, :email, :password, :password_confirmation,
68 params.fetch(:user, {}).permit(allowed) 73 :roles => [])
74 # Checkbox arrays post a leading blank from the hidden field.
75 permitted[:roles] = Array(permitted[:roles]).reject(&:blank?) if permitted.key?(:roles)
76 permitted.delete(:roles) unless current_user.is_admin?
77 permitted
69 end 78 end
70 79
71 def find_user 80 def find_user