consolidate the error handling for #impersonate
This commit is contained in:
parent
8f057a5109
commit
b88314f4ad
1 changed files with 12 additions and 9 deletions
|
@ -29,15 +29,7 @@ class Admin::UsersController < Admin::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def impersonate
|
def impersonate
|
||||||
if user.blocked?
|
if !can?(user, :log_in)
|
||||||
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
|
|
||||||
session[:impersonator_id] = current_user.id
|
session[:impersonator_id] = current_user.id
|
||||||
|
|
||||||
warden.set_user(user, scope: :user)
|
warden.set_user(user, scope: :user)
|
||||||
|
@ -47,6 +39,17 @@ class Admin::UsersController < Admin::ApplicationController
|
||||||
flash[:alert] = "You are now impersonating #{user.username}"
|
flash[:alert] = "You are now impersonating #{user.username}"
|
||||||
|
|
||||||
redirect_to root_path
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue