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

Inherits:
Rectify::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

Constructor Details

#initialize(form, current_user) ⇒ AddUserAsTrustee

Public: Initializes the command.

form - A form object with the params.


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

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

Instance Method Details

#callObject

Creates the trustee if valid.

Broadcasts :ok if successful, :invalid otherwise.


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

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

  broadcast(:ok)
end