Class: Decidim::Elections::Admin::AddUserAsTrustee

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

Overview

This command is executed when the admin user creates a trustee from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, current_user) ⇒ AddUserAsTrustee

Public: Initializes the command.

form - A form object with the params.



12
13
14
15
16
17
# File 'decidim-elections/app/commands/decidim/elections/admin/add_user_as_trustee.rb', line 12

def initialize(form, current_user)
  @form = form
  @user = form.user
  @participatory_space = form.current_participatory_space
  @current_user = current_user
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Creates the trustee if valid.

Broadcasts :ok if successful, :invalid otherwise.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'decidim-elections/app/commands/decidim/elections/admin/add_user_as_trustee.rb', line 22

def call
  return broadcast(:invalid) if form.invalid?
  return broadcast(:exists) if existing_trustee_participatory_spaces?

  transaction do
    add_user_as_trustee! if new_trustee?
    add_participatory_space
    notify_user_about_trustee_role if new_trustee?
  end

  send_email

  broadcast(:ok)
end