Class: Decidim::Admin::PromoteManagedUser

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

Overview

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

Managed users can be promoted to standard users. It means they will be invited to the application and will lose the managed flag so the user cannot be impersonated anymore.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(form, user, promoted_by) ⇒ PromoteManagedUser

Public: Initializes the command.

form - A form object with the params. user - The user to promote promoted_by - The user performing the operation



16
17
18
19
20
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 16

def initialize(form, user, promoted_by)
  @form = form
  @user = user
  @promoted_by = promoted_by
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



38
39
40
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38

def form
  @form
end

Returns the value of attribute promoted_by.



38
39
40
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38

def promoted_by
  @promoted_by
end

#userObject (readonly)

Returns the value of attribute user.



38
39
40
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38

def user
  @user
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



28
29
30
31
32
33
34
35
36
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 28

def call
  return broadcast(:invalid) if form.invalid? || !user.managed? || email_already_exists?

  promote_user
  invite_user
  create_action_log

  broadcast(:ok)
end