Class: Decidim::BulletinBoard::Authority::ReportMissingTrustee

Inherits:
Command
  • Object
show all
Defined in:
lib/decidim/bulletin_board/authority/report_missing_trustee.rb

Overview

This command uses the GraphQL client to report a missing trustee during the tally process.

Instance Attribute Summary

Attributes inherited from Command

#graphql, #settings

Instance Method Summary collapse

Methods inherited from Command

#build_message_id, #complete_message, #configure, #sign_message, #unique_election_id

Constructor Details

#initialize(election_id, trustee_id) ⇒ ReportMissingTrustee

Public: Initializes the command.

election_id - The local election identifier trustee_id - The trustee identifier



12
13
14
15
# File 'lib/decidim/bulletin_board/authority/report_missing_trustee.rb', line 12

def initialize(election_id, trustee_id)
  @election_id = election_id
  @trustee_id = trustee_id
end

Instance Method Details

#callObject

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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/decidim/bulletin_board/authority/report_missing_trustee.rb', line 28

def call
  # arguments used inside the graphql operation
  args = {
    message_id:,
    signed_data: sign_message(message_id, { trustee_id: })
  }

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

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

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

#message_idObject

Returns the message_id related to the operation



18
19
20
# File 'lib/decidim/bulletin_board/authority/report_missing_trustee.rb', line 18

def message_id
  @message_id ||= build_message_id(unique_election_id(election_id), "tally.missing_trustee")
end