Class: LcpRuby::ImpersonationController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lcp_ruby/impersonation_controller.rb

Constant Summary

Constants included from Controller::BearerAuthentication

Controller::BearerAuthentication::BASIC_PREFIX_LENGTH, Controller::BearerAuthentication::BEARER_PREFIX_LENGTH

Instance Method Summary collapse

Methods included from Controller::Authorization

#current_evaluator

Instance Method Details

#createObject



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

def create
  unless can_impersonate_current_user?
    redirect_back fallback_location: "/", allow_other_host: false, alert: I18n.t("lcp_ruby.impersonation.not_authorized", default: "You are not authorized to impersonate roles.")
    return
  end

  role = params[:role]
  if role.blank?
    redirect_back fallback_location: "/", allow_other_host: false, alert: I18n.t("lcp_ruby.impersonation.no_role", default: "No role specified.")
    return
  end

  unless available_roles_for_impersonation.include?(role)
    redirect_back fallback_location: "/", allow_other_host: false, alert: I18n.t("lcp_ruby.impersonation.invalid_role", role: role, default: "Role '%{role}' is not a valid role.")
    return
  end

  session[:lcp_impersonate_role] = role
  redirect_back fallback_location: "/", allow_other_host: false, notice: I18n.t("lcp_ruby.impersonation.started", role: role, default: "Impersonating role: %{role}")
end

#destroyObject



27
28
29
30
# File 'app/controllers/lcp_ruby/impersonation_controller.rb', line 27

def destroy
  session.delete(:lcp_impersonate_role)
  redirect_back fallback_location: "/", allow_other_host: false, notice: I18n.t("lcp_ruby.impersonation.stopped", default: "Stopped impersonation.")
end