Sha256: a4f322da3e533ec432f08a2d5365aae8caa743b31d43a14ce11e7a4d780cc641

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A command that sets all steps in a participatory process as inactive
    class DestroyParticipatoryProcessStep < Rectify::Command
      # Public: Initializes the command.
      #
      # step - A ParticipatoryProcessStep that will be deactivated
      def initialize(step)
        @step = step
        @participatory_process = step.participatory_process
      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, :last_step) if @participatory_process.steps.count == 1
        return broadcast(:invalid, :active_step) if @step.active?

        @step.destroy!
        reorder_steps
        broadcast(:ok)
      end

      private

      def reorder_steps
        steps = @participatory_process.steps.reload

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
decidim-admin-0.1.0 app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-0.1.0 decidim-admin/app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-admin-0.0.8.1 app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-0.0.8.1 decidim-admin/app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-admin-0.0.7 app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-0.0.7 decidim-admin/app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-admin-0.0.6 app/commands/decidim/admin/destroy_participatory_process_step.rb
decidim-0.0.6 decidim-admin/app/commands/decidim/admin/destroy_participatory_process_step.rb