Class: Decidim::Elections::Admin::AddUserAsTrustee
- Inherits:
-
Command
- Object
- Command
- Decidim::Elections::Admin::AddUserAsTrustee
- Defined in:
- 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
-
#call ⇒ Object
Creates the trustee if valid.
-
#initialize(form, current_user) ⇒ AddUserAsTrustee
constructor
Public: Initializes the command.
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 '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 |
Instance Method Details
#call ⇒ Object
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 '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 |