Sha256: c16932282f1b6c0ccbaf2081091b74b10171195449100ad0886278ebcf545434

Contents?: true

Size: 915 Bytes

Versions: 21

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A command that sets all steps in a participatory process as inactive
    class DeactivateParticipatoryProcessStep < Rectify::Command
      # Public: Initializes the command.
      #
      # step - A ParticipatoryProcessStep that will be deactivated
      def initialize(step)
        @step = step
      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 step.nil? || !step.active?

        deactivate_active_steps
        broadcast(:ok)
      end

      private

      attr_reader :step

      def deactivate_active_steps
        step.participatory_process.steps.where(active: true).update_all(active: false)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
decidim-admin-0.1.0 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.1.0 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.8.1 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.8.1 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.7 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.7 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.6 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.6 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.5 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.5 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.4 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.3 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.3 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.2 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.2 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.1 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.1 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.1.alpha9 app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-0.0.1.alpha9 decidim-admin/app/commands/decidim/admin/deactivate_participatory_process_step.rb
decidim-admin-0.0.1.alpha8 app/commands/decidim/admin/deactivate_participatory_process_step.rb