2016-04-22 17:19:55 -04:00
|
|
|
class Admin::ImpersonationsController < Admin::ApplicationController
|
|
|
|
skip_before_action :authenticate_admin!
|
|
|
|
before_action :authenticate_impersonator!
|
|
|
|
|
|
|
|
def destroy
|
2016-04-22 17:58:09 -04:00
|
|
|
original_user = current_user
|
2016-04-22 17:19:55 -04:00
|
|
|
|
|
|
|
warden.set_user(impersonator, scope: :user)
|
|
|
|
|
2016-08-23 04:06:54 -04:00
|
|
|
Gitlab::AppLogger.info("User #{impersonator.username} has stopped impersonating #{original_user.username}")
|
2016-05-03 23:55:35 -04:00
|
|
|
|
2016-04-22 17:19:55 -04:00
|
|
|
session[:impersonator_id] = nil
|
|
|
|
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to admin_user_path(original_user), status: 302
|
2016-04-22 17:19:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def impersonator
|
|
|
|
@impersonator ||= User.find(session[:impersonator_id]) if session[:impersonator_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate_impersonator!
|
2017-04-08 22:20:57 -04:00
|
|
|
render_404 unless impersonator && impersonator.admin? && !impersonator.blocked?
|
2016-04-22 17:19:55 -04:00
|
|
|
end
|
|
|
|
end
|