Sha256: 58535f846c61ca33b3d6a99eb35debdf09aff3425451b3edc22f503318024257

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command gets called when an 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.28.4 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.3 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.1 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.0 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/admin/publish_election.rb