decidim-bulletin_board 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/CHANGELOG.md +64 -0
- data/Gemfile.lock +8 -7
- data/app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js +16 -41063
- data/lib/decidim/bulletin_board/authority.rb +5 -2
- data/lib/decidim/bulletin_board/authority/create_election.rb +22 -16
- data/lib/decidim/bulletin_board/authority/end_vote.rb +57 -0
- data/lib/decidim/bulletin_board/authority/get_election_status.rb +12 -11
- data/lib/decidim/bulletin_board/authority/publish_results.rb +57 -0
- data/lib/decidim/bulletin_board/authority/start_key_ceremony.rb +57 -0
- data/lib/decidim/bulletin_board/authority/start_tally.rb +57 -0
- data/lib/decidim/bulletin_board/authority/start_vote.rb +57 -0
- data/lib/decidim/bulletin_board/client.rb +51 -18
- data/lib/decidim/bulletin_board/command.rb +9 -9
- data/lib/decidim/bulletin_board/graphql/bb_schema.json +505 -136
- data/lib/decidim/bulletin_board/version.rb +1 -1
- data/lib/decidim/bulletin_board/voter.rb +1 -0
- data/lib/decidim/bulletin_board/voter/cast_vote.rb +14 -3
- data/lib/decidim/bulletin_board/voter/get_pending_message_status.rb +41 -0
- metadata +8 -4
- data/lib/decidim/bulletin_board/authority/close_ballot_box.rb +0 -51
- data/lib/decidim/bulletin_board/authority/open_ballot_box.rb +0 -51
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "decidim/bulletin_board/authority/create_election"
|
4
|
+
require "decidim/bulletin_board/authority/end_vote"
|
4
5
|
require "decidim/bulletin_board/authority/get_election_status"
|
5
|
-
require "decidim/bulletin_board/authority/
|
6
|
-
require "decidim/bulletin_board/authority/
|
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,28 +10,34 @@ module Decidim
|
|
10
10
|
@election_data = election_data
|
11
11
|
end
|
12
12
|
|
13
|
+
# Returns the message_id related to the operation
|
14
|
+
def message_id
|
15
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "create_election")
|
16
|
+
end
|
17
|
+
|
13
18
|
def call
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
# arguments used inside the graphql operation
|
20
|
+
args = {
|
21
|
+
message_id: message_id,
|
22
|
+
signed_data: sign_message(message_id, election_data)
|
23
|
+
}
|
24
|
+
|
25
|
+
response = client.query do
|
26
|
+
mutation do
|
27
|
+
createElection(messageId: args[:message_id], signedData: args[:signed_data]) do
|
28
|
+
election do
|
29
|
+
status
|
25
30
|
end
|
31
|
+
error
|
26
32
|
end
|
27
33
|
end
|
34
|
+
end
|
28
35
|
|
29
|
-
|
36
|
+
return broadcast(:error, response.data.create_election.error) if response.data.create_election.error.present?
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
38
|
+
broadcast(:ok, response.data.create_election.election)
|
39
|
+
rescue Graphlient::Errors::ServerError
|
40
|
+
broadcast(:error, "Sorry, something went wrong")
|
35
41
|
end
|
36
42
|
|
37
43
|
private
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module BulletinBoard
|
5
|
+
module Authority
|
6
|
+
# This command uses the GraphQL client to request the ending of the voting period.
|
7
|
+
class EndVote < Decidim::BulletinBoard::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# election_id - The local election identifier
|
11
|
+
def initialize(election_id)
|
12
|
+
@election_id = election_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the message_id related to the operation
|
16
|
+
def message_id
|
17
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "end_vote")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid and the query operation is successful.
|
23
|
+
# - :error if query operation was not successful.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
# arguments used inside the graphql operation
|
28
|
+
args = {
|
29
|
+
message_id: message_id,
|
30
|
+
signed_data: sign_message(message_id, {})
|
31
|
+
}
|
32
|
+
|
33
|
+
response = client.query do
|
34
|
+
mutation do
|
35
|
+
endVote(messageId: args[:message_id], signedData: args[:signed_data]) do
|
36
|
+
pendingMessage do
|
37
|
+
status
|
38
|
+
end
|
39
|
+
error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return broadcast(:error, response.data.end_vote.error) if response.data.end_vote.error.present?
|
45
|
+
|
46
|
+
broadcast(:ok, response.data.end_vote.pending_message)
|
47
|
+
rescue Graphlient::Errors::FaradayServerError
|
48
|
+
broadcast(:error, "Sorry, something went wrong")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :election_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -19,21 +19,22 @@ module Decidim
|
|
19
19
|
#
|
20
20
|
# Returns nothing.
|
21
21
|
def call
|
22
|
-
|
22
|
+
# arguments used inside the graphql operation
|
23
|
+
args = {
|
24
|
+
unique_id: unique_election_id(election_id)
|
25
|
+
}
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
status
|
29
|
-
end
|
27
|
+
response = client.query do
|
28
|
+
query do
|
29
|
+
election(uniqueId: args[:unique_id]) do
|
30
|
+
status
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
|
-
broadcast(:ok, response.data.election.status)
|
34
|
-
rescue Graphlient::Errors::ServerError
|
35
|
-
broadcast(:error, "Sorry, something went wrong")
|
36
33
|
end
|
34
|
+
|
35
|
+
broadcast(:ok, response.data.election.status)
|
36
|
+
rescue Graphlient::Errors::ServerError
|
37
|
+
broadcast(:error, "Sorry, something went wrong")
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module BulletinBoard
|
5
|
+
module Authority
|
6
|
+
# This command uses the GraphQL client to publish the election results.
|
7
|
+
class PublishResults < Decidim::BulletinBoard::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# election_id - The local election identifier
|
11
|
+
def initialize(election_id)
|
12
|
+
@election_id = election_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the message_id related to the operation
|
16
|
+
def message_id
|
17
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "publish_results")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid and the query operation is successful.
|
23
|
+
# - :error if query operation was not successful.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
# arguments used inside the graphql operation
|
28
|
+
args = {
|
29
|
+
message_id: message_id,
|
30
|
+
signed_data: sign_message(message_id, {})
|
31
|
+
}
|
32
|
+
|
33
|
+
response = client.query do
|
34
|
+
mutation do
|
35
|
+
publishResults(messageId: args[:message_id], signedData: args[:signed_data]) do
|
36
|
+
election do
|
37
|
+
status
|
38
|
+
end
|
39
|
+
error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return broadcast(:error, response.data.publish_results.error) if response.data.publish_results.error.present?
|
45
|
+
|
46
|
+
broadcast(:ok, response.data.publish_results.election)
|
47
|
+
rescue Graphlient::Errors::ServerError
|
48
|
+
broadcast(:error, "Sorry, something went wrong")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :election_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module BulletinBoard
|
5
|
+
module Authority
|
6
|
+
# This command uses the GraphQL client to request the starting of the key ceremony.
|
7
|
+
class StartKeyCeremony < Decidim::BulletinBoard::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# election_id - The local election identifier
|
11
|
+
def initialize(election_id)
|
12
|
+
@election_id = election_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the message_id related to the operation
|
16
|
+
def message_id
|
17
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "start_key_ceremony")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid and the query operation is successful.
|
23
|
+
# - :error if query operation was not successful.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
# arguments used inside the graphql operation
|
28
|
+
args = {
|
29
|
+
message_id: message_id,
|
30
|
+
signed_data: sign_message(message_id, {})
|
31
|
+
}
|
32
|
+
|
33
|
+
response = client.query do
|
34
|
+
mutation do
|
35
|
+
startKeyCeremony(messageId: args[:message_id], signedData: args[:signed_data]) do
|
36
|
+
pendingMessage do
|
37
|
+
status
|
38
|
+
end
|
39
|
+
error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return broadcast(:error, response.data.start_key_ceremony.error) if response.data.start_key_ceremony.error.present?
|
45
|
+
|
46
|
+
broadcast(:ok, response.data.start_key_ceremony.pending_message)
|
47
|
+
rescue Graphlient::Errors::FaradayServerError
|
48
|
+
broadcast(:error, "Sorry, something went wrong")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :election_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module BulletinBoard
|
5
|
+
module Authority
|
6
|
+
# This command uses the GraphQL client to start the tally process.
|
7
|
+
class StartTally < Decidim::BulletinBoard::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# election_id - The local election identifier
|
11
|
+
def initialize(election_id)
|
12
|
+
@election_id = election_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the message_id related to the operation
|
16
|
+
def message_id
|
17
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "start_tally")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid and the query operation is successful.
|
23
|
+
# - :error if query operation was not successful.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
# arguments used inside the graphql operation
|
28
|
+
args = {
|
29
|
+
message_id: message_id,
|
30
|
+
signed_data: sign_message(message_id, {})
|
31
|
+
}
|
32
|
+
|
33
|
+
response = client.query do
|
34
|
+
mutation do
|
35
|
+
startTally(messageId: args[:message_id], signedData: args[:signed_data]) do
|
36
|
+
pendingMessage do
|
37
|
+
status
|
38
|
+
end
|
39
|
+
error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return broadcast(:error, response.data.start_tally.error) if response.data.start_tally.error.present?
|
45
|
+
|
46
|
+
broadcast(:ok, response.data.start_tally.pending_message)
|
47
|
+
rescue Graphlient::Errors::ServerError
|
48
|
+
broadcast(:error, "Sorry, something went wrong")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :election_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module BulletinBoard
|
5
|
+
module Authority
|
6
|
+
# This command uses the GraphQL client to request the starting of the voting period.
|
7
|
+
class StartVote < Decidim::BulletinBoard::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# election_id - The local election identifier
|
11
|
+
def initialize(election_id)
|
12
|
+
@election_id = election_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the message_id related to the operation
|
16
|
+
def message_id
|
17
|
+
@message_id ||= build_message_id(unique_election_id(election_id), "start_vote")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid and the query operation is successful.
|
23
|
+
# - :error if query operation was not successful.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
# arguments used inside the graphql operation
|
28
|
+
args = {
|
29
|
+
message_id: message_id,
|
30
|
+
signed_data: sign_message(message_id, {})
|
31
|
+
}
|
32
|
+
|
33
|
+
response = client.query do
|
34
|
+
mutation do
|
35
|
+
startVote(messageId: args[:message_id], signedData: args[:signed_data]) do
|
36
|
+
pendingMessage do
|
37
|
+
status
|
38
|
+
end
|
39
|
+
error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return broadcast(:error, response.data.start_vote.error) if response.data.start_vote.error.present?
|
45
|
+
|
46
|
+
broadcast(:ok, response.data.start_vote.pending_message)
|
47
|
+
rescue Graphlient::Errors::FaradayServerError
|
48
|
+
broadcast(:error, "Sorry, something went wrong")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :election_id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -21,9 +21,7 @@ module Decidim
|
|
21
21
|
delegate :authority_slug, to: Decidim::BulletinBoard::Command
|
22
22
|
|
23
23
|
def quorum
|
24
|
-
|
25
|
-
|
26
|
-
@scheme.dig(:parameters, :quorum)
|
24
|
+
@scheme.dig(:parameters, :quorum) || number_of_trustees
|
27
25
|
end
|
28
26
|
|
29
27
|
def public_key
|
@@ -36,37 +34,72 @@ module Decidim
|
|
36
34
|
|
37
35
|
def create_election(election_id, election_data)
|
38
36
|
create_election = Decidim::BulletinBoard::Authority::CreateElection.new(election_id, election_data)
|
37
|
+
yield create_election.message_id if block_given?
|
39
38
|
create_election.on(:ok) { |election| return election }
|
40
39
|
create_election.on(:error) { |error_message| raise StandardError, error_message }
|
41
40
|
create_election.call
|
42
41
|
end
|
43
42
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def start_key_ceremony(election_id)
|
44
|
+
start_key_ceremony = Decidim::BulletinBoard::Authority::StartKeyCeremony.new(election_id)
|
45
|
+
yield start_key_ceremony.message_id if block_given?
|
46
|
+
start_key_ceremony.on(:ok) { |pending_message| return pending_message }
|
47
|
+
start_key_ceremony.on(:error) { |error_message| raise StandardError, error_message }
|
48
|
+
start_key_ceremony.call
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def start_vote(election_id)
|
52
|
+
start_vote = Decidim::BulletinBoard::Authority::StartVote.new(election_id)
|
53
|
+
yield start_vote.message_id if block_given?
|
54
|
+
start_vote.on(:ok) { |pending_message| return pending_message }
|
55
|
+
start_vote.on(:error) { |error_message| raise StandardError, error_message }
|
56
|
+
start_vote.call
|
56
57
|
end
|
57
58
|
|
58
59
|
def cast_vote(election_id, voter_id, encrypted_vote)
|
59
60
|
cast_vote = Decidim::BulletinBoard::Voter::CastVote.new(election_id, voter_id, encrypted_vote)
|
61
|
+
yield cast_vote.message_id if block_given?
|
60
62
|
cast_vote.on(:ok) { |pending_message| return pending_message }
|
61
63
|
cast_vote.on(:error) { |error_message| raise StandardError, error_message }
|
62
64
|
cast_vote.call
|
63
65
|
end
|
64
66
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def get_pending_message_status(message_id)
|
68
|
+
get_pending_message_status = Decidim::BulletinBoard::Voter::GetPendingMessageStatus.new(message_id)
|
69
|
+
get_pending_message_status.on(:ok) { |status| return status }
|
70
|
+
get_pending_message_status.on(:error) { |error_message| raise StandardError, error_message }
|
71
|
+
get_pending_message_status.call
|
72
|
+
end
|
73
|
+
|
74
|
+
def end_vote(election_id)
|
75
|
+
end_vote = Decidim::BulletinBoard::Authority::EndVote.new(election_id)
|
76
|
+
yield end_vote.message_id if block_given?
|
77
|
+
end_vote.on(:ok) { |pending_message| return pending_message }
|
78
|
+
end_vote.on(:error) { |error_message| raise StandardError, error_message }
|
79
|
+
end_vote.call
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_election_status(election_id)
|
83
|
+
get_election_status = Decidim::BulletinBoard::Authority::GetElectionStatus.new(election_id)
|
84
|
+
get_election_status.on(:ok) { |status| return status }
|
85
|
+
get_election_status.on(:error) { |error_message| raise StandardError, error_message }
|
86
|
+
get_election_status.call
|
87
|
+
end
|
88
|
+
|
89
|
+
def start_tally(election_id)
|
90
|
+
start_tally = Decidim::BulletinBoard::Authority::StartTally.new(election_id)
|
91
|
+
yield start_tally.message_id if block_given?
|
92
|
+
start_tally.on(:ok) { |pending_message| return pending_message }
|
93
|
+
start_tally.on(:error) { |error_message| raise StandardError, error_message }
|
94
|
+
start_tally.call
|
95
|
+
end
|
96
|
+
|
97
|
+
def publish_results(election_id)
|
98
|
+
publish_results = Decidim::BulletinBoard::Authority::PublishResults.new(election_id)
|
99
|
+
yield publish_results.message_id if block_given?
|
100
|
+
publish_results.on(:ok) { |status| return status }
|
101
|
+
publish_results.on(:error) { |error_message| raise StandardError, error_message }
|
102
|
+
publish_results.call
|
70
103
|
end
|
71
104
|
|
72
105
|
private
|