Sha256: c393588f87465ca51db708f19706d0be3acf0155f1a80689c3543eded875824f

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    module Admin
      # A command with all the business logic that rejects an
      # existing initiative.
      class RejectInitiative < 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 was not valid and we could not proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if initiative.rejected?

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

        private

        attr_reader :initiative, :current_user
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.4 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.29.0 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.3 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.29.0.rc4 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.29.0.rc3 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.29.0.rc2 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.29.0.rc1 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.2 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.1 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.0 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.0.rc5 app/commands/decidim/initiatives/admin/reject_initiative.rb
decidim-initiatives-0.28.0.rc4 app/commands/decidim/initiatives/admin/reject_initiative.rb