decidim-bulletin_board 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,31 +34,31 @@ 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
49
- end
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
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
56
49
  end
57
50
 
58
- def cast_vote_message_id(election_id, voter_id)
59
- Decidim::BulletinBoard::Voter::CastVote.cast_vote_message_id(election_id, voter_id)
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
60
57
  end
61
58
 
62
59
  def cast_vote(election_id, voter_id, encrypted_vote)
63
60
  cast_vote = Decidim::BulletinBoard::Voter::CastVote.new(election_id, voter_id, encrypted_vote)
61
+ yield cast_vote.message_id if block_given?
64
62
  cast_vote.on(:ok) { |pending_message| return pending_message }
65
63
  cast_vote.on(:error) { |error_message| raise StandardError, error_message }
66
64
  cast_vote.call
@@ -73,6 +71,14 @@ module Decidim
73
71
  get_pending_message_status.call
74
72
  end
75
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
+
76
82
  def get_election_status(election_id)
77
83
  get_election_status = Decidim::BulletinBoard::Authority::GetElectionStatus.new(election_id)
78
84
  get_election_status.on(:ok) { |status| return status }
@@ -82,6 +88,7 @@ module Decidim
82
88
 
83
89
  def start_tally(election_id)
84
90
  start_tally = Decidim::BulletinBoard::Authority::StartTally.new(election_id)
91
+ yield start_tally.message_id if block_given?
85
92
  start_tally.on(:ok) { |pending_message| return pending_message }
86
93
  start_tally.on(:error) { |error_message| raise StandardError, error_message }
87
94
  start_tally.call
@@ -89,6 +96,7 @@ module Decidim
89
96
 
90
97
  def publish_results(election_id)
91
98
  publish_results = Decidim::BulletinBoard::Authority::PublishResults.new(election_id)
99
+ yield publish_results.message_id if block_given?
92
100
  publish_results.on(:ok) { |status| return status }
93
101
  publish_results.on(:error) { |error_message| raise StandardError, error_message }
94
102
  publish_results.call
@@ -8,7 +8,7 @@ module Decidim
8
8
  class Command
9
9
  include Wisper::Publisher
10
10
 
11
- delegate :authority_slug, :private_key, :unique_election_id, :message_id, to: :class
11
+ delegate :authority_slug, :private_key, :unique_election_id, :build_message_id, to: :class
12
12
 
13
13
  def sign_message(message_id, message)
14
14
  JWT.encode(complete_message(message_id, message), private_key.keypair, "RS256")
@@ -42,7 +42,7 @@ module Decidim
42
42
  Decidim::BulletinBoard::MessageIdentifier.unique_election_id(authority_slug, election_id)
43
43
  end
44
44
 
45
- def message_id(unique_election_id, type_subtype, voter_id = nil)
45
+ def build_message_id(unique_election_id, type_subtype, voter_id = nil)
46
46
  Decidim::BulletinBoard::MessageIdentifier.format(unique_election_id, type_subtype, voter_id ? :voter : :authority, voter_id || authority_slug)
47
47
  end
48
48
  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",
@@ -342,6 +301,47 @@
342
301
  "enumValues": null,
343
302
  "possibleTypes": null
344
303
  },
304
+ {
305
+ "kind": "OBJECT",
306
+ "name": "EndVoteMutationPayload",
307
+ "description": "Autogenerated return type of EndVoteMutation",
308
+ "fields": [
309
+ {
310
+ "name": "error",
311
+ "description": null,
312
+ "args": [
313
+
314
+ ],
315
+ "type": {
316
+ "kind": "SCALAR",
317
+ "name": "String",
318
+ "ofType": null
319
+ },
320
+ "isDeprecated": false,
321
+ "deprecationReason": null
322
+ },
323
+ {
324
+ "name": "pendingMessage",
325
+ "description": null,
326
+ "args": [
327
+
328
+ ],
329
+ "type": {
330
+ "kind": "OBJECT",
331
+ "name": "PendingMessage",
332
+ "ofType": null
333
+ },
334
+ "isDeprecated": false,
335
+ "deprecationReason": null
336
+ }
337
+ ],
338
+ "inputFields": null,
339
+ "interfaces": [
340
+
341
+ ],
342
+ "enumValues": null,
343
+ "possibleTypes": null
344
+ },
345
345
  {
346
346
  "kind": "SCALAR",
347
347
  "name": "ID",
@@ -611,7 +611,7 @@
611
611
  "description": null,
612
612
  "fields": [
613
613
  {
614
- "name": "closeBallotBox",
614
+ "name": "createElection",
615
615
  "description": null,
616
616
  "args": [
617
617
  {
@@ -645,14 +645,14 @@
645
645
  ],
646
646
  "type": {
647
647
  "kind": "OBJECT",
648
- "name": "CloseBallotBoxMutationPayload",
648
+ "name": "CreateElectionMutationPayload",
649
649
  "ofType": null
650
650
  },
651
651
  "isDeprecated": false,
652
652
  "deprecationReason": null
653
653
  },
654
654
  {
655
- "name": "createElection",
655
+ "name": "endVote",
656
656
  "description": null,
657
657
  "args": [
658
658
  {
@@ -686,14 +686,14 @@
686
686
  ],
687
687
  "type": {
688
688
  "kind": "OBJECT",
689
- "name": "CreateElectionMutationPayload",
689
+ "name": "EndVoteMutationPayload",
690
690
  "ofType": null
691
691
  },
692
692
  "isDeprecated": false,
693
693
  "deprecationReason": null
694
694
  },
695
695
  {
696
- "name": "openBallotBox",
696
+ "name": "processKeyCeremonyStep",
697
697
  "description": null,
698
698
  "args": [
699
699
  {
@@ -727,14 +727,14 @@
727
727
  ],
728
728
  "type": {
729
729
  "kind": "OBJECT",
730
- "name": "OpenBallotBoxMutationPayload",
730
+ "name": "ProcessKeyCeremonyStepMutationPayload",
731
731
  "ofType": null
732
732
  },
733
733
  "isDeprecated": false,
734
734
  "deprecationReason": null
735
735
  },
736
736
  {
737
- "name": "processKeyCeremonyStep",
737
+ "name": "processTallyStep",
738
738
  "description": null,
739
739
  "args": [
740
740
  {
@@ -768,14 +768,14 @@
768
768
  ],
769
769
  "type": {
770
770
  "kind": "OBJECT",
771
- "name": "ProcessKeyCeremonyStepMutationPayload",
771
+ "name": "ProcessTallyStepMutationPayload",
772
772
  "ofType": null
773
773
  },
774
774
  "isDeprecated": false,
775
775
  "deprecationReason": null
776
776
  },
777
777
  {
778
- "name": "processTallyStep",
778
+ "name": "publishResults",
779
779
  "description": null,
780
780
  "args": [
781
781
  {
@@ -809,14 +809,14 @@
809
809
  ],
810
810
  "type": {
811
811
  "kind": "OBJECT",
812
- "name": "ProcessTallyStepMutationPayload",
812
+ "name": "PublishResultsMutationPayload",
813
813
  "ofType": null
814
814
  },
815
815
  "isDeprecated": false,
816
816
  "deprecationReason": null
817
817
  },
818
818
  {
819
- "name": "publishResults",
819
+ "name": "startKeyCeremony",
820
820
  "description": null,
821
821
  "args": [
822
822
  {
@@ -850,7 +850,7 @@
850
850
  ],
851
851
  "type": {
852
852
  "kind": "OBJECT",
853
- "name": "PublishResultsMutationPayload",
853
+ "name": "StartKeyCeremonyMutationPayload",
854
854
  "ofType": null
855
855
  },
856
856
  "isDeprecated": false,
@@ -898,7 +898,7 @@
898
898
  "deprecationReason": null
899
899
  },
900
900
  {
901
- "name": "vote",
901
+ "name": "startVote",
902
902
  "description": null,
903
903
  "args": [
904
904
  {
@@ -932,48 +932,48 @@
932
932
  ],
933
933
  "type": {
934
934
  "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",
935
+ "name": "StartVoteMutationPayload",
963
936
  "ofType": null
964
937
  },
965
938
  "isDeprecated": false,
966
939
  "deprecationReason": null
967
940
  },
968
941
  {
969
- "name": "error",
942
+ "name": "vote",
970
943
  "description": null,
971
944
  "args": [
972
-
945
+ {
946
+ "name": "messageId",
947
+ "description": null,
948
+ "type": {
949
+ "kind": "NON_NULL",
950
+ "name": null,
951
+ "ofType": {
952
+ "kind": "SCALAR",
953
+ "name": "String",
954
+ "ofType": null
955
+ }
956
+ },
957
+ "defaultValue": null
958
+ },
959
+ {
960
+ "name": "signedData",
961
+ "description": null,
962
+ "type": {
963
+ "kind": "NON_NULL",
964
+ "name": null,
965
+ "ofType": {
966
+ "kind": "SCALAR",
967
+ "name": "String",
968
+ "ofType": null
969
+ }
970
+ },
971
+ "defaultValue": null
972
+ }
973
973
  ],
974
974
  "type": {
975
- "kind": "SCALAR",
976
- "name": "String",
975
+ "kind": "OBJECT",
976
+ "name": "VoteMutationPayload",
977
977
  "ofType": null
978
978
  },
979
979
  "isDeprecated": false,
@@ -1415,6 +1415,47 @@
1415
1415
  "enumValues": null,
1416
1416
  "possibleTypes": null
1417
1417
  },
1418
+ {
1419
+ "kind": "OBJECT",
1420
+ "name": "StartKeyCeremonyMutationPayload",
1421
+ "description": "Autogenerated return type of StartKeyCeremonyMutation",
1422
+ "fields": [
1423
+ {
1424
+ "name": "error",
1425
+ "description": null,
1426
+ "args": [
1427
+
1428
+ ],
1429
+ "type": {
1430
+ "kind": "SCALAR",
1431
+ "name": "String",
1432
+ "ofType": null
1433
+ },
1434
+ "isDeprecated": false,
1435
+ "deprecationReason": null
1436
+ },
1437
+ {
1438
+ "name": "pendingMessage",
1439
+ "description": null,
1440
+ "args": [
1441
+
1442
+ ],
1443
+ "type": {
1444
+ "kind": "OBJECT",
1445
+ "name": "PendingMessage",
1446
+ "ofType": null
1447
+ },
1448
+ "isDeprecated": false,
1449
+ "deprecationReason": null
1450
+ }
1451
+ ],
1452
+ "inputFields": null,
1453
+ "interfaces": [
1454
+
1455
+ ],
1456
+ "enumValues": null,
1457
+ "possibleTypes": null
1458
+ },
1418
1459
  {
1419
1460
  "kind": "OBJECT",
1420
1461
  "name": "StartTallyMutationPayload",
@@ -1456,6 +1497,47 @@
1456
1497
  "enumValues": null,
1457
1498
  "possibleTypes": null
1458
1499
  },
1500
+ {
1501
+ "kind": "OBJECT",
1502
+ "name": "StartVoteMutationPayload",
1503
+ "description": "Autogenerated return type of StartVoteMutation",
1504
+ "fields": [
1505
+ {
1506
+ "name": "error",
1507
+ "description": null,
1508
+ "args": [
1509
+
1510
+ ],
1511
+ "type": {
1512
+ "kind": "SCALAR",
1513
+ "name": "String",
1514
+ "ofType": null
1515
+ },
1516
+ "isDeprecated": false,
1517
+ "deprecationReason": null
1518
+ },
1519
+ {
1520
+ "name": "pendingMessage",
1521
+ "description": null,
1522
+ "args": [
1523
+
1524
+ ],
1525
+ "type": {
1526
+ "kind": "OBJECT",
1527
+ "name": "PendingMessage",
1528
+ "ofType": null
1529
+ },
1530
+ "isDeprecated": false,
1531
+ "deprecationReason": null
1532
+ }
1533
+ ],
1534
+ "inputFields": null,
1535
+ "interfaces": [
1536
+
1537
+ ],
1538
+ "enumValues": null,
1539
+ "possibleTypes": null
1540
+ },
1459
1541
  {
1460
1542
  "kind": "SCALAR",
1461
1543
  "name": "String",