Sha256: 36672f89bfce4661710a03259eece17a7255ea9c8fc406445a3ca536a16fb4ce

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module Decidim
  module BulletinBoard
    module Authority
      # This command uses the GraphQL client to request the starting of the key ceremony.
      class StartKeyCeremony < Decidim::BulletinBoard::Command
        # Public: Initializes the command.
        #
        # election_id - The local election identifier
        def initialize(election_id)
          @election_id = election_id
        end

        # Returns the message_id related to the operation
        def message_id
          @message_id ||= build_message_id(unique_election_id(election_id), "start_key_ceremony")
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid and the query operation is successful.
        # - :error if query operation was not successful.
        #
        # Returns nothing.
        def call
          # arguments used inside the graphql operation
          args = {
            message_id: message_id,
            signed_data: sign_message(message_id, {})
          }

          response = client.query do
            mutation do
              startKeyCeremony(messageId: args[:message_id], signedData: args[:signed_data]) do
                pendingMessage do
                  status
                end
                error
              end
            end
          end

          return broadcast(:error, response.data.start_key_ceremony.error) if response.data.start_key_ceremony.error.present?

          broadcast(:ok, response.data.start_key_ceremony.pending_message)
        rescue Graphlient::Errors::FaradayServerError
          broadcast(:error, "Sorry, something went wrong")
        end

        private

        attr_reader :election_id
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-bulletin_board-0.9.2 lib/decidim/bulletin_board/authority/start_key_ceremony.rb
decidim-bulletin_board-0.9.1 lib/decidim/bulletin_board/authority/start_key_ceremony.rb
decidim-bulletin_board-0.9.0 lib/decidim/bulletin_board/authority/start_key_ceremony.rb