Class: Decidim::ParticipatoryProcesses::Admin::UnpublishParticipatoryProcess

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

Overview

A command that sets a participatory process as unpublished.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(process, current_user) ⇒ UnpublishParticipatoryProcess

Public: Initializes the command.

process - A ParticipatoryProcess that will be unpublished current_user - the user performing this action


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

def initialize(process, current_user)
  @process = 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 wasn't valid and we couldn't proceed.

Returns nothing.


23
24
25
26
27
28
29
30
31
32
# File 'decidim-participatory_processes/app/commands/decidim/participatory_processes/admin/unpublish_participatory_process.rb', line 23

def call
  return broadcast(:invalid) if process.nil? || !process.published?

  transaction do
    Decidim.traceability.perform_action!("unpublish", process, current_user) do
      process.unpublish!
    end
  end
  broadcast(:ok)
end