Sha256: c8cc68448fe2ee26b10e20143c00cd63998608c0d2cda124990291a454c3de85

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

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

        # Public: Publishes the Election.
        #
        # Broadcasts :ok if published, :invalid otherwise.
        def call
          publish_election
          publish_event unless election.previously_published?

          broadcast(:ok, election)
        end

        private

        attr_reader :election, :current_user

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

        def publish_event
          Decidim::EventsManager.publish(
            event: "decidim.events.elections.election_published",
            event_class: ::Decidim::Elections::ElectionPublishedEvent,
            resource: election,
            followers: election.participatory_space.followers
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.8 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.7 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.6 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.5 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.4 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.27.3 app/commands/decidim/elections/admin/publish_election.rb