Class: Decidim::Kids::MinorImpersonationsController

Inherits:
ApplicationController show all
Includes:
UserProfile
Defined in:
app/controllers/decidim/kids/minor_impersonations_controller.rb

Overview

Controller that allows impersonating managed minors.

Instance Method Summary collapse

Instance Method Details

#close_sessionObject



41
42
43
44
45
46
47
48
# File 'app/controllers/decidim/kids/minor_impersonations_controller.rb', line 41

def close_session
  CloseSessionManagedMinor.call(current_user, real_user) do
    on(:ok) do
      flash[:notice] = I18n.t("impersonations.close_session.success", scope: "decidim.kids")
      redirect_to decidim.root_path
    end
  end
end

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/decidim/kids/minor_impersonations_controller.rb', line 23

def create
  enforce_permission_to :impersonate, :minor_accounts, minor_user: minor_user

  @form = form(ImpersonateMinorForm).from_params(params)

  ImpersonateMinor.call(minor_user, current_user, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("impersonations.create.success", scope: "decidim.kids")
      redirect_to decidim.root_path
    end

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

#newObject



17
18
19
20
21
# File 'app/controllers/decidim/kids/minor_impersonations_controller.rb', line 17

def new
  enforce_permission_to :impersonate, :minor_accounts, minor_user: minor_user

  @form = form(ImpersonateMinorForm).from_params(params)
end

#permission_class_chainObject



13
14
15
# File 'app/controllers/decidim/kids/minor_impersonations_controller.rb', line 13

def permission_class_chain
  [::Decidim::Kids::Permissions] + super
end