Class: Decidim::Proposals::Admin::PublishAnswers

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

Overview

A command with all the business logic to publish many answers at once.

Instance Method Summary collapse

Constructor Details

#initialize(component, user, proposal_ids) ⇒ PublishAnswers

Public: Initializes the command.

component - The component that contains the answers. user - the Decidim::User that is publishing the answers. proposal_ids - the identifiers of the proposals with the answers to be published.



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

def initialize(component, user, proposal_ids)
  @component = component
  @user = user
  @proposal_ids = proposal_ids
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if there are not proposals to publish.

Returns nothing.



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

def call
  return broadcast(:invalid) unless proposals.any?

  proposals.each do |proposal|
    transaction do
      mark_proposal_as_answered(proposal)
      notify_proposal_answer(proposal)
    end
  end

  broadcast(:ok)
end