Class: Decidim::Admin::ImpersonateManagedUser

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/admin/impersonate_managed_user.rb

Overview

A command with all the business logic to impersonate a managed user.

Instance Method Summary collapse

Constructor Details

#initialize(form, user) ⇒ ImpersonateManagedUser

Public: Initializes the command.

form - The form with the authorization info user - The user to impersonate



11
12
13
14
# File 'app/commands/decidim/admin/impersonate_managed_user.rb', line 11

def initialize(form, user)
  @form = form
  @user = user
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.



22
23
24
25
26
27
28
29
# File 'app/commands/decidim/admin/impersonate_managed_user.rb', line 22

def call
  return broadcast(:invalid) unless user.managed? && authorization_valid?

  create_impersonation_log
  enqueue_expire_job

  broadcast(:ok)
end