Sha256: 47d64b5c9074a4a92d4017b7bc8d8f6612fb7da5230e49ba43bb0a3359be3179

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    module Admin
      # A command with all the business logic that unpublishes an
      # existing initiative.
      class UnpublishInitiative < Decidim::Command
        # Public: Initializes the command.
        #
        # initiative - Decidim::Initiative
        # current_user - the user performing the action
        def initialize(initiative, current_user)
          @initiative = initiative
          @current_user = current_user
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) unless initiative.published?

          @initiative = Decidim.traceability.perform_action!(
            :unpublish,
            initiative,
            current_user
          ) do
            initiative.unpublish!
            initiative
          end
          broadcast(:ok, initiative)
        end

        private

        attr_reader :initiative, :current_user
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.9 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.8 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.7 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.6 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.5 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.4 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.3 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.2 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.1 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.0 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.0.rc2 app/commands/decidim/initiatives/admin/unpublish_initiative.rb
decidim-initiatives-0.27.0.rc1 app/commands/decidim/initiatives/admin/unpublish_initiative.rb