Sha256: 460e5db9299e32666ac57af2b5088d66f2904f8b35ed40db2b8899b65a335e02

Contents?: true

Size: 1.2 KB

Versions: 18

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A command that sets a step in a participatory process as active (and
      # unsets a previous active step)
      class ActivateParticipatoryProcessStep < Rectify::Command
        # Public: Initializes the command.
        #
        # step - A ParticipatoryProcessStep that will be activated
        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?

          Decidim::ParticipatoryProcessStep.transaction do
            deactivate_active_steps
            activate_step
          end
          broadcast(:ok)
        end

        private

        attr_reader :step

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

        def activate_step
          step.update_attribute(:active, true)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
decidim-participatory_processes-0.6.8 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.8 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.7 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.7 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.6 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.6 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.5 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.5 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.4 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.4 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.3 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.3 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.2 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.2 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.1 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.1 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-participatory_processes-0.6.0 app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb
decidim-0.6.0 decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb