Skip to content

Commit

Permalink
Send publish component notification even when the component is (re)pu…
Browse files Browse the repository at this point in the history
…blished (#497)
  • Loading branch information
fblupi authored Sep 22, 2023
1 parent 26b33a1 commit 0ebae5c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions app/commands/decidim/admin/publish_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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

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
1 change: 1 addition & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{
package: "decidim-admin",
files: {
"/app/commands/decidim/admin/publish_component.rb" => "48b73691b2aea10191ed427702a74359", # revert https://github.com/decidim/decidim/pull/10690
"/app/commands/decidim/admin/transfer_user.rb" => "7cf11abc98c3a0c4a656ab96c220dd6a", # ephemeral participation overrides
"/app/controllers/decidim/admin/conflicts_controller.rb" => "dfe4daf8dcb7b4963e37651b0fe8df3c", # ephemeral participation overrides
"/app/forms/decidim/admin/component_form.rb" => "0455dd26580817470fd7096ef6b08315", # ephemeral participation overrides
Expand Down

0 comments on commit 0ebae5c

Please sign in to comment.