decidim-bulletin_board 0.9.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -0
- data/Gemfile.lock +60 -56
- data/app/assets/config/{decidim_bulletin_board_manifest.js → manifest.js} +0 -0
- data/app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js +279 -2
- data/bin/release +10 -0
- data/lib/decidim/bulletin_board.rb +16 -20
- data/lib/decidim/bulletin_board/authority/create_election.rb +100 -2
- data/lib/decidim/bulletin_board/authority/end_vote.rb +1 -1
- data/lib/decidim/bulletin_board/authority/get_election_results.rb +63 -0
- data/lib/decidim/bulletin_board/authority/get_election_status.rb +1 -1
- data/lib/decidim/bulletin_board/authority/publish_results.rb +1 -1
- data/lib/decidim/bulletin_board/authority/start_key_ceremony.rb +1 -1
- data/lib/decidim/bulletin_board/authority/start_tally.rb +1 -1
- data/lib/decidim/bulletin_board/authority/start_vote.rb +1 -1
- data/lib/decidim/bulletin_board/client.rb +36 -38
- data/lib/decidim/bulletin_board/command.rb +11 -26
- data/lib/decidim/bulletin_board/graphql/bb_schema.json +19 -1
- data/lib/decidim/bulletin_board/graphql/factory.rb +18 -0
- data/lib/decidim/bulletin_board/message_identifier.rb +7 -3
- data/lib/decidim/bulletin_board/settings.rb +41 -0
- data/lib/decidim/bulletin_board/version.rb +1 -1
- data/lib/decidim/bulletin_board/voter/cast_vote.rb +1 -1
- data/lib/decidim/bulletin_board/voter/get_pending_message_status.rb +1 -1
- metadata +7 -7
- data/lib/decidim/bulletin_board/authority.rb +0 -10
- data/lib/decidim/bulletin_board/authority/get_election_log_entries_by_types.rb +0 -51
- data/lib/decidim/bulletin_board/graphql/client.rb +0 -18
- data/lib/decidim/bulletin_board/voter.rb +0 -4
@@ -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
|
-
|
9
|
+
attr_reader :settings, :graphql
|
12
10
|
|
13
|
-
def
|
14
|
-
|
11
|
+
def configure(settings, graphql)
|
12
|
+
@settings = settings
|
13
|
+
@graphql = graphql
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
18
|
-
|
16
|
+
def sign_message(message_id, message)
|
17
|
+
JWT.encode(complete_message(message_id, message), settings.authority_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
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
46
|
-
|
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": "
|
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.bulletin_board_server,
|
10
|
+
schema_path: File.join(__dir__, "bb_schema.json"),
|
11
|
+
headers: {
|
12
|
+
"Authorization" => settings.authority_api_key
|
13
|
+
})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -41,15 +41,19 @@ module Decidim
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def election_id
|
44
|
-
@election_id
|
44
|
+
@election_id ||= elements[0..1].join(".")
|
45
45
|
end
|
46
46
|
|
47
47
|
def type
|
48
|
-
@type
|
48
|
+
@type ||= elements[2]
|
49
49
|
end
|
50
50
|
|
51
51
|
def subtype
|
52
|
-
@subtype
|
52
|
+
@subtype ||= elements[3]
|
53
|
+
end
|
54
|
+
|
55
|
+
def type_subtype
|
56
|
+
@type_subtype ||= [type, subtype].compact.join(".")
|
53
57
|
end
|
54
58
|
|
55
59
|
def to_s
|
@@ -0,0 +1,41 @@
|
|
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
|
+
@bulletin_board_server = config.bulletin_board_server.presence
|
9
|
+
@bulletin_board_public_key = config.bulletin_board_public_key.presence
|
10
|
+
|
11
|
+
@authority_api_key = config.authority_api_key.presence
|
12
|
+
@authority_name = config.authority_name.presence
|
13
|
+
@authority_private_key = JwkUtils.import_private_key(config.authority_private_key) if config.authority_private_key.present?
|
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
|
+
def configured?
|
21
|
+
bulletin_board_server && bulletin_board_public_key && authority_api_key && authority_name && authority_private_key && scheme_name && number_of_trustees
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :bulletin_board_server, :bulletin_board_public_key,
|
25
|
+
:authority_private_key, :authority_api_key, :authority_name,
|
26
|
+
:scheme_name, :number_of_trustees, :quorum
|
27
|
+
|
28
|
+
def bulletin_board_public_key_rsa
|
29
|
+
@bulletin_board_public_key_rsa ||= JWT::JWK::RSA.import(bulletin_board_public_key).public_key
|
30
|
+
end
|
31
|
+
|
32
|
+
def authority_slug
|
33
|
+
@authority_slug ||= authority_name.parameterize
|
34
|
+
end
|
35
|
+
|
36
|
+
def authority_public_key
|
37
|
+
@authority_public_key ||= authority_private_key&.export
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
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.
|
4
|
+
version: 0.12.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-
|
14
|
+
date: 2021-02-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -160,16 +160,16 @@ files:
|
|
160
160
|
- Gemfile.lock
|
161
161
|
- README.md
|
162
162
|
- Rakefile
|
163
|
-
- app/assets/config/
|
163
|
+
- app/assets/config/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/
|
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/
|
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
|