decidim-bulletin_board 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ module Decidim
7
7
  class Client
8
8
  def self.client
9
9
  @client ||= Graphlient::Client.new(BulletinBoard.server,
10
+ schema_path: File.join(__dir__, "bb_schema.json"),
10
11
  headers: {
11
12
  "Authorization" => BulletinBoard.api_key
12
13
  })
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module BulletinBoard
5
- VERSION = "0.4.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "decidim/bulletin_board/voter/cast_vote"
4
- require "decidim/bulletin_board/voter/vote_form"
@@ -4,13 +4,14 @@ module Decidim
4
4
  module BulletinBoard
5
5
  module Voter
6
6
  # This command uses the GraphQL client to cast the vote.
7
- class CastVote
8
- include Wisper::Publisher
7
+ class CastVote < Decidim::BulletinBoard::Command
9
8
  # Public: Initializes the command.
10
9
  #
11
10
  # form - A form object with the params.
12
- def initialize(form)
13
- @form = form
11
+ def initialize(election_id, voter_id, encrypted_vote)
12
+ @election_id = election_id
13
+ @voter_id = voter_id
14
+ @encrypted_vote = encrypted_vote
14
15
  end
15
16
 
16
17
  # Executes the command. Broadcasts these events:
@@ -20,17 +21,13 @@ module Decidim
20
21
  #
21
22
  # Returns nothing.
22
23
  def call
23
- return broadcast(:error, form.errors.full_messages.join(". ")) unless form.valid?
24
-
25
- args = {
26
- message_id: form.message_id,
27
- signed_data: form.signed_data
28
- }
24
+ message_id = message_id(unique_election_id(election_id), "vote.cast", voter_id)
25
+ signed_data = sign_message(message_id, { content: encrypted_vote })
29
26
 
30
27
  begin
31
28
  response = client.query do
32
29
  mutation do
33
- vote(messageId: args[:message_id], signedData: args[:signed_data]) do
30
+ vote(messageId: message_id, signedData: signed_data) do
34
31
  pendingMessage do
35
32
  status
36
33
  end
@@ -49,11 +46,7 @@ module Decidim
49
46
 
50
47
  private
51
48
 
52
- attr_reader :form
53
-
54
- def client
55
- @client ||= BulletinBoard::Graphql::Client.client
56
- end
49
+ attr_reader :election_id, :voter_id, :encrypted_vote
57
50
  end
58
51
  end
59
52
  end
metadata CHANGED
@@ -1,32 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-bulletin_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Morcillo
8
8
  - Svenja Schäfer
9
- autorequire:
9
+ - Leonardo Diez
10
+ - Agustí B.R.
11
+ autorequire:
10
12
  bindir: exe
11
13
  cert_chain: []
12
- date: 2020-12-18 00:00:00.000000000 Z
14
+ date: 2021-01-12 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
- name: activemodel
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 5.0.0
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: 5.0.0
28
- - !ruby/object:Gem::Dependency
29
- name: activesupport
17
+ name: rails
30
18
  requirement: !ruby/object:Gem::Requirement
31
19
  requirements:
32
20
  - - ">="
@@ -155,6 +143,8 @@ description: ''
155
143
  email:
156
144
  - david@codegram.com
157
145
  - svenja@codegram.com
146
+ - leo@codegram.com
147
+ - agusti@codegram.com
158
148
  executables: []
159
149
  extensions: []
160
150
  extra_rdoc_files: []
@@ -170,26 +160,32 @@ files:
170
160
  - Gemfile.lock
171
161
  - README.md
172
162
  - Rakefile
163
+ - app/assets/config/decidim_bulletin_board_manifest.js
164
+ - app/assets/javascripts/decidim/bulletin_board/decidim-bulletin_board.js
173
165
  - bin/console
174
166
  - bin/setup
175
167
  - decidim-bulletin_board.gemspec
176
168
  - lib/decidim/bulletin_board.rb
177
169
  - lib/decidim/bulletin_board/authority.rb
170
+ - lib/decidim/bulletin_board/authority/close_ballot_box.rb
178
171
  - lib/decidim/bulletin_board/authority/create_election.rb
179
172
  - lib/decidim/bulletin_board/authority/get_election_status.rb
173
+ - lib/decidim/bulletin_board/authority/open_ballot_box.rb
180
174
  - lib/decidim/bulletin_board/client.rb
175
+ - lib/decidim/bulletin_board/command.rb
176
+ - lib/decidim/bulletin_board/engine.rb
177
+ - lib/decidim/bulletin_board/graphql/bb_schema.json
181
178
  - lib/decidim/bulletin_board/graphql/client.rb
182
179
  - lib/decidim/bulletin_board/jwk_utils.rb
183
180
  - lib/decidim/bulletin_board/message_identifier.rb
184
181
  - lib/decidim/bulletin_board/version.rb
185
182
  - lib/decidim/bulletin_board/voter.rb
186
183
  - lib/decidim/bulletin_board/voter/cast_vote.rb
187
- - lib/decidim/bulletin_board/voter/vote_form.rb
188
184
  homepage: https://github.com
189
185
  licenses:
190
186
  - AGPL-3.0
191
187
  metadata: {}
192
- post_install_message:
188
+ post_install_message:
193
189
  rdoc_options: []
194
190
  require_paths:
195
191
  - lib
@@ -205,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
201
  version: '0'
206
202
  requirements: []
207
203
  rubygems_version: 3.0.3
208
- signing_key:
204
+ signing_key:
209
205
  specification_version: 4
210
206
  summary: ''
211
207
  test_files: []
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module BulletinBoard
5
- module Voter
6
- # A form object to handle some data transformation and validation to cast a vote.
7
- class VoteForm
8
- include ActiveModel::Validations
9
-
10
- validates :election_data, :voter_data, :encrypted_vote, presence: true
11
- validate :election_id_present
12
- validate :voter_id_present
13
-
14
- # Public: initialize the form
15
- #
16
- # bulletin_board_data - An instance of the bulletin board client
17
- # election_data - A Hash including the necessary data from the election.
18
- # voter_data - A Hash including the necessary data from the voter.
19
- # encrypted_vote - A Hash including the encrypted vote to cast
20
- def initialize(bulletin_board_client, election_data, voter_data, encrypted_vote)
21
- @bulletin_board_client = bulletin_board_client
22
- @election_data = election_data
23
- @voter_data = voter_data
24
- @encrypted_vote = encrypted_vote
25
- end
26
-
27
- # Public: returns a message identifier for the cast vote operation.
28
- def message_id
29
- @message_id ||= "#{election_id}.vote.cast+v.#{voter_id}"
30
- end
31
-
32
- # Public: uses the bulletin board client to sign the encrypted vote merged with the metadata
33
- def signed_data
34
- @signed_data ||= bulletin_board_client.sign_data(message)
35
- end
36
-
37
- private
38
-
39
- attr_reader :bulletin_board_client, :election_data, :voter_data, :encrypted_vote
40
-
41
- def election_id_present
42
- errors.add(:election_data, "doesn't include the election id") unless election_id.present?
43
- end
44
-
45
- def election_id
46
- return if election_data.blank?
47
-
48
- election_data[:election_id]
49
- end
50
-
51
- def voter_id_present
52
- errors.add(:voter_data, "doesn't include the voter id") unless voter_id.present?
53
- end
54
-
55
- def voter_id
56
- return if voter_data.blank?
57
-
58
- voter_data[:voter_id]
59
- end
60
-
61
- def message
62
- {
63
- iat: Time.now.to_i,
64
- message_id: message_id,
65
- content: encrypted_vote
66
- }
67
- end
68
- end
69
- end
70
- end
71
- end