Sha256: a37dea085fcf3ab46121398d59b56d766229eef1a923dcaaf668743a62d536a3

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 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 < Rectify::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

        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,
          recipient_ids: component.participatory_space.followers.pluck(:id)
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-admin-0.15.2 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.15.1 app/commands/decidim/admin/publish_component.rb
decidim-admin-0.15.0 app/commands/decidim/admin/publish_component.rb