summaryrefslogtreecommitdiff
path: root/app/controllers/users_controller.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-03 23:00:28 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-03 23:00:28 +0200
commitbe2cdea85177ac016e56dcce6cbe6015d754adf5 (patch)
tree17de8f7474f8d2104f1342c8fe4e1ef7d3058c2e /app/controllers/users_controller.rb
parentf026f07d891bc0055ae3cb5160263ca03ad2e32a (diff)
Require elevation before editing another account
Diffstat (limited to 'app/controllers/users_controller.rb')
-rw-r--r--app/controllers/users_controller.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 7932e28b..1bd436e5 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -10,6 +10,7 @@ class UsersController < ApplicationController
10 before_action :require_admin, :only => [:new, :create, :reset_otp, :deactivate, :reactivate] 10 before_action :require_admin, :only => [:new, :create, :reset_otp, :deactivate, :reactivate]
11 before_action :require_elevation, :only => [:new, :create, :reset_otp, :deactivate, :reactivate] 11 before_action :require_elevation, :only => [:new, :create, :reset_otp, :deactivate, :reactivate]
12 before_action :verify_status, :except => [:index, :grant_redaktion, :revoke_redaktion] 12 before_action :verify_status, :except => [:index, :grant_redaktion, :revoke_redaktion]
13 before_action :require_elevation_for_other_accounts, :only => [:edit, :update]
13 14
14 layout 'admin' 15 layout 'admin'
15 16
@@ -43,6 +44,11 @@ class UsersController < ApplicationController
43 end 44 end
44 45
45 def update 46 def update
47 if roles_change_needs_elevation?
48 session[:elevation_return_to] = request.fullpath
49 return redirect_to new_elevation_path
50 end
51
46 permitted = user_params 52 permitted = user_params
47 53
48 if @user.update(permitted) 54 if @user.update(permitted)
@@ -128,4 +134,16 @@ class UsersController < ApplicationController
128 def deny_user_access 134 def deny_user_access
129 deny_role_access(:admin_required) 135 deny_role_access(:admin_required)
130 end 136 end
137
138 def require_elevation_for_other_accounts
139 return if @user == current_user
140 require_elevation
141 end
142
143 def roles_change_needs_elevation?
144 return false unless params[:user].respond_to?(:key?) && params[:user].key?(:roles)
145 submitted = Array(params[:user][:roles]).reject(&:blank?).sort
146 return false if submitted == @user.roles.sort
147 !(current_user.is_admin? && elevated?)
148 end
131end 149end