Sha256: b25dd7e6901bbf78e32cefc511f94377bad1554169542343fed8887300e0c8d7

Contents?: true

Size: 1.51 KB

Versions: 12

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A command that sets all steps in a participatory process as inactive
      class DestroyParticipatoryProcessStep < Decidim::Command
        # Public: Initializes the command.
        #
        # step - A ParticipatoryProcessStep that will be deactivated
        # current_user - the user performing the action
        def initialize(step, current_user)
          @step = step
          @participatory_process = step.participatory_process
          @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, :active_step) if active_step?

          transaction do
            Decidim.traceability.perform_action!(:delete, step, current_user) do
              step.destroy!
              step
            end

            reorder_steps
          end

          broadcast(:ok)
        end

        private

        attr_reader :step, :participatory_process, :current_user

        def active_step?
          participatory_process.steps.count > 1 && step.active?
        end

        def reorder_steps
          steps = participatory_process.steps.reload

          ReorderParticipatoryProcessSteps
            .new(steps, steps.map(&:id))
            .call
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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