Sha256: 9baa92f254159aa3b291a3fdef96cb89bfb841de668736c6a5c7aa7857996ef2

Contents?: true

Size: 1.03 KB

Versions: 49

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    module Admin
      # A command that sets a question as published.
      class PublishQuestion < Rectify::Command
        # Public: Initializes the command.
        #
        # question - A Question that will be published
        # current_user - the user performing the action
        def initialize(question, current_user)
          @question = question
          @current_user = current_user
        end

        # 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.
        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

        private

        attr_reader :question
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
decidim-consultations-0.17.2 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.18.0 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.17.1 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.16.1 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.17.0 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.16.0 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.15.2 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.15.1 app/commands/decidim/consultations/admin/publish_question.rb
decidim-consultations-0.15.0 app/commands/decidim/consultations/admin/publish_question.rb