Class: Decidim::Admin::ParticipatorySpace::Unpublish

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/admin/participatory_space/unpublish.rb

Overview

A command that sets a ParticipatorySpace as unpublished.

Instance Method Summary collapse

Constructor Details

#initialize(participatory_space, user) ⇒ Unpublish

Public: Initializes the command.

participatory_space - A ParticipatorySpace that will be unpublished user - the user performing the action



12
13
14
15
# File 'app/commands/decidim/admin/participatory_space/unpublish.rb', line 12

def initialize(participatory_space, user)
  @participatory_space = participatory_space
  @user = user
end

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.



23
24
25
26
27
28
29
30
31
# File 'app/commands/decidim/admin/participatory_space/unpublish.rb', line 23

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

  Decidim.traceability.perform_action!(:unpublish, participatory_space, user, **default_options) do
    participatory_space.unpublish!
  end

  broadcast(:ok, participatory_space)
end