Class: Decidim::Admin::ImpersonateUser
- Inherits:
-
Command
- Object
- Command
- Decidim::Admin::ImpersonateUser
- Defined in:
- app/commands/decidim/admin/impersonate_user.rb
Overview
A command with all the business logic to impersonate a managed user.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ ImpersonateUser
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ ImpersonateUser
Public: Initializes the command.
form - The form with the authorization info user - The user to impersonate
11 12 13 |
# File 'app/commands/decidim/admin/impersonate_user.rb', line 11 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the impersonation is not valid.
Returns nothing.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/commands/decidim/admin/impersonate_user.rb', line 21 def call return broadcast(:invalid) unless form.valid? transaction do user.save! unless user.persisted? impersonation_log = create_impersonation_log create_action_log(impersonation_log) end enqueue_expire_job broadcast(:ok) end |