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

Inherits:
Rectify::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

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

Instance Method Details

#callObject

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.


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