Sha256: a11d6d120d87fe69249b40f5671b327e1bdabf5367b5f1f5f0a1c0736c11d795

Contents?: true

Size: 1.3 KB

Versions: 20

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This command gets called when a component is published from the admin panel.
    class PublishComponent < Decidim::Command
      # Public: Initializes the command.
      #
      # component - The component to publish.
      # current_user - the user performing the action
      def initialize(component, current_user)
        @component = component
        @current_user = current_user
      end

      # Public: Publishes the Component.
      #
      # Broadcasts :ok if published, :invalid otherwise.
      def call
        publish_component
        publish_event unless component.previously_published?

        broadcast(:ok)
      end

      private

      attr_reader :component, :current_user

      def publish_component
        Decidim.traceability.perform_action!(
          :publish,
          component,
          current_user,
          visibility: "all"
        ) do
          component.publish!
          component
        end
      end

      def publish_event
        Decidim::EventsManager.publish(
          event: "decidim.events.components.component_published",
          event_class: Decidim::ComponentPublishedEvent,
          resource: component,
          followers: component.participatory_space.followers
        )
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.4 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.9 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.29.0 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.3 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.8 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.2 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.7 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.1 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.6 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.0 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.5 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.4 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.27.3 app/commands/decidim/admin/publish_component.rb