Sha256: 11d8b3704eb433bd31b82f6564f0aaa18b7f20f43486fede89958c1c20d5b791

Contents?: true

Size: 1.38 KB

Versions: 29

Compression:

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

          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

29 entries across 29 versions & 1 rubygems

Version Path
decidim-elections-0.26.5 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.4 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.3 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.1 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.0 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.1 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.0 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.24.3 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.23.6 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.24.2 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.23.5 app/commands/decidim/elections/admin/publish_election.rb
decidim-elections-0.24.1 app/commands/decidim/elections/admin/publish_election.rb