Skip to content

Commit 308fce4

Browse files
committed
allow dev mode to impersonate users directly
1 parent 79b3b38 commit 308fce4

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

app/controllers/admin_controller.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class AdminController < ApplicationController
44
before_action :verify_global_admin, only: [:admin_email, :send_admin_email, :new_site, :create_site, :setup,
55
:setup_save, :hellban, :all_email, :send_all_email]
66
before_action :verify_developer, only: [:change_users, :impersonate]
7+
before_action :set_user, only: [:change_users, :hellban, :impersonate]
78

89
def index; end
910

@@ -182,20 +183,19 @@ def setup_save
182183
end
183184

184185
def hellban
185-
@user = User.find params[:id]
186186
@user.block("user manually blocked by admin ##{current_user.id}")
187187
flash[:success] = t 'admin.user_fed_stat'
188188
redirect_back fallback_location: admin_path
189189
end
190190

191191
def impersonate
192-
@user = User.find params[:id]
192+
if Rails.env.development?
193+
change_users
194+
end
193195
end
194196

195197
def change_users
196-
@user = User.find params[:id]
197-
198-
unless params[:comment].present?
198+
unless params[:comment].present? || Rails.env.development?
199199
flash[:danger] = 'Please explain why you are impersonating this user.'
200200
render :impersonate
201201
return
@@ -246,4 +246,10 @@ def do_email_query
246246
end
247247
render :email_query
248248
end
249+
250+
private
251+
252+
def set_user
253+
@user = User.find(params[:id])
254+
end
249255
end

app/views/admin/impersonate.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
<%= submit_tag 'Impersonate', class: 'button is-danger h-m-b-2' %>
2929
</div>
3030
</div>
31-
<% end %>
31+
<% end %>

0 commit comments

Comments
 (0)