Sha256: 08fe61138144b0147b4b481d2b823ff9fd02c62a4b62b6cfb5a300111e9f7e91

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command is executed when the user creates a Question
      # from the admin panel.
      class CreateQuestion < Decidim::Command
        def initialize(form)
          @form = form
        end

        # Creates the question if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:election_started) if form.election.blocked?
          return broadcast(:invalid) if form.invalid?

          create_question!

          broadcast(:ok, question)
        end

        private

        attr_reader :form, :question

        def create_question!
          attributes = {
            election: form.election,
            title: form.title,
            max_selections: form.max_selections,
            weight: form.weight,
            random_answers_order: form.random_answers_order,
            min_selections: form.min_selections
          }

          @question = Decidim.traceability.create!(
            Question,
            form.current_user,
            attributes,
            visibility: "all"
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.9 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.3 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.8 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.2 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.7 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.1 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.6 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.0 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.5 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/admin/create_question.rb
decidim-elections-0.27.4 app/commands/decidim/elections/admin/create_question.rb