decidim-bulletin_board 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3d1e27c207aed87322d6be72c10f4cdec8abcad317b1b0f500911d1a1a2db6e
4
- data.tar.gz: d60a4887bb883c3f4da0f0100cf1b8e19e37bf14c26326288c5d4b63ff417f1e
3
+ metadata.gz: 280da5476565894dccc6cd9e234afb36eec03ed270bc480a9181717b03c66f21
4
+ data.tar.gz: c663840afcfb2af5a2f4adb26ae2e7539be4692f0de5d6a5c1c23fe1db07ae0a
5
5
  SHA512:
6
- metadata.gz: c69fc5b2a6a410969c72936d030bf8d87184b1a52d2145da348d4b5288cabf51df7edd877317f42555781481b0fe7107da3df89033ef53915dc4ec38db9f2977
7
- data.tar.gz: 83383e33224e36288e9d25d645a71624375274104a80e59eb1b082ad7cfcd679c283fadcb8d4ab0e6f973821a161006d837c92f73817bf0ab900fa90cef1744d
6
+ metadata.gz: ed1164634c2d02d1481455df14bb005f2cbedf01472eef6494d87aa6dd0df72d840949c4a2e7551316936653f7ac72c127e3f3090dc378ac1924544c21edc83c
7
+ data.tar.gz: c852e90c7c682e7fcc1799002956e76c1f5cc4a3958fc90bac9760884ce999a4c0b19d1d819217df23d1b8dcaa6c063e5657d95eb7f7505120e3d7284c9e5bce
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.0] - 2020-12-10
11
+
12
+ ### Added
13
+
14
+ - `Decidim::BulletinBoard::Authority` namespace that includes commands and forms to get the status of an election.
15
+
16
+ ### Changed
17
+
18
+ - `Decidim::BulletinBoard::Client` now includes a `get_status` method to get the election status using the `Authority` namespace.
19
+
20
+ ### Fixed
21
+
22
+ - `Decidim::BulletinBoard::Voter::CastVote` command uses the `encrypted_vote` as a `String` and not as a `Hash`.
23
+
24
+ ## [0.2.0] - 2020-12-08
25
+
26
+ ### Added
27
+
28
+ - `Decidim::BulletinBoard::Voter` namespace that includes commands and forms to perform the cast vote action.
29
+
30
+ ### Changed
31
+
32
+ - `Decidim::BulletinBoard::Client` now includes a `cast_vote` method to cast a vote using the `Voter` namespace.
33
+
34
+ ## [0.1.0] - 2020-12-07
35
+
36
+ ### Added
37
+
38
+ - `Decidim::BulletinBoard::Client` class totally configurable using `ActiveSupport::Configurable`
39
+ - The client now includes a `setup_election` method that creates the election in the bulletin board.
40
+
41
+ [unreleased]: https://github.com/decidim/decidim-bulletin-board/compare/v0.3.0...HEAD
42
+ [0.3.0]: https://github.com/decidim/decidim-bulletin-board/compare/v0.2.0...v0.3.0
43
+ [0.2.0]: https://github.com/decidim/decidim-bulletin-board/compare/v0.1.0...v0.2.0
44
+ [0.1.0]: https://github.com/decidim/decidim-bulletin-board/releases/tag/v0.1.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decidim-bulletin_board (0.2.0)
4
+ decidim-bulletin_board (0.3.0)
5
5
  activemodel (~> 5.0, >= 5.0.0.1)
6
6
  activesupport (~> 5.0, >= 5.0.0.1)
7
7
  byebug (~> 11.0)
@@ -9,6 +9,7 @@ require "decidim/bulletin_board/client"
9
9
  require "decidim/bulletin_board/graphql/client"
10
10
  require "decidim/bulletin_board/create_election"
11
11
  require "decidim/bulletin_board/voter"
12
+ require "decidim/bulletin_board/authority/get_election_status"
12
13
  require "active_support/configurable"
13
14
  require "jwt"
14
15
 
@@ -0,0 +1,52 @@
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 status of the election.
7
+ class GetElectionStatus
8
+ include Wisper::Publisher
9
+ # Public: Initializes the command.
10
+ #
11
+ # election - The election to receive the status from.
12
+ def initialize(election_id)
13
+ @election_id = election_id
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid and the query operation is successful.
19
+ # - :error if query operation was not successful.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ args = {
24
+ unique_id: election_id
25
+ }
26
+
27
+ begin
28
+ response = client.query do
29
+ query do
30
+ election(uniqueId: args[:unique_id]) do
31
+ status
32
+ end
33
+ end
34
+ end
35
+
36
+ broadcast(:ok, response.data.election.status)
37
+ rescue Graphlient::Errors::ServerError
38
+ broadcast(:error, "Sorry, something went wrong")
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :election_id
45
+
46
+ def client
47
+ @client ||= BulletinBoard::Graphql::Client.client
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -51,6 +51,14 @@ module Decidim
51
51
  cast_vote.call
52
52
  end
53
53
 
54
+ def get_status(election_id)
55
+ unique_election_id = "#{authority_slug}.#{election_id}"
56
+ get_status = Decidim::BulletinBoard::Authority::GetElectionStatus.new(unique_election_id)
57
+ get_status.on(:ok) { |status| return status }
58
+ get_status.on(:error) { |error_message| raise StandardError, error_message }
59
+ get_status.call
60
+ end
61
+
54
62
  private
55
63
 
56
64
  attr_reader :identification_private_key, :private_key
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module BulletinBoard
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -29,9 +29,9 @@ module Decidim
29
29
  @message_id ||= "#{election_id}.vote.cast+v.#{voter_id}"
30
30
  end
31
31
 
32
- # Public: uses the bulletin board client to sign the encrypted vote merged with the `message_id`.
32
+ # Public: uses the bulletin board client to sign the encrypted vote merged with the metadata
33
33
  def signed_data
34
- @signed_data ||= bulletin_board_client.sign_data(encrypted_vote.merge(message_id: message_id))
34
+ @signed_data ||= bulletin_board_client.sign_data(message)
35
35
  end
36
36
 
37
37
  private
@@ -57,6 +57,14 @@ module Decidim
57
57
 
58
58
  voter_data[:voter_id]
59
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
60
68
  end
61
69
  end
62
70
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Morcillo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-08 00:00:00.000000000 Z
12
+ date: 2020-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -176,6 +176,7 @@ files:
176
176
  - ".rubocop.yml"
177
177
  - ".ruby-version"
178
178
  - ".travis.yml"
179
+ - CHANGELOG.md
179
180
  - CODE_OF_CONDUCT.md
180
181
  - Gemfile
181
182
  - Gemfile.lock
@@ -185,6 +186,7 @@ files:
185
186
  - bin/setup
186
187
  - decidim-bulletin_board.gemspec
187
188
  - lib/decidim/bulletin_board.rb
189
+ - lib/decidim/bulletin_board/authority/get_election_status.rb
188
190
  - lib/decidim/bulletin_board/client.rb
189
191
  - lib/decidim/bulletin_board/create_election.rb
190
192
  - lib/decidim/bulletin_board/graphql/client.rb