Class: Decidim::Consultations::Admin::PublishQuestion

Inherits:
Decidim::Command show all
Defined in:
decidim-consultations/app/commands/decidim/consultations/admin/publish_question.rb

Overview

A command that sets a question as published.

Instance Method Summary collapse

Methods inherited from Decidim::Command

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

Constructor Details

#initialize(question, current_user) ⇒ PublishQuestion

Public: Initializes the command.

question - A Question that will be published current_user - the user performing the action


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

def initialize(question, current_user)
  @question = question
  @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

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the data wasn't valid and we couldn't proceed.

Returns nothing.


23
24
25
26
27
28
29
30
31
# File 'decidim-consultations/app/commands/decidim/consultations/admin/publish_question.rb', line 23

def call
  return broadcast(:invalid) if question.nil? || question.published?

  Decidim.traceability.perform_action!("publish", question, @current_user, visibility: "all") do
    question.publish!
  end

  broadcast(:ok)
end