Class: Decidim::Votings::Admin::CreateMonitoringCommitteeMember

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

Overview

A command with the business logic to create a new monitoring committee member

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user, voting) ⇒ CreateMonitoringCommitteeMember

Public: Initializes the command.

form - A form object with the params current_user - The user creating the monitoring committee member voting - The Voting that will hold the monitoring committee member



13
14
15
16
17
# File 'app/commands/decidim/votings/admin/create_monitoring_committee_member.rb', line 13

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form wasn’t valid and we couldn’t proceed.

Returns nothing.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/commands/decidim/votings/admin/create_monitoring_committee_member.rb', line 25

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

  ActiveRecord::Base.transaction do
    user = retrieve_or_invite_user
    create_monitoring_committee_member(user)
  end

  broadcast(:ok)
rescue ActiveRecord::RecordInvalid
  form.errors.add(:email, :taken)
  broadcast(:invalid)
end