Sha256: 21a71bcb8305e44f3beb727e4abc827662ab1068bd8d3225569fbf5ecbc530fd

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module ParticipatorySpace
      # A command that sets a ParticipatorySpace as unpublished.
      class Unpublish < Decidim::Command
        # Public: Initializes the command.
        #
        # participatory_space - A ParticipatorySpace that will be unpublished
        # 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!(:unpublish, participatory_space, user, **default_options) do
            participatory_space.unpublish!
          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/unpublish.rb
decidim-admin-0.28.4 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.29.0 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.3 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.2 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.1 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.0 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/participatory_space/unpublish.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/participatory_space/unpublish.rb