decidim-bulletin_board 0.7.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,11 @@ module Decidim
12
12
  @election_id = election_id
13
13
  end
14
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
+
15
20
  # Executes the command. Broadcasts these events:
16
21
  #
17
22
  # - :ok when everything is valid and the query operation is successful.
@@ -19,27 +24,28 @@ module Decidim
19
24
  #
20
25
  # Returns nothing.
21
26
  def call
22
- message_id = message_id(unique_election_id(election_id), "start_tally")
23
- signed_data = sign_message(message_id, {})
24
-
25
- begin
26
- response = client.query do
27
- mutation do
28
- startTally(messageId: message_id, signedData: signed_data) do
29
- pendingMessage do
30
- status
31
- end
32
- error
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
33
38
  end
39
+ error
34
40
  end
35
41
  end
42
+ end
36
43
 
37
- return broadcast(:error, response.data.start_tally.error) if response.data.start_tally.error.present?
44
+ return broadcast(:error, response.data.start_tally.error) if response.data.start_tally.error.present?
38
45
 
39
- broadcast(:ok, response.data.start_tally.pending_message)
40
- rescue Graphlient::Errors::ServerError
41
- broadcast(:error, "Sorry, something went wrong")
42
- end
46
+ broadcast(:ok, response.data.start_tally.pending_message)
47
+ rescue Graphlient::Errors::ServerError
48
+ broadcast(:error, "Sorry, something went wrong")
43
49
  end
44
50
 
45
51
  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 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
- return 0 if @scheme.dig(:parameters, :quorum).blank?
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,48 +34,76 @@ 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 open_ballot_box(election_id)
45
- open_ballot_box = Decidim::BulletinBoard::Authority::OpenBallotBox.new(election_id)
46
- open_ballot_box.on(:ok) { |election| return election }
47
- open_ballot_box.on(:error) { |error_message| raise StandardError, error_message }
48
- open_ballot_box.call
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 close_ballot_box(election_id)
52
- close_ballot_box = Decidim::BulletinBoard::Authority::CloseBallotBox.new(election_id)
53
- close_ballot_box.on(:ok) { |election| return election }
54
- close_ballot_box.on(:error) { |error_message| raise StandardError, error_message }
55
- close_ballot_box.call
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 get_status(election_id)
66
- get_status = Decidim::BulletinBoard::Authority::GetElectionStatus.new(election_id)
67
- get_status.on(:ok) { |status| return status }
68
- get_status.on(:error) { |error_message| raise StandardError, error_message }
69
- get_status.call
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
70
87
  end
71
88
 
72
89
  def start_tally(election_id)
73
90
  start_tally = Decidim::BulletinBoard::Authority::StartTally.new(election_id)
91
+ yield start_tally.message_id if block_given?
74
92
  start_tally.on(:ok) { |pending_message| return pending_message }
75
93
  start_tally.on(:error) { |error_message| raise StandardError, error_message }
76
94
  start_tally.call
77
95
  end
78
96
 
97
+ def get_election_log_entries_by_types(election_id, types)
98
+ get_log_entries = Decidim::BulletinBoard::Authority::GetElectionLogEntriesByTypes.new(election_id, types)
99
+ get_log_entries.on(:ok) { |log_entries| return log_entries }
100
+ get_log_entries.on(:error) { |error_message| raise StandardError, error_message }
101
+ get_log_entries.call
102
+ end
103
+
79
104
  def publish_results(election_id)
80
105
  publish_results = Decidim::BulletinBoard::Authority::PublishResults.new(election_id)
106
+ yield publish_results.message_id if block_given?
81
107
  publish_results.on(:ok) { |status| return status }
82
108
  publish_results.on(:error) { |error_message| raise StandardError, error_message }
83
109
  publish_results.call
@@ -8,15 +8,7 @@ module Decidim
8
8
  class Command
9
9
  include Wisper::Publisher
10
10
 
11
- delegate :authority_slug, :private_key, to: :class
12
-
13
- def unique_election_id(election_id)
14
- Decidim::BulletinBoard::MessageIdentifier.unique_election_id(authority_slug, election_id)
15
- end
16
-
17
- def message_id(unique_election_id, type_subtype, voter_id = nil)
18
- Decidim::BulletinBoard::MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || authority_slug)
19
- end
11
+ delegate :authority_slug, :private_key, :unique_election_id, :build_message_id, to: :class
20
12
 
21
13
  def sign_message(message_id, message)
22
14
  JWT.encode(complete_message(message_id, message), private_key.keypair, "RS256")
@@ -45,6 +37,14 @@ module Decidim
45
37
  def authority_slug
46
38
  @authority_slug ||= BulletinBoard.authority_name.parameterize
47
39
  end
40
+
41
+ def unique_election_id(election_id)
42
+ Decidim::BulletinBoard::MessageIdentifier.unique_election_id(authority_slug, election_id)
43
+ end
44
+
45
+ def build_message_id(unique_election_id, type_subtype, voter_id = nil)
46
+ Decidim::BulletinBoard::MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || authority_slug)
47
+ end
48
48
  end
49
49
  end
50
50
  end
@@ -114,47 +114,6 @@
114
114
  "enumValues": null,
115
115
  "possibleTypes": null
116
116
  },
117
- {
118
- "kind": "OBJECT",
119
- "name": "CloseBallotBoxMutationPayload",
120
- "description": "Autogenerated return type of CloseBallotBoxMutation",
121
- "fields": [
122
- {
123
- "name": "election",
124
- "description": null,
125
- "args": [
126
-
127
- ],
128
- "type": {
129
- "kind": "OBJECT",
130
- "name": "Election",
131
- "ofType": null
132
- },
133
- "isDeprecated": false,
134
- "deprecationReason": null
135
- },
136
- {
137
- "name": "error",
138
- "description": null,
139
- "args": [
140
-
141
- ],
142
- "type": {
143
- "kind": "SCALAR",
144
- "name": "String",
145
- "ofType": null
146
- },
147
- "isDeprecated": false,
148
- "deprecationReason": null
149
- }
150
- ],
151
- "inputFields": null,
152
- "interfaces": [
153
-
154
- ],
155
- "enumValues": null,
156
- "possibleTypes": null
157
- },
158
117
  {
159
118
  "kind": "OBJECT",
160
119
  "name": "CreateElectionMutationPayload",
@@ -250,6 +209,24 @@
250
209
  "ofType": null
251
210
  },
252
211
  "defaultValue": null
212
+ },
213
+ {
214
+ "name": "types",
215
+ "description": null,
216
+ "type": {
217
+ "kind": "LIST",
218
+ "name": null,
219
+ "ofType": {
220
+ "kind": "NON_NULL",
221
+ "name": null,
222
+ "ofType": {
223
+ "kind": "SCALAR",
224
+ "name": "String",
225
+ "ofType": null
226
+ }
227
+ }
228
+ },
229
+ "defaultValue": null
253
230
  }
254
231
  ],
255
232
  "type": {
@@ -342,6 +319,47 @@
342
319
  "enumValues": null,
343
320
  "possibleTypes": null
344
321
  },
322
+ {
323
+ "kind": "OBJECT",
324
+ "name": "EndVoteMutationPayload",
325
+ "description": "Autogenerated return type of EndVoteMutation",
326
+ "fields": [
327
+ {
328
+ "name": "error",
329
+ "description": null,
330
+ "args": [
331
+
332
+ ],
333
+ "type": {
334
+ "kind": "SCALAR",
335
+ "name": "String",
336
+ "ofType": null
337
+ },
338
+ "isDeprecated": false,
339
+ "deprecationReason": null
340
+ },
341
+ {
342
+ "name": "pendingMessage",
343
+ "description": null,
344
+ "args": [
345
+
346
+ ],
347
+ "type": {
348
+ "kind": "OBJECT",
349
+ "name": "PendingMessage",
350
+ "ofType": null
351
+ },
352
+ "isDeprecated": false,
353
+ "deprecationReason": null
354
+ }
355
+ ],
356
+ "inputFields": null,
357
+ "interfaces": [
358
+
359
+ ],
360
+ "enumValues": null,
361
+ "possibleTypes": null
362
+ },
345
363
  {
346
364
  "kind": "SCALAR",
347
365
  "name": "ID",
@@ -611,7 +629,7 @@
611
629
  "description": null,
612
630
  "fields": [
613
631
  {
614
- "name": "closeBallotBox",
632
+ "name": "createElection",
615
633
  "description": null,
616
634
  "args": [
617
635
  {
@@ -645,14 +663,14 @@
645
663
  ],
646
664
  "type": {
647
665
  "kind": "OBJECT",
648
- "name": "CloseBallotBoxMutationPayload",
666
+ "name": "CreateElectionMutationPayload",
649
667
  "ofType": null
650
668
  },
651
669
  "isDeprecated": false,
652
670
  "deprecationReason": null
653
671
  },
654
672
  {
655
- "name": "createElection",
673
+ "name": "endVote",
656
674
  "description": null,
657
675
  "args": [
658
676
  {
@@ -686,14 +704,14 @@
686
704
  ],
687
705
  "type": {
688
706
  "kind": "OBJECT",
689
- "name": "CreateElectionMutationPayload",
707
+ "name": "EndVoteMutationPayload",
690
708
  "ofType": null
691
709
  },
692
710
  "isDeprecated": false,
693
711
  "deprecationReason": null
694
712
  },
695
713
  {
696
- "name": "openBallotBox",
714
+ "name": "processKeyCeremonyStep",
697
715
  "description": null,
698
716
  "args": [
699
717
  {
@@ -727,14 +745,14 @@
727
745
  ],
728
746
  "type": {
729
747
  "kind": "OBJECT",
730
- "name": "OpenBallotBoxMutationPayload",
748
+ "name": "ProcessKeyCeremonyStepMutationPayload",
731
749
  "ofType": null
732
750
  },
733
751
  "isDeprecated": false,
734
752
  "deprecationReason": null
735
753
  },
736
754
  {
737
- "name": "processKeyCeremonyStep",
755
+ "name": "processTallyStep",
738
756
  "description": null,
739
757
  "args": [
740
758
  {
@@ -768,14 +786,14 @@
768
786
  ],
769
787
  "type": {
770
788
  "kind": "OBJECT",
771
- "name": "ProcessKeyCeremonyStepMutationPayload",
789
+ "name": "ProcessTallyStepMutationPayload",
772
790
  "ofType": null
773
791
  },
774
792
  "isDeprecated": false,
775
793
  "deprecationReason": null
776
794
  },
777
795
  {
778
- "name": "processTallyStep",
796
+ "name": "publishResults",
779
797
  "description": null,
780
798
  "args": [
781
799
  {
@@ -809,14 +827,14 @@
809
827
  ],
810
828
  "type": {
811
829
  "kind": "OBJECT",
812
- "name": "ProcessTallyStepMutationPayload",
830
+ "name": "PublishResultsMutationPayload",
813
831
  "ofType": null
814
832
  },
815
833
  "isDeprecated": false,
816
834
  "deprecationReason": null
817
835
  },
818
836
  {
819
- "name": "publishResults",
837
+ "name": "startKeyCeremony",
820
838
  "description": null,
821
839
  "args": [
822
840
  {
@@ -850,7 +868,7 @@
850
868
  ],
851
869
  "type": {
852
870
  "kind": "OBJECT",
853
- "name": "PublishResultsMutationPayload",
871
+ "name": "StartKeyCeremonyMutationPayload",
854
872
  "ofType": null
855
873
  },
856
874
  "isDeprecated": false,
@@ -898,7 +916,7 @@
898
916
  "deprecationReason": null
899
917
  },
900
918
  {
901
- "name": "vote",
919
+ "name": "startVote",
902
920
  "description": null,
903
921
  "args": [
904
922
  {
@@ -932,48 +950,48 @@
932
950
  ],
933
951
  "type": {
934
952
  "kind": "OBJECT",
935
- "name": "VoteMutationPayload",
936
- "ofType": null
937
- },
938
- "isDeprecated": false,
939
- "deprecationReason": null
940
- }
941
- ],
942
- "inputFields": null,
943
- "interfaces": [
944
-
945
- ],
946
- "enumValues": null,
947
- "possibleTypes": null
948
- },
949
- {
950
- "kind": "OBJECT",
951
- "name": "OpenBallotBoxMutationPayload",
952
- "description": "Autogenerated return type of OpenBallotBoxMutation",
953
- "fields": [
954
- {
955
- "name": "election",
956
- "description": null,
957
- "args": [
958
-
959
- ],
960
- "type": {
961
- "kind": "OBJECT",
962
- "name": "Election",
953
+ "name": "StartVoteMutationPayload",
963
954
  "ofType": null
964
955
  },
965
956
  "isDeprecated": false,
966
957
  "deprecationReason": null
967
958
  },
968
959
  {
969
- "name": "error",
960
+ "name": "vote",
970
961
  "description": null,
971
962
  "args": [
972
-
963
+ {
964
+ "name": "messageId",
965
+ "description": null,
966
+ "type": {
967
+ "kind": "NON_NULL",
968
+ "name": null,
969
+ "ofType": {
970
+ "kind": "SCALAR",
971
+ "name": "String",
972
+ "ofType": null
973
+ }
974
+ },
975
+ "defaultValue": null
976
+ },
977
+ {
978
+ "name": "signedData",
979
+ "description": null,
980
+ "type": {
981
+ "kind": "NON_NULL",
982
+ "name": null,
983
+ "ofType": {
984
+ "kind": "SCALAR",
985
+ "name": "String",
986
+ "ofType": null
987
+ }
988
+ },
989
+ "defaultValue": null
990
+ }
973
991
  ],
974
992
  "type": {
975
- "kind": "SCALAR",
976
- "name": "String",
993
+ "kind": "OBJECT",
994
+ "name": "VoteMutationPayload",
977
995
  "ofType": null
978
996
  },
979
997
  "isDeprecated": false,
@@ -1382,13 +1400,19 @@
1382
1400
  "name": "id",
1383
1401
  "description": null,
1384
1402
  "type": {
1385
- "kind": "NON_NULL",
1386
- "name": null,
1387
- "ofType": {
1388
- "kind": "SCALAR",
1389
- "name": "ID",
1390
- "ofType": null
1391
- }
1403
+ "kind": "SCALAR",
1404
+ "name": "ID",
1405
+ "ofType": null
1406
+ },
1407
+ "defaultValue": null
1408
+ },
1409
+ {
1410
+ "name": "messageId",
1411
+ "description": null,
1412
+ "type": {
1413
+ "kind": "SCALAR",
1414
+ "name": "String",
1415
+ "ofType": null
1392
1416
  },
1393
1417
  "defaultValue": null
1394
1418
  }
@@ -1409,6 +1433,47 @@
1409
1433
  "enumValues": null,
1410
1434
  "possibleTypes": null
1411
1435
  },
1436
+ {
1437
+ "kind": "OBJECT",
1438
+ "name": "StartKeyCeremonyMutationPayload",
1439
+ "description": "Autogenerated return type of StartKeyCeremonyMutation",
1440
+ "fields": [
1441
+ {
1442
+ "name": "error",
1443
+ "description": null,
1444
+ "args": [
1445
+
1446
+ ],
1447
+ "type": {
1448
+ "kind": "SCALAR",
1449
+ "name": "String",
1450
+ "ofType": null
1451
+ },
1452
+ "isDeprecated": false,
1453
+ "deprecationReason": null
1454
+ },
1455
+ {
1456
+ "name": "pendingMessage",
1457
+ "description": null,
1458
+ "args": [
1459
+
1460
+ ],
1461
+ "type": {
1462
+ "kind": "OBJECT",
1463
+ "name": "PendingMessage",
1464
+ "ofType": null
1465
+ },
1466
+ "isDeprecated": false,
1467
+ "deprecationReason": null
1468
+ }
1469
+ ],
1470
+ "inputFields": null,
1471
+ "interfaces": [
1472
+
1473
+ ],
1474
+ "enumValues": null,
1475
+ "possibleTypes": null
1476
+ },
1412
1477
  {
1413
1478
  "kind": "OBJECT",
1414
1479
  "name": "StartTallyMutationPayload",
@@ -1450,6 +1515,47 @@
1450
1515
  "enumValues": null,
1451
1516
  "possibleTypes": null
1452
1517
  },
1518
+ {
1519
+ "kind": "OBJECT",
1520
+ "name": "StartVoteMutationPayload",
1521
+ "description": "Autogenerated return type of StartVoteMutation",
1522
+ "fields": [
1523
+ {
1524
+ "name": "error",
1525
+ "description": null,
1526
+ "args": [
1527
+
1528
+ ],
1529
+ "type": {
1530
+ "kind": "SCALAR",
1531
+ "name": "String",
1532
+ "ofType": null
1533
+ },
1534
+ "isDeprecated": false,
1535
+ "deprecationReason": null
1536
+ },
1537
+ {
1538
+ "name": "pendingMessage",
1539
+ "description": null,
1540
+ "args": [
1541
+
1542
+ ],
1543
+ "type": {
1544
+ "kind": "OBJECT",
1545
+ "name": "PendingMessage",
1546
+ "ofType": null
1547
+ },
1548
+ "isDeprecated": false,
1549
+ "deprecationReason": null
1550
+ }
1551
+ ],
1552
+ "inputFields": null,
1553
+ "interfaces": [
1554
+
1555
+ ],
1556
+ "enumValues": null,
1557
+ "possibleTypes": null
1558
+ },
1453
1559
  {
1454
1560
  "kind": "SCALAR",
1455
1561
  "name": "String",