Sha256: 3acb2f262d44623699477e3dd4e712b469ae899940f2ab2449a9b99c69862855

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module ParticipatorySpace
      # A command that sets a ParticipatorySpace as published.
      class Publish < Decidim::Command
        # Public: Initializes the command.
        #
        # participatory_space - A ParticipatorySpace that will be published
        # user - the user performing the action
        def initialize(participatory_space, user)
          @participatory_space = participatory_space
          @user = user
        end

        # 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.
        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

        private

        attr_reader :participatory_space, :user

        def default_options = { visibility: "all" }
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.4 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.29.0 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.3 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.2 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.1 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.0 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/participatory_space/publish.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/participatory_space/publish.rb