Sha256: 38449b0e1eb6ebb5a0971cf3e2e57af99fa324be38d0c0aca3f8e9a958d72963

Contents?: true

Size: 1.56 KB

Versions: 12

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command gets called to start the key ceremony in the Bulletin Board.
      class StartKeyCeremony < Decidim::Command
        # Public: Initializes the command.
        #
        # form - An ActionForm object with the information needed to perform an action
        def initialize(form)
          @form = form
        end

        # Public: Starts the key ceremony for the Election.
        #
        # Broadcasts :ok if setup, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

          transaction do
            log_action
            start_key_ceremony
          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!(
            :start_key_ceremony,
            election,
            form.current_user,
            visibility: "all"
          )
        end

        def start_key_ceremony
          bulletin_board.start_key_ceremony(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: :start_key_ceremony,
            message_id: message_id,
            status: :pending
          )
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-elections-0.27.9 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.8 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.7 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.6 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.5 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.4 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.3 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.2 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.1 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.0 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.0.rc2 app/commands/decidim/elections/admin/start_key_ceremony.rb
decidim-elections-0.27.0.rc1 app/commands/decidim/elections/admin/start_key_ceremony.rb