diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-03-08 06:05:01 +0300 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-03-09 22:50:11 +0300 |
commit | b88314f4ad955897dc737b6e9515b43dc9d97422 (patch) | |
tree | bb9335751f975950e54e98fc259c09365a409361 | |
parent | 8f057a5109687016fe72c6512fa0d4ea2354731f (diff) |
consolidate the error handling for #impersonate
-rw-r--r-- | app/controllers/admin/users_controller.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 7f86723b921..205cf0490ab 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -29,15 +29,7 @@ class Admin::UsersController < Admin::ApplicationController end def impersonate - if user.blocked? - flash[:alert] = "You cannot impersonate a blocked user" - - redirect_to admin_user_path(user) - elsif user.internal? - flash[:alert] = "You cannot impersonate an internal user" - - redirect_to admin_user_path(user) - else + if !can?(user, :log_in) session[:impersonator_id] = current_user.id warden.set_user(user, scope: :user) @@ -47,6 +39,17 @@ class Admin::UsersController < Admin::ApplicationController flash[:alert] = "You are now impersonating #{user.username}" redirect_to root_path + else + flash[:alert] = + if user.blocked? + "You cannot impersonate a blocked user" + elsif user.internal? + "You cannot impersonate an internal user" + else + "You cannot impersonate a user who cannot log in" + end + + redirect_to admin_user_path(user) end end |