Class: Decidim::Admin::ImpersonationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/decidim/admin/impersonations_controller.rb

Overview

Controller that allows impersonating managed users at the admin panel.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Instance Method Details

#close_sessionObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/decidim/admin/impersonations_controller.rb', line 53

def close_session
  CloseSessionManagedUser.call(user, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("impersonations.close_session.success", scope: "decidim.admin")
      redirect_to impersonatable_users_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("impersonations.close_session.error", scope: "decidim.admin")
      redirect_to decidim.root_path
    end
  end
end

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/decidim/admin/impersonations_controller.rb', line 27

def create
  enforce_permission_to :impersonate, :impersonatable_user, user: user

  @form = form(ImpersonateUserForm).from_params(
    user: user,
    handler_name: handler_name,
    reason: params[:impersonate_user][:reason],
    authorization: Decidim::AuthorizationHandler.handler_for(
      handler_name,
      params[:impersonate_user][:authorization].merge(user: user)
    )
  )

  ImpersonateUser.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("impersonations.create.success", scope: "decidim.admin") if creating_managed_user?
      redirect_to decidim.root_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("impersonations.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#newObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/decidim/admin/impersonations_controller.rb', line 14

def new
  enforce_permission_to :impersonate, :impersonatable_user, user: user

  @form = form(ImpersonateUserForm).from_params(
    user: user,
    handler_name: handler_name,
    authorization: Decidim::AuthorizationHandler.handler_for(
      handler_name,
      user: user
    )
  )
end