Class: Decidim::Surveys::Admin::PublishSurvey

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

Overview

A command with all the business logic that publishes an existing survey.

Instance Method Summary collapse

Constructor Details

#initialize(survey, current_user) ⇒ PublishSurvey

Public: Initializes the command.

survey - Decidim::Surveys::Survey current_user - the user performing the action



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

def initialize(survey, current_user)
  @survey = survey
  @current_user = current_user
  @questionnaire = survey.questionnaire
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



25
26
27
28
29
30
31
32
33
34
# File 'app/commands/decidim/surveys/admin/publish_survey.rb', line 25

def call
  return broadcast(:invalid) if survey.published?

  transaction do
    publish_survey
    delete_responses if @survey.clean_after_publish?
  end

  broadcast(:ok, survey)
end