Class: Decidim::Admin::ParticipatorySpace::Publish

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

Overview

A command that sets a ParticipatorySpace as published.

Instance Method Summary collapse

Constructor Details

#initialize(participatory_space, user) ⇒ Publish

Public: Initializes the command.

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



12
13
14
15
# File 'app/commands/decidim/admin/participatory_space/publish.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/publish.rb', line 23

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

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

  broadcast(:ok, participatory_space)
end