decidim-bulletin_board 0.17.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc363471aea52b3ad74405e87e9410937432954146e13a929c94b8fadcad3629
4
- data.tar.gz: 70baf206b39fa702eab21665c99b4ee9c45b897862317bc46aa8622c5c643933
3
+ metadata.gz: '03922663d9b5541ee3f5e27ac57825b7306c4b4d876068d607ab6774ff61acdb'
4
+ data.tar.gz: d3c3569be3291c7ebbbe4b42aa8727ff172c486eb13ced87649ad6c93a18691f
5
5
  SHA512:
6
- metadata.gz: 326b1a82ecf89514a0e96f646b30ee74ba9d1daa00b4eb8e03b0ec75de64c71bcfd3a850f52660c7636a372e16bbb1ea288cc06ee7b706947846b8747a3abc52
7
- data.tar.gz: '07967b7cd63e30bdb0727bd4b325975d25dfd7a5538cee9c28239a8b03c1ffa50ac4e51297b9e940be58c3e32f15b195706c18ab721918392e57c6ad868ed0f7'
6
+ metadata.gz: 25066d09cf994dc43f03f1100d7eedd54c5c386aeb7e58210ffe8219bf3ef363f20ff42e209867381cb8a823bee50eb9c2aa888e9d6a31a2d6e01a0bb2b3add5
7
+ data.tar.gz: f46fd917b4c8673414850410f05a04f997964ee005e30a384925d73a8374aa393b1cc2942ea4bfb67c59a7c85f6208ff7f1a490f8018b919cca3863726e710a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-bulletin_board (0.17.0)
4
+ decidim-bulletin_board (0.21.0)
5
5
  byebug (~> 11.0)
6
6
  graphlient (~> 0.4.0)
7
7
  jwt (~> 2.2.2)
@@ -83,11 +83,15 @@ GEM
83
83
  erubi (1.10.0)
84
84
  faker (2.15.1)
85
85
  i18n (>= 1.6, < 2)
86
- faraday (1.3.0)
86
+ faraday (1.4.1)
87
+ faraday-excon (~> 1.1)
87
88
  faraday-net_http (~> 1.0)
89
+ faraday-net_http_persistent (~> 1.1)
88
90
  multipart-post (>= 1.2, < 3)
89
- ruby2_keywords
91
+ ruby2_keywords (>= 0.0.4)
92
+ faraday-excon (1.1.0)
90
93
  faraday-net_http (1.0.1)
94
+ faraday-net_http_persistent (1.1.0)
91
95
  faraday_middleware (1.0.0)
92
96
  faraday (~> 1.0)
93
97
  globalid (0.4.2)
@@ -103,7 +107,7 @@ GEM
103
107
  hashdiff (1.0.1)
104
108
  i18n (1.8.10)
105
109
  concurrent-ruby (~> 1.0)
106
- jwt (2.2.2)
110
+ jwt (2.2.3)
107
111
  loofah (2.9.1)
108
112
  crass (~> 1.0.2)
109
113
  nokogiri (>= 1.5.9)
@@ -227,4 +231,4 @@ DEPENDENCIES
227
231
  wisper-rspec (~> 1.1.0)
228
232
 
229
233
  BUNDLED WITH
230
- 2.2.0
234
+ 2.2.15
@@ -50,6 +50,7 @@ module Decidim
50
50
  bulletin_board: bulletin_board,
51
51
  authority: authority,
52
52
  trustees: trustees,
53
+ polling_stations: polling_stations,
53
54
  description: {
54
55
  name: text(election_data[:title]),
55
56
  start_date: election_data[:start_date].strftime("%FT%T%:z"),
@@ -94,6 +95,10 @@ module Decidim
94
95
  end
95
96
  end
96
97
 
98
+ def polling_stations
99
+ election_data[:polling_stations] || []
100
+ end
101
+
97
102
  def contests
98
103
  election_data[:questions].each_with_index.map do |question, index|
99
104
  {
@@ -33,22 +33,25 @@ module Decidim
33
33
  logEntries(types: args[:types]) do
34
34
  signedData
35
35
  end
36
+ verifiableResultsUrl
37
+ verifiableResultsHash
36
38
  end
37
39
  end
38
40
  end
39
41
 
40
42
  return broadcast(:error, "There aren't any log entries with type: 'end_tally' for this election.") if response.data.election.log_entries.empty?
41
43
 
42
- @signed_data = response.data.election.log_entries.first.signed_data
44
+ @election = response.data.election
45
+ @signed_data = election.log_entries.first.signed_data
43
46
 
44
- broadcast(:ok, decoded_data["results"])
47
+ broadcast(:ok, { election_results: decoded_data["results"], verifiable_results: verifiable_results })
45
48
  rescue Graphlient::Errors::ServerError
46
49
  broadcast(:error, "Sorry, something went wrong")
47
50
  end
48
51
 
49
52
  private
50
53
 
51
- attr_reader :election_id, :types, :signed_data
54
+ attr_reader :election_id, :types, :signed_data, :election
52
55
 
53
56
  def decoded_data
54
57
  @decoded_data ||= begin
@@ -57,6 +60,13 @@ module Decidim
57
60
  { error: e.message }
58
61
  end
59
62
  end
63
+
64
+ def verifiable_results
65
+ {
66
+ url: election.verifiable_results_url,
67
+ hash: election.verifiable_results_hash
68
+ }
69
+ end
60
70
  end
61
71
  end
62
72
  end
@@ -14,6 +14,7 @@ require "decidim/bulletin_board/authority/publish_results"
14
14
  require "decidim/bulletin_board/authority/get_election_results"
15
15
  require "decidim/bulletin_board/voter/cast_vote"
16
16
  require "decidim/bulletin_board/voter/get_pending_message_status"
17
+ require "decidim/bulletin_board/voter/in_person_vote"
17
18
  require "decidim/bulletin_board/test/reset_test_database"
18
19
 
19
20
  module Decidim
@@ -62,6 +63,14 @@ module Decidim
62
63
  cast_vote.call
63
64
  end
64
65
 
66
+ def in_person_vote(election_id, voter_id, polling_station_id)
67
+ in_person_vote = configure Voter::InPersonVote.new(election_id, voter_id, polling_station_id)
68
+ yield in_person_vote.message_id if block_given?
69
+ in_person_vote.on(:ok) { |pending_message| return pending_message }
70
+ in_person_vote.on(:error) { |error_message| raise StandardError, error_message }
71
+ in_person_vote.call
72
+ end
73
+
65
74
  def get_pending_message_status(message_id)
66
75
  get_pending_message_status = configure Voter::GetPendingMessageStatus.new(message_id)
67
76
  get_pending_message_status.on(:ok) { |status| return status }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module BulletinBoard
5
- VERSION = "0.17.0"
5
+ VERSION = "0.21.0"
6
6
  end
7
7
  end
@@ -7,7 +7,9 @@ module Decidim
7
7
  class CastVote < Decidim::BulletinBoard::Command
8
8
  # Public: Initializes the command.
9
9
  #
10
- # form - A form object with the params.
10
+ # election_id - The local election identifier
11
+ # voter_id - The unique identifier of the voter
12
+ # encrypted_vote - The content of the encrypted vote.
11
13
  def initialize(election_id, voter_id, encrypted_vote)
12
14
  @election_id = election_id
13
15
  @voter_id = voter_id
@@ -55,8 +57,6 @@ module Decidim
55
57
 
56
58
  private
57
59
 
58
- delegate :cast_vote_message_id, to: :class
59
-
60
60
  attr_reader :election_id, :voter_id, :encrypted_vote
61
61
  end
62
62
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module BulletinBoard
5
+ module Voter
6
+ # This command uses the GraphQL client to inform about a vote casted in person in a polling station.
7
+ class InPersonVote < Decidim::BulletinBoard::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # election_id - The local election identifier
11
+ # voter_id - The unique identifier of the voter
12
+ # polling_station_id - The identifier of the polling station where the vote was casted.
13
+ def initialize(election_id, voter_id, polling_station_id)
14
+ @election_id = election_id
15
+ @voter_id = voter_id
16
+ @polling_station_id = polling_station_id
17
+ end
18
+
19
+ # Returns the message_id related to the operation
20
+ def message_id
21
+ @message_id ||= build_message_id(unique_election_id(election_id), "vote.in_person", voter_id)
22
+ end
23
+
24
+ # Executes the command. Broadcasts these events:
25
+ #
26
+ # - :ok when everything is valid and the mutation operation is successful.
27
+ # - :error if the form wasn't valid or the mutation operation was not successful.
28
+ #
29
+ # Returns nothing.
30
+ def call
31
+ # arguments used inside the graphql operation
32
+ args = {
33
+ message_id: message_id,
34
+ signed_data: sign_message(message_id, { polling_station_id: polling_station_id })
35
+ }
36
+
37
+ begin
38
+ response = graphql.query do
39
+ mutation do
40
+ vote(messageId: args[:message_id], signedData: args[:signed_data]) do
41
+ pendingMessage do
42
+ messageId
43
+ status
44
+ end
45
+ error
46
+ end
47
+ end
48
+ end
49
+
50
+ return broadcast(:error, response.data.vote.error) if response.data.vote.error.present?
51
+
52
+ broadcast(:ok, response.data.vote.pending_message)
53
+ rescue Graphlient::Errors::FaradayServerError
54
+ broadcast(:error, "something went wrong")
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ attr_reader :election_id, :voter_id, :polling_station_id
61
+ end
62
+ end
63
+ end
64
+ 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.17.0
4
+ version: 0.21.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-04-12 00:00:00.000000000 Z
14
+ date: 2021-04-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -186,6 +186,7 @@ files:
186
186
  - lib/decidim/bulletin_board/version.rb
187
187
  - lib/decidim/bulletin_board/voter/cast_vote.rb
188
188
  - lib/decidim/bulletin_board/voter/get_pending_message_status.rb
189
+ - lib/decidim/bulletin_board/voter/in_person_vote.rb
189
190
  homepage: https://github.com/decidim/decidim-bulletin-board
190
191
  licenses:
191
192
  - AGPL-3.0