Class: Decidim::Admin::ImpersonateUser

Inherits:
Command
  • Object
show all
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

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

#callObject

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?

    create_authorization

    impersonation_log = create_impersonation_log
    create_action_log(impersonation_log)
  end

  enqueue_expire_job

  broadcast(:ok)
end