decidim-bulletin_board 0.15.2 → 0.18.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: 41fe89dbbb133f650cbadd8e22d4cd7bb67687b13b591afddf70334b74c96bf0
4
- data.tar.gz: 850c0ccab8c4cc1b4a3837de32eaf386514d1ff8f99786510b9ca8f658ef56f5
3
+ metadata.gz: 5bd025ed5f336f685e503a1401902e26c62f4eba4e5bef652fa811a1d83a874f
4
+ data.tar.gz: e71eadb9dd3221324ac7a114f5fd73222089c87db377b32f120632ea6a3b9673
5
5
  SHA512:
6
- metadata.gz: 053e32a801dc8c535363a7ca3b391dc8ed67b70efd1afb584dad16451f4648bc3a129ef3847cacedf25100e7c641c67c3f477c0fef9aeb05e5c45f17da27b6de
7
- data.tar.gz: 9b8246def474df901503bcb72efe953b87710a3ca477248dc15d44a95703b2f3600afacbbe0a73e2c1dee098a18150111206b1ba9639f78b14cab067270b483a
6
+ metadata.gz: 912fda5b140c9ee1acc4ed7eb9513e24aca52586d3974708c9d03b6b5716a59890025f018ded4a981bc46457ea02d287aa15a00b068b550cf75e392ecd2c8a80
7
+ data.tar.gz: f7913e4ccd28f94c816d0d0d348a47ec9b7877e1c9cba5bb00287da840740a50550066cb2a370ad99dc13032bee96f21bb4071cb5926bc749597c5b679ccaf78
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/
1
+ /.bundle
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-bulletin_board (0.15.2)
4
+ decidim-bulletin_board (0.18.0)
5
5
  byebug (~> 11.0)
6
6
  graphlient (~> 0.4.0)
7
7
  jwt (~> 2.2.2)
@@ -11,60 +11,60 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actioncable (6.1.3)
15
- actionpack (= 6.1.3)
16
- activesupport (= 6.1.3)
14
+ actioncable (6.1.3.1)
15
+ actionpack (= 6.1.3.1)
16
+ activesupport (= 6.1.3.1)
17
17
  nio4r (~> 2.0)
18
18
  websocket-driver (>= 0.6.1)
19
- actionmailbox (6.1.3)
20
- actionpack (= 6.1.3)
21
- activejob (= 6.1.3)
22
- activerecord (= 6.1.3)
23
- activestorage (= 6.1.3)
24
- activesupport (= 6.1.3)
19
+ actionmailbox (6.1.3.1)
20
+ actionpack (= 6.1.3.1)
21
+ activejob (= 6.1.3.1)
22
+ activerecord (= 6.1.3.1)
23
+ activestorage (= 6.1.3.1)
24
+ activesupport (= 6.1.3.1)
25
25
  mail (>= 2.7.1)
26
- actionmailer (6.1.3)
27
- actionpack (= 6.1.3)
28
- actionview (= 6.1.3)
29
- activejob (= 6.1.3)
30
- activesupport (= 6.1.3)
26
+ actionmailer (6.1.3.1)
27
+ actionpack (= 6.1.3.1)
28
+ actionview (= 6.1.3.1)
29
+ activejob (= 6.1.3.1)
30
+ activesupport (= 6.1.3.1)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  rails-dom-testing (~> 2.0)
33
- actionpack (6.1.3)
34
- actionview (= 6.1.3)
35
- activesupport (= 6.1.3)
33
+ actionpack (6.1.3.1)
34
+ actionview (= 6.1.3.1)
35
+ activesupport (= 6.1.3.1)
36
36
  rack (~> 2.0, >= 2.0.9)
37
37
  rack-test (>= 0.6.3)
38
38
  rails-dom-testing (~> 2.0)
39
39
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
- actiontext (6.1.3)
41
- actionpack (= 6.1.3)
42
- activerecord (= 6.1.3)
43
- activestorage (= 6.1.3)
44
- activesupport (= 6.1.3)
40
+ actiontext (6.1.3.1)
41
+ actionpack (= 6.1.3.1)
42
+ activerecord (= 6.1.3.1)
43
+ activestorage (= 6.1.3.1)
44
+ activesupport (= 6.1.3.1)
45
45
  nokogiri (>= 1.8.5)
46
- actionview (6.1.3)
47
- activesupport (= 6.1.3)
46
+ actionview (6.1.3.1)
47
+ activesupport (= 6.1.3.1)
48
48
  builder (~> 3.1)
49
49
  erubi (~> 1.4)
50
50
  rails-dom-testing (~> 2.0)
51
51
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
- activejob (6.1.3)
53
- activesupport (= 6.1.3)
52
+ activejob (6.1.3.1)
53
+ activesupport (= 6.1.3.1)
54
54
  globalid (>= 0.3.6)
55
- activemodel (6.1.3)
56
- activesupport (= 6.1.3)
57
- activerecord (6.1.3)
58
- activemodel (= 6.1.3)
59
- activesupport (= 6.1.3)
60
- activestorage (6.1.3)
61
- actionpack (= 6.1.3)
62
- activejob (= 6.1.3)
63
- activerecord (= 6.1.3)
64
- activesupport (= 6.1.3)
65
- marcel (~> 0.3.1)
66
- mimemagic (~> 0.3.2)
67
- activesupport (6.1.3)
55
+ activemodel (6.1.3.1)
56
+ activesupport (= 6.1.3.1)
57
+ activerecord (6.1.3.1)
58
+ activemodel (= 6.1.3.1)
59
+ activesupport (= 6.1.3.1)
60
+ activestorage (6.1.3.1)
61
+ actionpack (= 6.1.3.1)
62
+ activejob (= 6.1.3.1)
63
+ activerecord (= 6.1.3.1)
64
+ activesupport (= 6.1.3.1)
65
+ marcel (~> 1.0.0)
66
+ mini_mime (~> 1.0.2)
67
+ activesupport (6.1.3.1)
68
68
  concurrent-ruby (~> 1.0, >= 1.0.2)
69
69
  i18n (>= 1.6, < 2)
70
70
  minitest (>= 5.1)
@@ -75,7 +75,7 @@ GEM
75
75
  ast (2.4.1)
76
76
  builder (3.2.4)
77
77
  byebug (11.1.3)
78
- concurrent-ruby (1.1.7)
78
+ concurrent-ruby (1.1.8)
79
79
  crack (0.4.5)
80
80
  rexml
81
81
  crass (1.0.6)
@@ -96,31 +96,33 @@ GEM
96
96
  faraday (>= 1.0)
97
97
  faraday_middleware
98
98
  graphql-client
99
- graphql (1.12.6)
99
+ graphql (1.12.8)
100
100
  graphql-client (0.16.0)
101
101
  activesupport (>= 3.0)
102
102
  graphql (~> 1.8)
103
103
  hashdiff (1.0.1)
104
- i18n (1.8.5)
104
+ i18n (1.8.10)
105
105
  concurrent-ruby (~> 1.0)
106
106
  jwt (2.2.2)
107
- loofah (2.9.0)
107
+ loofah (2.9.1)
108
108
  crass (~> 1.0.2)
109
109
  nokogiri (>= 1.5.9)
110
110
  mail (2.7.1)
111
111
  mini_mime (>= 0.1.1)
112
- marcel (0.3.3)
113
- mimemagic (~> 0.3.2)
112
+ marcel (1.0.1)
114
113
  method_source (1.0.0)
115
- mimemagic (0.3.5)
116
- mini_mime (1.0.2)
114
+ mini_mime (1.0.3)
117
115
  mini_portile2 (2.5.0)
118
116
  minitest (5.14.4)
119
117
  multipart-post (2.1.1)
120
118
  nio4r (2.5.7)
121
- nokogiri (1.11.2)
119
+ nokogiri (1.11.3)
122
120
  mini_portile2 (~> 2.5.0)
123
121
  racc (~> 1.4)
122
+ nokogiri (1.11.3-x86_64-darwin)
123
+ racc (~> 1.4)
124
+ nokogiri (1.11.3-x86_64-linux)
125
+ racc (~> 1.4)
124
126
  parallel (1.20.1)
125
127
  parser (2.7.2.0)
126
128
  ast (~> 2.4.1)
@@ -129,34 +131,34 @@ GEM
129
131
  rack (2.2.3)
130
132
  rack-test (1.1.0)
131
133
  rack (>= 1.0, < 3)
132
- rails (6.1.3)
133
- actioncable (= 6.1.3)
134
- actionmailbox (= 6.1.3)
135
- actionmailer (= 6.1.3)
136
- actionpack (= 6.1.3)
137
- actiontext (= 6.1.3)
138
- actionview (= 6.1.3)
139
- activejob (= 6.1.3)
140
- activemodel (= 6.1.3)
141
- activerecord (= 6.1.3)
142
- activestorage (= 6.1.3)
143
- activesupport (= 6.1.3)
134
+ rails (6.1.3.1)
135
+ actioncable (= 6.1.3.1)
136
+ actionmailbox (= 6.1.3.1)
137
+ actionmailer (= 6.1.3.1)
138
+ actionpack (= 6.1.3.1)
139
+ actiontext (= 6.1.3.1)
140
+ actionview (= 6.1.3.1)
141
+ activejob (= 6.1.3.1)
142
+ activemodel (= 6.1.3.1)
143
+ activerecord (= 6.1.3.1)
144
+ activestorage (= 6.1.3.1)
145
+ activesupport (= 6.1.3.1)
144
146
  bundler (>= 1.15.0)
145
- railties (= 6.1.3)
147
+ railties (= 6.1.3.1)
146
148
  sprockets-rails (>= 2.0.0)
147
149
  rails-dom-testing (2.0.3)
148
150
  activesupport (>= 4.2.0)
149
151
  nokogiri (>= 1.6)
150
152
  rails-html-sanitizer (1.3.0)
151
153
  loofah (~> 2.3)
152
- railties (6.1.3)
153
- actionpack (= 6.1.3)
154
- activesupport (= 6.1.3)
154
+ railties (6.1.3.1)
155
+ actionpack (= 6.1.3.1)
156
+ activesupport (= 6.1.3.1)
155
157
  method_source
156
158
  rake (>= 0.8.7)
157
159
  thor (~> 1.0)
158
160
  rainbow (3.0.0)
159
- rake (13.0.1)
161
+ rake (13.0.3)
160
162
  regexp_parser (2.0.0)
161
163
  rexml (3.2.4)
162
164
  rspec (3.9.0)
@@ -229,4 +231,4 @@ DEPENDENCIES
229
231
  wisper-rspec (~> 1.1.0)
230
232
 
231
233
  BUNDLED WITH
232
- 2.2.0
234
+ 2.2.15
@@ -50,12 +50,14 @@ 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
- start_date: election_data[:start_date].iso8601,
56
- end_date: election_data[:end_date].iso8601,
56
+ start_date: election_data[:start_date].strftime("%FT%T%:z"),
57
+ end_date: election_data[:end_date].strftime("%FT%T%:z"),
57
58
  candidates: candidates,
58
- contests: contests
59
+ contests: contests,
60
+ ballot_styles: ballot_styles
59
61
  }
60
62
  }
61
63
  end
@@ -93,6 +95,10 @@ module Decidim
93
95
  end
94
96
  end
95
97
 
98
+ def polling_stations
99
+ election_data[:polling_stations] || []
100
+ end
101
+
96
102
  def contests
97
103
  election_data[:questions].each_with_index.map do |question, index|
98
104
  {
@@ -128,6 +134,15 @@ module Decidim
128
134
  end
129
135
  end
130
136
 
137
+ def ballot_styles
138
+ election_data[:ballot_styles].map do |ballot_style_id, question_ids|
139
+ {
140
+ object_id: ballot_style_id.to_s,
141
+ contests: question_ids
142
+ }
143
+ end
144
+ end
145
+
131
146
  def default_text(field)
132
147
  field[default_locale]
133
148
  end
@@ -14,6 +14,8 @@ 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"
18
+ require "decidim/bulletin_board/test/reset_test_database"
17
19
 
18
20
  module Decidim
19
21
  module BulletinBoard
@@ -61,6 +63,14 @@ module Decidim
61
63
  cast_vote.call
62
64
  end
63
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
+
64
74
  def get_pending_message_status(message_id)
65
75
  get_pending_message_status = configure Voter::GetPendingMessageStatus.new(message_id)
66
76
  get_pending_message_status.on(:ok) { |status| return status }
@@ -106,6 +116,15 @@ module Decidim
106
116
  publish_results.call
107
117
  end
108
118
 
119
+ if Rails.env.test?
120
+ def reset_test_database
121
+ reset_test_database = configure Test::ResetTestDatabase.new
122
+ reset_test_database.on(:ok) { |result| return result }
123
+ reset_test_database.on(:error) { |error_message| raise StandardError, error_message }
124
+ reset_test_database.call
125
+ end
126
+ end
127
+
109
128
  private
110
129
 
111
130
  attr_reader :settings, :graphql
@@ -398,6 +398,16 @@
398
398
  "enumValues": null,
399
399
  "possibleTypes": null
400
400
  },
401
+ {
402
+ "kind": "SCALAR",
403
+ "name": "Int",
404
+ "description": "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.",
405
+ "fields": null,
406
+ "inputFields": null,
407
+ "interfaces": null,
408
+ "enumValues": null,
409
+ "possibleTypes": null
410
+ },
401
411
  {
402
412
  "kind": "SCALAR",
403
413
  "name": "JSON",
@@ -875,6 +885,20 @@
875
885
  "isDeprecated": false,
876
886
  "deprecationReason": null
877
887
  },
888
+ {
889
+ "name": "resetTestDatabase",
890
+ "description": null,
891
+ "args": [
892
+
893
+ ],
894
+ "type": {
895
+ "kind": "OBJECT",
896
+ "name": "ResetTestDatabaseMutationPayload",
897
+ "ofType": null
898
+ },
899
+ "isDeprecated": false,
900
+ "deprecationReason": null
901
+ },
878
902
  {
879
903
  "name": "startKeyCeremony",
880
904
  "description": null,
@@ -1475,6 +1499,37 @@
1475
1499
  "enumValues": null,
1476
1500
  "possibleTypes": null
1477
1501
  },
1502
+ {
1503
+ "kind": "OBJECT",
1504
+ "name": "ResetTestDatabaseMutationPayload",
1505
+ "description": "Autogenerated return type of ResetTestDatabaseMutation",
1506
+ "fields": [
1507
+ {
1508
+ "name": "timestamp",
1509
+ "description": null,
1510
+ "args": [
1511
+
1512
+ ],
1513
+ "type": {
1514
+ "kind": "NON_NULL",
1515
+ "name": null,
1516
+ "ofType": {
1517
+ "kind": "SCALAR",
1518
+ "name": "Int",
1519
+ "ofType": null
1520
+ }
1521
+ },
1522
+ "isDeprecated": false,
1523
+ "deprecationReason": null
1524
+ }
1525
+ ],
1526
+ "inputFields": null,
1527
+ "interfaces": [
1528
+
1529
+ ],
1530
+ "enumValues": null,
1531
+ "possibleTypes": null
1532
+ },
1478
1533
  {
1479
1534
  "kind": "OBJECT",
1480
1535
  "name": "StartKeyCeremonyMutationPayload",
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module BulletinBoard
5
+ module Test
6
+ # This command uses the GraphQL client to clear the database in test mode.
7
+ class ResetTestDatabase < Decidim::BulletinBoard::Command
8
+ # Executes the command. Broadcasts these events:
9
+ #
10
+ # - :ok when everything is valid and the mutation operation is successful.
11
+ # - :error if query operation was not successful.
12
+ #
13
+ # Returns nothing.
14
+ def call
15
+ graphql.query do
16
+ mutation do
17
+ resetTestDatabase do
18
+ timestamp
19
+ end
20
+ end
21
+ end
22
+
23
+ broadcast(:ok)
24
+ rescue Graphlient::Errors::ServerError
25
+ broadcast(:error, "Sorry, something went wrong")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module BulletinBoard
5
- VERSION = "0.15.2"
5
+ VERSION = "0.18.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,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-bulletin_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Morcillo
8
8
  - Svenja Schäfer
9
9
  - Leonardo Diez
10
10
  - Agustí B.R.
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-03-19 00:00:00.000000000 Z
14
+ date: 2021-04-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -182,14 +182,16 @@ files:
182
182
  - lib/decidim/bulletin_board/jwk_utils.rb
183
183
  - lib/decidim/bulletin_board/message_identifier.rb
184
184
  - lib/decidim/bulletin_board/settings.rb
185
+ - lib/decidim/bulletin_board/test/reset_test_database.rb
185
186
  - lib/decidim/bulletin_board/version.rb
186
187
  - lib/decidim/bulletin_board/voter/cast_vote.rb
187
188
  - lib/decidim/bulletin_board/voter/get_pending_message_status.rb
189
+ - lib/decidim/bulletin_board/voter/in_person_vote.rb
188
190
  homepage: https://github.com/decidim/decidim-bulletin-board
189
191
  licenses:
190
192
  - AGPL-3.0
191
193
  metadata: {}
192
- post_install_message:
194
+ post_install_message:
193
195
  rdoc_options: []
194
196
  require_paths:
195
197
  - lib
@@ -205,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  version: '0'
206
208
  requirements: []
207
209
  rubygems_version: 3.0.3
208
- signing_key:
210
+ signing_key:
209
211
  specification_version: 4
210
212
  summary: ''
211
213
  test_files: []