Class: Decidim::ParticipatoryProcesses::Admin::DestroyParticipatoryProcessStep

Inherits:
Command
  • Object
show all
Defined in:
decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/destroy_participatory_process_step.rb

Overview

A command that sets all steps in a participatory process as inactive

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(step, current_user) ⇒ DestroyParticipatoryProcessStep

Public: Initializes the command.

step - A ParticipatoryProcessStep that will be deactivated current_user - the user performing the action



12
13
14
15
16
# File 'decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/destroy_participatory_process_step.rb', line 12

def initialize(step, current_user)
  @step = step
  @participatory_process = step.participatory_process
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the data was not valid and we could not proceed.

Returns nothing.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/destroy_participatory_process_step.rb', line 24

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