decidim-bulletin_board 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "decidim/bulletin_board/graphql/client"
4
-
5
3
  module Decidim
6
4
  module BulletinBoard
7
5
  # The base class for all commands.
8
6
  class Command
9
7
  include Wisper::Publisher
10
8
 
11
- delegate :authority_slug, :private_key, :unique_election_id, :build_message_id, to: :class
9
+ attr_reader :settings, :graphql
12
10
 
13
- def sign_message(message_id, message)
14
- JWT.encode(complete_message(message_id, message), private_key.keypair, "RS256")
11
+ def configure(settings, graphql)
12
+ @settings = settings
13
+ @graphql = graphql
15
14
  end
16
15
 
17
- def client
18
- @client ||= BulletinBoard::Graphql::Client.client
16
+ def sign_message(message_id, message)
17
+ JWT.encode(complete_message(message_id, message), settings.private_key.keypair, "RS256")
19
18
  end
20
19
 
21
20
  def complete_message(message_id, message)
@@ -25,26 +24,12 @@ module Decidim
25
24
  })
26
25
  end
27
26
 
28
- class << self
29
- def self.call(*args)
30
- new(*args).call
31
- end
32
-
33
- def private_key
34
- @private_key ||= JwkUtils.import_private_key(BulletinBoard.identification_private_key)
35
- end
36
-
37
- def authority_slug
38
- @authority_slug ||= BulletinBoard.authority_name.parameterize
39
- end
40
-
41
- def unique_election_id(election_id)
42
- Decidim::BulletinBoard::MessageIdentifier.unique_election_id(authority_slug, election_id)
43
- end
27
+ def build_message_id(unique_election_id, type_subtype, voter_id = nil)
28
+ MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || settings.authority_slug)
29
+ end
44
30
 
45
- def build_message_id(unique_election_id, type_subtype, voter_id = nil)
46
- Decidim::BulletinBoard::MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || authority_slug)
47
- end
31
+ def unique_election_id(election_id)
32
+ MessageIdentifier.unique_election_id(settings.authority_slug, election_id)
48
33
  end
49
34
  end
50
35
  end
@@ -278,7 +278,7 @@
278
278
  "name": null,
279
279
  "ofType": {
280
280
  "kind": "SCALAR",
281
- "name": "String",
281
+ "name": "JSON",
282
282
  "ofType": null
283
283
  }
284
284
  },
@@ -435,6 +435,24 @@
435
435
  "isDeprecated": false,
436
436
  "deprecationReason": null
437
437
  },
438
+ {
439
+ "name": "decodedData",
440
+ "description": null,
441
+ "args": [
442
+
443
+ ],
444
+ "type": {
445
+ "kind": "NON_NULL",
446
+ "name": null,
447
+ "ofType": {
448
+ "kind": "SCALAR",
449
+ "name": "JSON",
450
+ "ofType": null
451
+ }
452
+ },
453
+ "isDeprecated": false,
454
+ "deprecationReason": null
455
+ },
438
456
  {
439
457
  "name": "election",
440
458
  "description": null,
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module BulletinBoard
5
+ module Graphql
6
+ class Factory
7
+ # The Bulletin Board GraphQL client factory
8
+ def self.client_for(settings)
9
+ Graphlient::Client.new(settings.server,
10
+ schema_path: File.join(__dir__, "bb_schema.json"),
11
+ headers: {
12
+ "Authorization" => settings.api_key
13
+ })
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module BulletinBoard
5
+ # The Bulletin Board settings class
6
+ class Settings
7
+ def initialize(config)
8
+ @server = config.server.presence
9
+ @server_public_key = config.server_public_key.presence
10
+ @api_key = config.api_key.presence
11
+
12
+ @authority_name = config.authority_name.presence
13
+ @identification_private_key = config.identification_private_key.presence
14
+
15
+ @scheme_name = config.scheme_name.presence
16
+ @number_of_trustees = config.number_of_trustees.presence
17
+ @quorum = config.quorum.presence || number_of_trustees
18
+ end
19
+
20
+ attr_reader :server, :server_public_key, :api_key, :authority_name, :scheme_name, :number_of_trustees, :quorum
21
+
22
+ def configured?
23
+ server && server_public_key && api_key && authority_name && private_key && scheme_name && number_of_trustees
24
+ end
25
+
26
+ def authority_slug
27
+ @authority_slug ||= authority_name.parameterize
28
+ end
29
+
30
+ def private_key
31
+ return nil unless identification_private_key.present?
32
+
33
+ @private_key ||= JwkUtils.import_private_key(identification_private_key)
34
+ end
35
+
36
+ def public_key
37
+ @public_key ||= private_key&.export
38
+ end
39
+
40
+ def server_public_key_rsa
41
+ @server_public_key_rsa ||= JWT::JWK::RSA.import(server_public_key).public_key
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :identification_private_key
47
+ end
48
+ end
49
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module BulletinBoard
5
- VERSION = "0.9.2"
5
+ VERSION = "0.10.0"
6
6
  end
7
7
  end
@@ -33,7 +33,7 @@ module Decidim
33
33
  }
34
34
 
35
35
  begin
36
- response = client.query do
36
+ response = graphql.query do
37
37
  mutation do
38
38
  vote(messageId: args[:message_id], signedData: args[:signed_data]) do
39
39
  pendingMessage do
@@ -22,7 +22,7 @@ module Decidim
22
22
  message_id = @message_id
23
23
 
24
24
  begin
25
- response = client.query do
25
+ response = graphql.query do
26
26
  query do
27
27
  pendingMessage(messageId: message_id) do
28
28
  status
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-bulletin_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Morcillo
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-02-02 00:00:00.000000000 Z
14
+ date: 2021-02-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -163,13 +163,13 @@ files:
163
163
  - app/assets/config/decidim_bulletin_board_manifest.js
164
164
  - app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js
165
165
  - bin/console
166
+ - bin/release
166
167
  - bin/setup
167
168
  - decidim-bulletin_board.gemspec
168
169
  - lib/decidim/bulletin_board.rb
169
- - lib/decidim/bulletin_board/authority.rb
170
170
  - lib/decidim/bulletin_board/authority/create_election.rb
171
171
  - lib/decidim/bulletin_board/authority/end_vote.rb
172
- - lib/decidim/bulletin_board/authority/get_election_log_entries_by_types.rb
172
+ - lib/decidim/bulletin_board/authority/get_election_results.rb
173
173
  - lib/decidim/bulletin_board/authority/get_election_status.rb
174
174
  - lib/decidim/bulletin_board/authority/publish_results.rb
175
175
  - lib/decidim/bulletin_board/authority/start_key_ceremony.rb
@@ -179,11 +179,11 @@ files:
179
179
  - lib/decidim/bulletin_board/command.rb
180
180
  - lib/decidim/bulletin_board/engine.rb
181
181
  - lib/decidim/bulletin_board/graphql/bb_schema.json
182
- - lib/decidim/bulletin_board/graphql/client.rb
182
+ - lib/decidim/bulletin_board/graphql/factory.rb
183
183
  - lib/decidim/bulletin_board/jwk_utils.rb
184
184
  - lib/decidim/bulletin_board/message_identifier.rb
185
+ - lib/decidim/bulletin_board/settings.rb
185
186
  - lib/decidim/bulletin_board/version.rb
186
- - lib/decidim/bulletin_board/voter.rb
187
187
  - lib/decidim/bulletin_board/voter/cast_vote.rb
188
188
  - lib/decidim/bulletin_board/voter/get_pending_message_status.rb
189
189
  homepage: https://github.com
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "decidim/bulletin_board/authority/create_election"
4
- require "decidim/bulletin_board/authority/end_vote"
5
- require "decidim/bulletin_board/authority/get_election_status"
6
- require "decidim/bulletin_board/authority/start_key_ceremony"
7
- require "decidim/bulletin_board/authority/start_tally"
8
- require "decidim/bulletin_board/authority/start_vote"
9
- require "decidim/bulletin_board/authority/publish_results"
10
- require "decidim/bulletin_board/authority/get_election_log_entries_by_types"
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module BulletinBoard
5
- module Authority
6
- # This command uses the GraphQL client to get the log entries of an election.
7
- class GetElectionLogEntriesByTypes < Decidim::BulletinBoard::Command
8
- # Public: Initializes the command.
9
- #
10
- # election_id [String] - The local election identifier
11
- # types [Array of Strings] - The message types you want to filter the log entries with
12
- def initialize(election_id, types)
13
- @election_id = election_id
14
- @types = types
15
- end
16
-
17
- # Executes the command. Broadcasts these events:
18
- #
19
- # - :ok when everything is valid and the query operation is successful.
20
- # - :error if query operation was not successful.
21
- #
22
- # Returns nothing.
23
- def call
24
- # arguments used inside the graphql operation
25
- args = {
26
- unique_id: unique_election_id(election_id),
27
- types: types
28
- }
29
-
30
- response = client.query do
31
- query do
32
- election(uniqueId: args[:unique_id]) do
33
- logEntries(types: args[:types]) do
34
- signedData
35
- end
36
- end
37
- end
38
- end
39
-
40
- broadcast(:ok, response.data.election.log_entries)
41
- rescue Graphlient::Errors::ServerError
42
- broadcast(:error, "Sorry, something went wrong")
43
- end
44
-
45
- private
46
-
47
- attr_reader :election_id, :types
48
- end
49
- end
50
- end
51
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module BulletinBoard
5
- module Graphql
6
- # The Bulletin Board GraphQL Client
7
- class Client
8
- def self.client
9
- @client ||= Graphlient::Client.new(BulletinBoard.server,
10
- schema_path: File.join(__dir__, "bb_schema.json"),
11
- headers: {
12
- "Authorization" => BulletinBoard.api_key
13
- })
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "decidim/bulletin_board/voter/cast_vote"
4
- require "decidim/bulletin_board/voter/get_pending_message_status"