Class: Decidim::Admin::PromoteManagedUser

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

Constructor Details

#initialize(form, user) ⇒ PromoteManagedUser

Public: Initializes the command.

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



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

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

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



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

def form
  @form
end

#userObject (readonly)

Returns the value of attribute user.



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

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.



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

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

  promote_user
  invite_user
  create_action_log

  broadcast(:ok)
end