Sha256: 5bc2600c4c500d2b699fccc96bc91a0ddcc8791bf970fe79d3c17f4132344d86

Contents?: true

Size: 1.51 KB

Versions: 25

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command gets called to end the voting period in the Bulletin Board.
      class EndVote < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A VotePeriodForm object with the information needed to start or end the vote period
        def initialize(form)
          @form = form
        end

        # Public: Ends the voting period for the Election.
        #
        # Broadcasts :ok if setup, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

          transaction do
            log_action
            end_vote
          end

          broadcast(:ok)
        rescue StandardError => e
          broadcast(:invalid, e.message)
        end

        private

        attr_accessor :form

        delegate :election, :bulletin_board, to: :form

        def log_action
          Decidim.traceability.perform_action!(
            :end_vote,
            election,
            form.current_user,
            visibility: "all"
          )
        end

        def end_vote
          bulletin_board.end_vote(election.id) do |message_id|
            create_election_action(message_id)
          end
        end

        def create_election_action(message_id)
          Decidim::Elections::Action.create!(
            election: election,
            action: :end_vote,
            message_id: message_id,
            status: :pending
          )
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.9 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.8 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.7 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.5 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.4 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.3 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.2 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.1 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.0 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.2 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.1 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.0 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/elections/admin/end_vote.rb
decidim-elections-0.24.3 app/commands/decidim/elections/admin/end_vote.rb