Sha256: bf3414b649ca14804245b821bd68eeaaf5351afe7ceecddfecbb04b2880cf844

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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

        # Updates the question if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if invalid?

          update_question!

          broadcast(:ok, question)
        end

        private

        attr_reader :form, :question

        def invalid?
          question.election.blocked? || form.invalid?
        end

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

          Decidim.traceability.update!(
            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/update_question.rb
decidim-elections-0.27.9 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.3 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.27.8 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.2 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.27.7 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.1 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.27.6 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.0 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.27.5 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/admin/update_question.rb
decidim-elections-0.27.4 app/commands/decidim/elections/admin/update_question.rb