Module: Effective::ImpersonationController::Destroy

Defined in:
app/controllers/concerns/effective/impersonation_controller/destroy.rb

Instance Method Summary collapse

Instance Method Details

#after_destroy_impersonate_path_for(user) ⇒ Object



29
30
31
# File 'app/controllers/concerns/effective/impersonation_controller/destroy.rb', line 29

def after_destroy_impersonate_path_for(user)
  session[:impersonation_original_path].presence || '/admin/users'
end

#destroyObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/concerns/effective/impersonation_controller/destroy.rb', line 5

def destroy
  # Edge case where the current_user is blank. Weird session data.
  if current_user.blank?
    # Reset impersonation
    session[:impersonation_user_id] = nil
    session[:impersonation_original_path] = nil

    redirect_to(root_path) and return
  end

  # The current_user exists
  @user = current_user.class.find(session[:impersonation_user_id])
  redirect_path = after_destroy_impersonate_path_for(@user)

  # Reset impersonation
  session[:impersonation_user_id] = nil
  session[:impersonation_original_path] = nil

  expire_data_after_sign_in!
  warden.session_serializer.store(@user, Devise::Mapping.find_scope!(@user))

  redirect_to(redirect_path)
end