decidim-elections 0.24.3 → 0.25.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (433) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/cells/decidim/elections/election_m/tags.erb +3 -0
  4. data/app/cells/decidim/elections/election_m_cell.rb +1 -8
  5. data/app/cells/decidim/elections/election_preview/show.erb +28 -0
  6. data/app/cells/decidim/elections/election_preview_cell.rb +13 -0
  7. data/app/cells/decidim/elections/election_results/blank_votes.erb +7 -0
  8. data/app/cells/decidim/elections/election_results/progress_bar.erb +16 -0
  9. data/app/cells/decidim/elections/election_results/show.erb +40 -0
  10. data/app/cells/decidim/elections/election_results_cell.rb +13 -0
  11. data/app/cells/decidim/elections/election_vote_cta/show.erb +35 -0
  12. data/app/cells/decidim/elections/election_vote_cta_cell.rb +83 -0
  13. data/app/cells/decidim/elections/remaining_time_callout/show.erb +5 -0
  14. data/app/cells/decidim/elections/remaining_time_callout_cell.rb +28 -0
  15. data/app/cells/decidim/elections/voting_step_navigation/show.erb +1 -1
  16. data/app/cells/decidim/elections/voting_step_navigation_cell.rb +1 -1
  17. data/app/cells/decidim/votings/content_blocks/highlighted_votings/show.erb +1 -1
  18. data/app/cells/decidim/votings/content_blocks/landing_page/attachments_and_folders_cell.rb +8 -1
  19. data/app/cells/decidim/votings/content_blocks/landing_page/description/show.erb +25 -0
  20. data/app/cells/decidim/votings/content_blocks/landing_page/description_cell.rb +20 -2
  21. data/app/cells/decidim/votings/content_blocks/landing_page/elections/show.erb +15 -0
  22. data/app/cells/decidim/votings/content_blocks/landing_page/elections/single.erb +11 -0
  23. data/app/cells/decidim/votings/content_blocks/landing_page/elections_cell.rb +33 -1
  24. data/app/cells/decidim/votings/content_blocks/landing_page/header/show.erb +29 -0
  25. data/app/cells/decidim/votings/content_blocks/landing_page/header_cell.rb +95 -2
  26. data/app/cells/decidim/votings/content_blocks/landing_page/header_settings_form/show.erb +4 -0
  27. data/app/cells/decidim/votings/content_blocks/landing_page/{stats_cell.rb → header_settings_form_cell.rb} +5 -3
  28. data/app/cells/decidim/votings/content_blocks/landing_page/metrics/show.erb +12 -0
  29. data/app/cells/decidim/votings/content_blocks/landing_page/metrics_cell.rb +6 -2
  30. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations/address.erb +14 -0
  31. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations/map.erb +18 -0
  32. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations/show.erb +25 -0
  33. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations_cell.rb +42 -1
  34. data/app/cells/decidim/votings/content_blocks/landing_page/statistics_cell.rb +24 -0
  35. data/app/cells/decidim/votings/content_blocks/landing_page/timeline/show.erb +7 -0
  36. data/app/cells/decidim/votings/content_blocks/landing_page/timeline_cell.rb +4 -2
  37. data/app/cells/decidim/votings/polling_officers/polling_officers_picker/show.erb +1 -1
  38. data/app/cells/decidim/votings/polling_station_closure_certificate/show.erb +9 -0
  39. data/app/cells/decidim/votings/polling_station_closure_certificate_cell.rb +12 -0
  40. data/app/cells/decidim/votings/polling_station_closure_recount/show.erb +74 -0
  41. data/app/cells/decidim/votings/polling_station_closure_recount_cell.rb +9 -0
  42. data/app/cells/decidim/votings/voting_m_cell.rb +2 -2
  43. data/app/commands/decidim/elections/admin/add_user_as_trustee.rb +2 -1
  44. data/app/commands/decidim/elections/admin/create_election.rb +2 -1
  45. data/app/commands/decidim/elections/admin/publish_results.rb +10 -6
  46. data/app/commands/decidim/elections/admin/setup_election.rb +73 -67
  47. data/app/commands/decidim/elections/admin/update_answer_selection.rb +1 -1
  48. data/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb +61 -2
  49. data/app/commands/decidim/elections/trustee_zone/update_trustee.rb +3 -0
  50. data/app/commands/decidim/elections/voter/cast_vote.rb +4 -7
  51. data/app/commands/decidim/elections/voter/update_vote_status.rb +23 -7
  52. data/app/commands/decidim/votings/admin/create_ballot_style.rb +58 -0
  53. data/app/commands/decidim/votings/admin/create_voting.rb +2 -1
  54. data/app/commands/decidim/votings/admin/destroy_ballot_style.rb +33 -0
  55. data/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb +37 -0
  56. data/app/commands/decidim/votings/admin/update_ballot_style.rb +70 -0
  57. data/app/commands/decidim/votings/admin/update_voting.rb +5 -14
  58. data/app/commands/decidim/votings/census/admin/create_dataset.rb +82 -0
  59. data/app/commands/decidim/votings/census/admin/create_datum.rb +55 -0
  60. data/app/commands/decidim/votings/census/admin/destroy_dataset.rb +45 -0
  61. data/app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb +43 -0
  62. data/app/commands/decidim/votings/census/admin/launch_access_codes_export.rb +38 -0
  63. data/app/commands/decidim/votings/census/admin/launch_access_codes_generation.rb +44 -0
  64. data/app/commands/decidim/votings/census/admin/update_dataset.rb +51 -0
  65. data/app/commands/decidim/votings/certify_polling_station_closure.rb +46 -0
  66. data/app/commands/decidim/votings/check_census.rb +35 -0
  67. data/app/commands/decidim/votings/create_polling_station_closure.rb +53 -0
  68. data/app/commands/decidim/votings/create_polling_station_results.rb +83 -0
  69. data/app/commands/decidim/votings/send_access_code.rb +48 -0
  70. data/app/commands/decidim/votings/sign_polling_station_closure.rb +41 -0
  71. data/app/commands/decidim/votings/voter/in_person_vote.rb +55 -0
  72. data/app/commands/decidim/votings/voter/update_in_person_vote_status.rb +52 -0
  73. data/app/controllers/concerns/decidim/elections/has_vote_flow.rb +43 -0
  74. data/app/controllers/concerns/decidim/monitoring_committee_polling_station_closures/admin/filterable.rb +72 -0
  75. data/app/controllers/concerns/decidim/votings/needs_voting.rb +5 -5
  76. data/app/controllers/decidim/elections/admin/steps_controller.rb +5 -2
  77. data/app/controllers/decidim/elections/elections_controller.rb +18 -5
  78. data/app/controllers/decidim/elections/feedbacks_controller.rb +37 -3
  79. data/app/controllers/decidim/elections/trustee_zone/elections_controller.rb +15 -1
  80. data/app/controllers/decidim/elections/votes_controller.rb +101 -41
  81. data/app/controllers/decidim/votings/admin/ballot_styles_controller.rb +93 -0
  82. data/app/controllers/decidim/votings/admin/monitoring_committee_election_results_controller.rb +69 -0
  83. data/app/controllers/decidim/votings/admin/monitoring_committee_members_controller.rb +4 -0
  84. data/app/controllers/decidim/votings/admin/monitoring_committee_polling_station_closures_controller.rb +73 -0
  85. data/app/controllers/decidim/votings/admin/monitoring_committee_verify_elections_controller.rb +24 -0
  86. data/app/controllers/decidim/votings/admin/polling_stations_controller.rb +4 -0
  87. data/app/controllers/decidim/votings/admin/votings_controller.rb +1 -1
  88. data/app/controllers/decidim/votings/census/admin/application_controller.rb +19 -0
  89. data/app/controllers/decidim/votings/census/admin/census_controller.rb +191 -0
  90. data/app/controllers/decidim/votings/polling_officer_zone/closures_controller.rb +131 -0
  91. data/app/controllers/decidim/votings/polling_officer_zone/in_person_votes_controller.rb +149 -0
  92. data/app/controllers/decidim/votings/polling_officer_zone/polling_officers_controller.rb +10 -2
  93. data/app/controllers/decidim/votings/votings_controller.rb +91 -4
  94. data/app/events/decidim/elections/votes/vote_accepted_event.rb +1 -1
  95. data/app/forms/decidim/elections/admin/action_form.rb +5 -0
  96. data/app/forms/decidim/elections/admin/question_form.rb +1 -1
  97. data/app/forms/decidim/elections/admin/trustees_participatory_space_form.rb +1 -1
  98. data/app/forms/decidim/elections/{ballot → voter}/verify_vote_form.rb +1 -5
  99. data/app/forms/decidim/elections/voter/vote_form.rb +50 -0
  100. data/app/forms/decidim/votings/admin/ballot_style_form.rb +19 -0
  101. data/app/forms/decidim/votings/admin/monitoring_committee_polling_station_closure_form.rb +11 -0
  102. data/app/forms/decidim/votings/admin/publish_results_form.rb +64 -0
  103. data/app/forms/decidim/votings/admin/voting_form.rb +3 -2
  104. data/app/forms/decidim/votings/answer_result_form.rb +24 -0
  105. data/app/forms/decidim/votings/ballot_result_form.rb +28 -0
  106. data/app/forms/decidim/votings/census/admin/dataset_form.rb +25 -0
  107. data/app/forms/decidim/votings/census/admin/datum_form.rb +30 -0
  108. data/app/forms/decidim/votings/census/check_fields.rb +28 -0
  109. data/app/forms/decidim/votings/census/check_form.rb +13 -0
  110. data/app/forms/decidim/votings/census/frontend_fields.rb +42 -0
  111. data/app/forms/decidim/votings/census/in_person_fields.rb +48 -0
  112. data/app/forms/decidim/votings/census/in_person_form.rb +13 -0
  113. data/app/forms/decidim/votings/census/login_form.rb +13 -0
  114. data/app/forms/decidim/votings/census/online_fields.rb +28 -0
  115. data/app/forms/decidim/votings/closure_certify_form.rb +20 -0
  116. data/app/forms/decidim/votings/closure_result_form.rb +37 -0
  117. data/app/forms/decidim/votings/closure_sign_form.rb +11 -0
  118. data/app/forms/decidim/votings/envelopes_result_form.rb +34 -0
  119. data/app/forms/decidim/votings/question_result_form.rb +24 -0
  120. data/app/forms/decidim/votings/voter/in_person_vote_form.rb +40 -0
  121. data/app/jobs/decidim/votings/census/admin/create_datum_job.rb +41 -0
  122. data/app/jobs/decidim/votings/census/admin/export_access_codes_job.rb +39 -0
  123. data/app/jobs/decidim/votings/census/admin/generate_access_codes_job.rb +44 -0
  124. data/app/mailers/decidim/elections/vote_accepted_mailer.rb +29 -0
  125. data/app/mailers/decidim/votings/access_code_mailer.rb +34 -0
  126. data/app/mailers/decidim/votings/census/export_mailer.rb +44 -0
  127. data/app/models/decidim/elections/action.rb +1 -1
  128. data/app/models/decidim/elections/answer.rb +21 -0
  129. data/app/models/decidim/elections/bulletin_board_closure.rb +19 -0
  130. data/app/models/decidim/elections/election.rb +5 -4
  131. data/app/models/decidim/elections/question.rb +24 -13
  132. data/app/models/decidim/elections/result.rb +22 -0
  133. data/app/models/decidim/elections/trustee.rb +10 -1
  134. data/app/models/decidim/elections/vote.rb +2 -2
  135. data/app/models/decidim/votings/ballot_style.rb +29 -0
  136. data/app/models/decidim/votings/ballot_style_question.rb +11 -0
  137. data/app/models/decidim/votings/census/dataset.rb +32 -0
  138. data/app/models/decidim/votings/census/datum.rb +34 -0
  139. data/app/models/decidim/votings/in_person_vote.rb +22 -0
  140. data/app/models/decidim/votings/polling_station.rb +18 -1
  141. data/app/models/decidim/votings/polling_station_closure.rb +43 -0
  142. data/app/models/decidim/votings/voting.rb +38 -15
  143. data/app/packs/entrypoints/decidim_elections.js +2 -0
  144. data/app/packs/entrypoints/decidim_elections_admin_pending_action.js +1 -0
  145. data/app/packs/entrypoints/decidim_elections_admin_vote_statistics.js +1 -0
  146. data/app/packs/entrypoints/decidim_elections_election_log.js +1 -0
  147. data/app/packs/entrypoints/decidim_elections_onboarding.js +1 -0
  148. data/app/packs/entrypoints/decidim_elections_trustee_key_ceremony.js +1 -0
  149. data/app/packs/entrypoints/decidim_elections_trustee_tally.js +1 -0
  150. data/app/packs/entrypoints/decidim_elections_trustee_trustee_zone.js +1 -0
  151. data/app/packs/entrypoints/decidim_elections_trustee_zone.js +1 -0
  152. data/app/packs/entrypoints/decidim_elections_trustee_zone.scss +1 -0
  153. data/app/packs/entrypoints/decidim_elections_voter_casting-vote.js +1 -0
  154. data/app/packs/entrypoints/decidim_elections_voter_new-vote.js +1 -0
  155. data/app/packs/entrypoints/decidim_elections_voter_setup-preview.js +1 -0
  156. data/app/packs/entrypoints/decidim_elections_voter_setup-vote.js +1 -0
  157. data/app/packs/entrypoints/decidim_elections_voter_verify-vote.js +1 -0
  158. data/app/packs/entrypoints/decidim_votings_admin_monitoring_committee_members_form.js +1 -0
  159. data/app/packs/entrypoints/decidim_votings_admin_polling_officers_form.js +1 -0
  160. data/app/packs/entrypoints/decidim_votings_admin_polling_officers_picker.js +1 -0
  161. data/app/packs/entrypoints/decidim_votings_admin_polling_stations_form.js +1 -0
  162. data/app/packs/entrypoints/decidim_votings_admin_update_census_dataset_status.js +1 -0
  163. data/app/packs/entrypoints/decidim_votings_admin_votings.js +1 -0
  164. data/app/packs/entrypoints/decidim_votings_admin_votings.scss +1 -0
  165. data/app/packs/entrypoints/decidim_votings_in-person-vote.js +1 -0
  166. data/app/packs/entrypoints/decidim_votings_voting-description-cell.js +1 -0
  167. data/app/packs/entrypoints/decidim_votings_voting_polling_officer_zone-edit-closure.js +1 -0
  168. data/app/packs/entrypoints/decidim_votings_voting_polling_officer_zone-in-person-vote.js +1 -0
  169. data/app/packs/entrypoints/decidim_votings_voting_polling_officer_zone-new-closure.js +1 -0
  170. data/app/packs/entrypoints/decidim_votings_voting_polling_officer_zone-sign-closure.js +1 -0
  171. data/app/{assets/images/decidim/elections/icon.svg → packs/images/decidim/elections/decidim_elections.svg} +0 -0
  172. data/app/{assets/images/decidim/votings/icon.svg → packs/images/decidim/votings/decidim_votings.svg} +0 -0
  173. data/app/{assets/javascripts/decidim/elections/admin/pending_action.js.es6 → packs/src/decidim/elections/admin/pending_action.js} +4 -6
  174. data/app/{assets/javascripts/decidim/elections/admin/vote_statistics.js.es6 → packs/src/decidim/elections/admin/vote_statistics.js} +0 -0
  175. data/app/packs/src/decidim/elections/election_log.js +145 -0
  176. data/app/packs/src/decidim/elections/onboarding.js +5 -0
  177. data/app/{assets/javascripts/decidim/elections/trustee_zone/key_ceremony.js.es6 → packs/src/decidim/elections/trustee/key_ceremony.js} +59 -22
  178. data/app/{assets/javascripts/decidim/elections/trustee_zone/tally.js.es6 → packs/src/decidim/elections/trustee/tally.js} +48 -12
  179. data/app/{assets/javascripts/decidim/elections/trustee_zone.js.es6 → packs/src/decidim/elections/trustee/trustee_zone.js} +3 -6
  180. data/app/packs/src/decidim/elections/voter/casting-vote.js +14 -0
  181. data/app/packs/src/decidim/elections/voter/new-vote.js +83 -0
  182. data/app/packs/src/decidim/elections/voter/setup-preview.js +79 -0
  183. data/app/packs/src/decidim/elections/voter/setup-vote.js +50 -0
  184. data/app/{assets/javascripts/decidim/elections/vote_verify.js.es6 → packs/src/decidim/elections/voter/verify-vote.js} +22 -21
  185. data/app/packs/src/decidim/elections/voter/vote_questions.component.js +124 -0
  186. data/app/{assets/javascripts/decidim/votings/admin/monitoring_committee_members_form.js.es6 → packs/src/decidim/votings/admin/monitoring_committee_members_form.js} +3 -3
  187. data/app/{assets/javascripts/decidim/votings/admin/polling_officers_form.js.es6 → packs/src/decidim/votings/admin/polling_officers_form.js} +3 -3
  188. data/app/{assets/javascripts/decidim/votings/admin/polling_officers_picker.js.es6 → packs/src/decidim/votings/admin/polling_officers_picker.js} +0 -0
  189. data/app/{assets/javascripts/decidim/votings/admin/polling_stations_form.js.es6 → packs/src/decidim/votings/admin/polling_stations_form.js} +4 -3
  190. data/app/packs/src/decidim/votings/admin/update_census_dataset_status.js +13 -0
  191. data/app/packs/src/decidim/votings/in-person-vote.js +20 -0
  192. data/app/packs/src/decidim/votings/polling_officer_zone/edit-closure.js +26 -0
  193. data/app/packs/src/decidim/votings/polling_officer_zone/in-person-vote.js +5 -0
  194. data/app/packs/src/decidim/votings/polling_officer_zone/new-closure.js +35 -0
  195. data/app/packs/src/decidim/votings/polling_officer_zone/sign-closure.js +13 -0
  196. data/app/packs/src/decidim/votings/voting-description-cell.js +41 -0
  197. data/app/packs/stylesheets/decidim/elections/elections.scss +8 -0
  198. data/app/{assets → packs}/stylesheets/decidim/elections/focus/_accordion.scss +0 -0
  199. data/app/{assets → packs}/stylesheets/decidim/elections/focus/_evote.scss +8 -1
  200. data/app/{assets → packs}/stylesheets/decidim/elections/focus/_focus.scss +0 -0
  201. data/app/{assets → packs}/stylesheets/decidim/elections/trustee_zone.scss +0 -0
  202. data/app/packs/stylesheets/decidim/votings/admin/votings.scss +3 -0
  203. data/app/packs/stylesheets/decidim/votings/admin/votings/_ballot-styles.scss +16 -0
  204. data/app/packs/stylesheets/decidim/votings/admin/votings/_monitoring-committee-polling-station-closures.scss +9 -0
  205. data/app/packs/stylesheets/decidim/votings/admin/votings/_results.scss +3 -0
  206. data/app/packs/stylesheets/decidim/votings/votings.scss +2 -0
  207. data/app/packs/stylesheets/decidim/votings/votings/_polling-stations-cell.scss +6 -0
  208. data/app/packs/stylesheets/decidim/votings/votings/_voting-description-cell.scss +29 -0
  209. data/app/permissions/decidim/elections/admin/permissions.rb +5 -0
  210. data/app/permissions/decidim/elections/permissions.rb +18 -33
  211. data/app/permissions/decidim/votings/admin/permissions.rb +87 -27
  212. data/app/permissions/decidim/votings/permissions.rb +5 -1
  213. data/app/permissions/decidim/votings/polling_officer_zone/permissions.rb +8 -2
  214. data/app/presenters/decidim/votings/census/admin_log/dataset_presenter.rb +30 -0
  215. data/app/presenters/decidim/votings/voting_presenter.rb +2 -11
  216. data/app/presenters/decidim/votings/voting_stats_presenter.rb +52 -0
  217. data/app/queries/decidim/elections/admin/votes_for_statistics.rb +1 -1
  218. data/app/queries/decidim/elections/votes/last_vote_for_voter.rb +29 -0
  219. data/app/queries/decidim/votings/admin/admin_users.rb +15 -10
  220. data/app/queries/decidim/votings/admin/ballot_style_by_voting_code.rb +31 -0
  221. data/app/queries/decidim/votings/votes/in_person_vote_for_voter.rb +27 -0
  222. data/app/queries/decidim/votings/votes/pending_in_person_votes.rb +20 -0
  223. data/app/serializers/decidim/votings/census/datum_serializer.rb +29 -0
  224. data/app/services/decidim/elections/current_user_vote_flow.rb +68 -0
  225. data/app/services/decidim/elections/vote_flow.rb +109 -0
  226. data/app/services/decidim/votings/census/access_codes_exporter.rb +50 -0
  227. data/app/services/decidim/votings/census_vote_flow.rb +106 -0
  228. data/app/uploaders/decidim/cw/votings/census/voting_census_uploader.rb +19 -0
  229. data/app/views/decidim/elections/admin/answers/index.html.erb +23 -4
  230. data/app/views/decidim/elections/admin/elections/index.html.erb +5 -5
  231. data/app/views/decidim/elections/admin/questions/index.html.erb +2 -2
  232. data/app/views/decidim/elections/admin/steps/_results_published.html.erb +62 -0
  233. data/app/views/decidim/elections/admin/steps/_tally_ended.html.erb +49 -3
  234. data/app/views/decidim/elections/admin/steps/_vote.html.erb +1 -1
  235. data/app/views/decidim/elections/admin/steps/_vote_ended.html.erb +4 -0
  236. data/app/views/decidim/elections/admin/steps/index.html.erb +2 -2
  237. data/app/views/decidim/elections/admin/trustees_participatory_spaces/index.html.erb +7 -3
  238. data/app/views/decidim/elections/elections/_filters.html.erb +1 -0
  239. data/app/views/decidim/elections/elections/election_log.html.erb +182 -0
  240. data/app/views/decidim/elections/elections/index.html.erb +0 -2
  241. data/app/views/decidim/elections/elections/show.html.erb +11 -37
  242. data/app/views/decidim/elections/trustee_zone/elections/_key_ceremony_steps.html.erb +41 -39
  243. data/app/views/decidim/elections/trustee_zone/elections/show.html.erb +11 -27
  244. data/app/views/decidim/elections/trustee_zone/elections/update.js.erb +1 -1
  245. data/app/views/decidim/elections/trustee_zone/trustees/show.html.erb +7 -7
  246. data/app/views/decidim/elections/vote_accepted_mailer/notification.html.erb +3 -0
  247. data/app/views/decidim/elections/votes/{_election_votes_header.html.erb → _focus_header.html.erb} +0 -0
  248. data/app/views/decidim/elections/votes/_new_ballot_decision_step.html.erb +30 -0
  249. data/app/views/decidim/elections/votes/{_election_votes_confirm.html.erb → _new_confirm_step.html.erb} +5 -5
  250. data/app/views/decidim/elections/votes/{_election_votes_confirm_footer.html.erb → _new_confirm_step_footer.html.erb} +2 -3
  251. data/app/views/decidim/elections/votes/{_election_votes_encrypting.html.erb → _new_encrypting_step.html.erb} +1 -1
  252. data/app/views/decidim/elections/votes/{_election_votes_question.html.erb → _new_question.html.erb} +7 -7
  253. data/app/views/decidim/elections/votes/{_election_votes_modal.html.erb → _new_question_modal.html.erb} +1 -1
  254. data/app/views/decidim/elections/votes/_onboarding_modal.html.erb +23 -0
  255. data/app/views/decidim/elections/votes/_show_casted.html.erb +36 -0
  256. data/app/views/decidim/elections/votes/_show_casting.html.erb +25 -0
  257. data/app/views/decidim/elections/votes/{_election_votes_failed.html.erb → _show_failed.html.erb} +6 -4
  258. data/app/views/decidim/elections/votes/new.html.erb +29 -16
  259. data/app/views/decidim/elections/votes/show.html.erb +11 -0
  260. data/app/views/decidim/elections/votes/verify.html.erb +6 -9
  261. data/app/views/decidim/votings/access_code_mailer/send_access_code.html.erb +5 -0
  262. data/app/views/decidim/votings/admin/ballot_styles/_form.html.erb +24 -0
  263. data/app/views/decidim/votings/admin/ballot_styles/edit.html.erb +7 -0
  264. data/app/views/decidim/votings/admin/ballot_styles/index.html.erb +68 -0
  265. data/app/views/decidim/votings/admin/ballot_styles/new.html.erb +7 -0
  266. data/app/views/decidim/votings/admin/monitoring_committee_election_results/_results.html.erb +53 -0
  267. data/app/views/decidim/votings/admin/monitoring_committee_election_results/index.html.erb +32 -0
  268. data/app/views/decidim/votings/admin/monitoring_committee_election_results/show.html.erb +24 -0
  269. data/app/views/decidim/votings/admin/monitoring_committee_members/_form.html.erb +1 -1
  270. data/app/views/decidim/votings/admin/monitoring_committee_members/index.html.erb +1 -1
  271. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/_closure_certificate_results.erb +9 -0
  272. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/_closures.html.erb +71 -0
  273. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/_elections.html.erb +32 -0
  274. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/edit.html.erb +29 -0
  275. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/index.html.erb +5 -0
  276. data/app/views/decidim/votings/admin/monitoring_committee_polling_station_closures/show.html.erb +10 -0
  277. data/app/views/decidim/votings/admin/monitoring_committee_verify_elections/index.html.erb +59 -0
  278. data/app/views/decidim/votings/admin/polling_officers/_form.html.erb +1 -1
  279. data/app/views/decidim/votings/admin/polling_officers/index.html.erb +1 -1
  280. data/app/views/decidim/votings/admin/polling_stations/_form.html.erb +1 -1
  281. data/app/views/decidim/votings/admin/polling_stations/index.html.erb +2 -2
  282. data/app/views/decidim/votings/admin/votings/_form.html.erb +9 -2
  283. data/app/views/decidim/votings/admin/votings/edit.html.erb +1 -1
  284. data/app/views/decidim/votings/admin/votings/index.html.erb +3 -2
  285. data/app/views/decidim/votings/census/admin/census/_creating_data.html.erb +10 -0
  286. data/app/views/decidim/votings/census/admin/census/_export_codes.html.erb +8 -0
  287. data/app/views/decidim/votings/census/admin/census/_exporting_codes.html.erb +3 -0
  288. data/app/views/decidim/votings/census/admin/census/_freeze.html.erb +3 -0
  289. data/app/views/decidim/votings/census/admin/census/_generate_codes.html.erb +25 -0
  290. data/app/views/decidim/votings/census/admin/census/_generating_codes.html.erb +3 -0
  291. data/app/views/decidim/votings/census/admin/census/_new_census.html.erb +22 -0
  292. data/app/views/decidim/votings/census/admin/census/_upload_info.html.erb +17 -0
  293. data/app/views/decidim/votings/census/admin/census/show.html.erb +23 -0
  294. data/app/views/decidim/votings/census/admin/census/status.js.erb +1 -0
  295. data/app/views/decidim/votings/census/export_mailer/access_codes_export.erb +7 -0
  296. data/app/views/decidim/votings/polling_officer_zone/closures/_answer_results_form_fields.html.erb +12 -0
  297. data/app/views/decidim/votings/polling_officer_zone/closures/_ballot_results_form_fields.html.erb +40 -0
  298. data/app/views/decidim/votings/polling_officer_zone/closures/_certify_form.html.erb +15 -0
  299. data/app/views/decidim/votings/polling_officer_zone/closures/_modal_ballots_count_error.html.erb +60 -0
  300. data/app/views/decidim/votings/polling_officer_zone/closures/_modal_ballots_results_count_error.html.erb +19 -0
  301. data/app/views/decidim/votings/polling_officer_zone/closures/_question_results_form_fields.html.erb +22 -0
  302. data/app/views/decidim/votings/polling_officer_zone/closures/_sign_form.html.erb +55 -0
  303. data/app/views/decidim/votings/polling_officer_zone/closures/edit.html.erb +48 -0
  304. data/app/views/decidim/votings/polling_officer_zone/closures/new.html.erb +62 -0
  305. data/app/views/decidim/votings/polling_officer_zone/closures/show.html.erb +35 -0
  306. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/_complete_voting.html.erb +59 -0
  307. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/_in_person_form.html.erb +50 -0
  308. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/_verify_document.html.erb +23 -0
  309. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/new.html.erb +21 -0
  310. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/show.html.erb +25 -0
  311. data/app/views/decidim/votings/polling_officer_zone/polling_officers/_polling_station.html.erb +60 -0
  312. data/app/views/decidim/votings/polling_officer_zone/polling_officers/index.html.erb +15 -0
  313. data/app/views/decidim/votings/votings/_access_code_modal.html.erb +33 -0
  314. data/app/views/decidim/votings/votings/_check_fields.html.erb +31 -0
  315. data/app/views/decidim/votings/votings/_filters.html.erb +1 -0
  316. data/app/views/decidim/votings/votings/_promoted_voting.html.erb +1 -1
  317. data/app/views/decidim/votings/votings/check_census.html.erb +64 -0
  318. data/app/views/decidim/votings/votings/elections_log.html.erb +34 -0
  319. data/app/views/decidim/votings/votings/index.html.erb +0 -2
  320. data/app/views/decidim/votings/votings/login.html.erb +50 -0
  321. data/app/views/decidim/votings/votings/show.html.erb +11 -11
  322. data/app/views/layouts/decidim/_election_votes_header.html.erb +3 -3
  323. data/app/views/layouts/decidim/admin/voting.html.erb +5 -83
  324. data/app/views/layouts/decidim/election_votes.html.erb +1 -0
  325. data/app/views/layouts/decidim/voting_landing.html.erb +13 -0
  326. data/app/views/layouts/decidim/{voting.html.erb → votings.html.erb} +3 -1
  327. data/config/assets.rb +35 -0
  328. data/config/initializers/decidim_bulletin_board.rb +17 -11
  329. data/config/initializers/rack_attack.rb +15 -0
  330. data/config/locales/ca.yml +496 -49
  331. data/config/locales/cs.yml +498 -43
  332. data/config/locales/de.yml +469 -44
  333. data/config/locales/el.yml +0 -14
  334. data/config/locales/en.yml +491 -42
  335. data/config/locales/es-MX.yml +338 -42
  336. data/config/locales/es-PY.yml +338 -42
  337. data/config/locales/es.yml +338 -42
  338. data/config/locales/fi-plain.yml +489 -42
  339. data/config/locales/fi.yml +489 -42
  340. data/config/locales/fr-CA.yml +241 -39
  341. data/config/locales/fr-LU.yml +890 -0
  342. data/config/locales/fr.yml +241 -39
  343. data/config/locales/gl.yml +418 -34
  344. data/config/locales/hu.yml +29 -0
  345. data/config/locales/it.yml +1027 -17
  346. data/config/locales/ja.yml +578 -17
  347. data/config/locales/lb-LU.yml +1 -0
  348. data/config/locales/lv.yml +0 -14
  349. data/config/locales/nl.yml +308 -42
  350. data/config/locales/no.yml +12 -36
  351. data/config/locales/pl.yml +670 -215
  352. data/config/locales/pt-BR.yml +1338 -0
  353. data/config/locales/pt.yml +0 -19
  354. data/config/locales/ro-RO.yml +99 -19
  355. data/config/locales/sv.yml +49 -22
  356. data/config/locales/tr-TR.yml +3 -24
  357. data/config/locales/zh-CN.yml +0 -19
  358. data/db/migrate/20210308104024_add_decidim_votings_census_datasets.rb +17 -0
  359. data/db/migrate/20210308104154_add_decidim_votings_census_data.rb +23 -0
  360. data/db/migrate/20210326090435_create_elections_results.rb +16 -0
  361. data/db/migrate/20210330102348_remove_votes_count_from_answer.rb +7 -0
  362. data/db/migrate/20210330123606_add_voting_ballot_style.rb +19 -0
  363. data/db/migrate/20210330183204_add_email_to_votes.rb +10 -0
  364. data/db/migrate/20210331152729_add_census_contact_information_to_votings.rb +7 -0
  365. data/db/migrate/20210401095507_add_organization_to_decidim_elections_trustee.rb +11 -0
  366. data/db/migrate/20210402102215_add_ballot_style_to_decidim_votings_census_data.rb +7 -0
  367. data/db/migrate/20210402140402_add_salt_to_elections.rb +22 -0
  368. data/db/migrate/20210412144721_change_elections_results.rb +24 -0
  369. data/db/migrate/20210412144740_create_elections_bulletin_board_closures.rb +13 -0
  370. data/db/migrate/20210412144741_create_votings_polling_station_closures.rb +22 -0
  371. data/db/migrate/20210420112721_create_decidim_votings_in_person_votes.rb +21 -0
  372. data/db/migrate/20210422124826_add_verifiable_results_to_decidim_elections_election.rb +8 -0
  373. data/db/migrate/20210426072845_add_signed_at_to_polling_station_closure.rb +7 -0
  374. data/db/migrate/20210427131742_add_validated_at_to_votings_polling_station_closures.rb +8 -0
  375. data/db/seeds/Exampledocument.pdf +0 -0
  376. data/db/seeds/city2.jpeg +0 -0
  377. data/lib/decidim/api/bulletin_board_closure_type.rb +16 -0
  378. data/lib/decidim/api/election_answer_type.rb +3 -2
  379. data/lib/decidim/api/election_result_type.rb +19 -0
  380. data/lib/decidim/api/polling_station_closure_type.rb +19 -0
  381. data/lib/decidim/api/polling_station_type.rb +24 -0
  382. data/lib/decidim/elections.rb +8 -0
  383. data/lib/decidim/elections/admin_engine.rb +14 -15
  384. data/lib/decidim/elections/answer_serializer.rb +2 -1
  385. data/lib/decidim/elections/api.rb +2 -0
  386. data/lib/decidim/elections/component.rb +85 -19
  387. data/lib/decidim/elections/engine.rb +4 -6
  388. data/lib/decidim/elections/test/factories.rb +76 -11
  389. data/lib/decidim/elections/trustee_zone_engine.rb +5 -4
  390. data/lib/decidim/elections/version.rb +1 -1
  391. data/lib/decidim/votings.rb +17 -0
  392. data/lib/decidim/votings/admin_engine.rb +134 -8
  393. data/lib/decidim/votings/api.rb +2 -0
  394. data/lib/decidim/votings/census.rb +16 -0
  395. data/lib/decidim/votings/census_admin.rb +12 -0
  396. data/lib/decidim/votings/census_admin_engine.rb +22 -0
  397. data/lib/decidim/votings/census_engine.rb +19 -0
  398. data/lib/decidim/votings/engine.rb +25 -20
  399. data/lib/decidim/votings/participatory_space.rb +149 -2
  400. data/lib/decidim/votings/polling_officer_zone_engine.rb +15 -6
  401. data/lib/decidim/votings/test/factories.rb +163 -0
  402. data/lib/decidim/votings/voting_serializer.rb +1 -0
  403. data/lib/tasks/decidim_voting_census.rake +26 -0
  404. metadata +326 -72
  405. data/app/assets/config/admin/decidim_votings_manifest.css +0 -0
  406. data/app/assets/config/admin/decidim_votings_manifest.js +0 -4
  407. data/app/assets/config/decidim_elections_manifest.css +0 -3
  408. data/app/assets/config/decidim_elections_manifest.js +0 -8
  409. data/app/assets/config/decidim_votings_manifest.css +0 -3
  410. data/app/assets/config/decidim_votings_manifest.js +0 -0
  411. data/app/assets/javascripts/decidim/elections/vote.js.es6 +0 -117
  412. data/app/assets/javascripts/decidim/elections/vote_questions.component.js.es6 +0 -129
  413. data/app/assets/stylesheets/decidim/elections/elections.scss +0 -6
  414. data/app/assets/stylesheets/decidim/votings/votings.scss +0 -1
  415. data/app/assets/stylesheets/decidim/votings/votings/_votings-header.scss +0 -99
  416. data/app/assets/stylesheets/decidim/votings/votings/_votings-home-banner.scss +0 -11
  417. data/app/controllers/decidim/votings/polling_officer_zone/polling_stations_controller.rb +0 -22
  418. data/app/forms/decidim/elections/voter/encrypted_vote_form.rb +0 -49
  419. data/app/helpers/decidim/elections/elections_helper.rb +0 -29
  420. data/app/queries/decidim/elections/votes/election_votes.rb +0 -19
  421. data/app/queries/decidim/elections/votes/user_election_last_vote.rb +0 -26
  422. data/app/queries/decidim/elections/votes/user_votes.rb +0 -19
  423. data/app/views/decidim/elections/elections/_preview.html.erb +0 -26
  424. data/app/views/decidim/elections/elections/_results.html.erb +0 -47
  425. data/app/views/decidim/elections/votes/_election_votes_confirmed.html.erb +0 -47
  426. data/app/views/decidim/elections/votes/_election_votes_steps_header.html.erb +0 -12
  427. data/app/views/decidim/elections/votes/cast_failed.js.erb +0 -1
  428. data/app/views/decidim/elections/votes/cast_success.js.erb +0 -1
  429. data/app/views/decidim/votings/polling_officer_zone/polling_officers/show.html.erb +0 -42
  430. data/app/views/decidim/votings/polling_officer_zone/polling_stations/show.html.erb +0 -1
  431. data/app/views/decidim/votings/votings/_voting_details.html.erb +0 -7
  432. data/app/views/layouts/decidim/_voting_header.html.erb +0 -16
  433. data/config/locales/ja-JP.yml +0 -216
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Votings
5
+ module Voter
6
+ # This command allows the user to register an in person vote.
7
+ class InPersonVote < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form with necessary info to register an in person vote.
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Store and register the in person vote in the bulletin board
16
+ #
17
+ # Broadcasts :ok if successful, :invalid otherwise
18
+ def call
19
+ return broadcast(:invalid) if form.invalid?
20
+
21
+ transaction do
22
+ register_in_person_vote
23
+ end
24
+
25
+ broadcast(:ok, in_person_vote)
26
+ rescue StandardError => e
27
+ broadcast(:invalid, e.message)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :form, :in_person_vote
33
+
34
+ delegate :bulletin_board, to: :form
35
+
36
+ def register_in_person_vote
37
+ bulletin_board.in_person_vote(form.election_id, form.voter_id, form.polling_station_slug) do |message_id|
38
+ create_in_person_vote(message_id)
39
+ end
40
+ end
41
+
42
+ def create_in_person_vote(message_id)
43
+ @in_person_vote = Decidim::Votings::InPersonVote.create!(
44
+ election: form.election,
45
+ polling_station: form.polling_station,
46
+ polling_officer: form.polling_officer,
47
+ message_id: message_id,
48
+ voter_id: form.voter_id,
49
+ status: :pending
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Votings
5
+ module Voter
6
+ # This command updates the in person vote status
7
+ class UpdateInPersonVoteStatus < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # in_person_vote - the in person vote that has been updated
11
+ def initialize(in_person_vote)
12
+ @in_person_vote = in_person_vote
13
+ end
14
+
15
+ # Update status and send notification
16
+ #
17
+ # Broadcasts :ok if successful, :invalid otherwise
18
+ def call
19
+ return broadcast(:ok) unless status_changed?
20
+
21
+ transaction do
22
+ update_vote_status
23
+ end
24
+
25
+ broadcast(:ok)
26
+ rescue StandardError => e
27
+ broadcast(:invalid, e.message)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :in_person_vote, :locale
33
+
34
+ def status_changed?
35
+ in_person_vote.status != vote_status
36
+ end
37
+
38
+ def bulletin_board
39
+ @bulletin_board ||= Decidim::Elections.bulletin_board
40
+ end
41
+
42
+ def vote_status
43
+ @vote_status ||= bulletin_board.get_pending_message_status(in_person_vote.message_id)
44
+ end
45
+
46
+ def update_vote_status
47
+ in_person_vote.update!(status: vote_status)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Elections
7
+ # Common logic for the vote flow
8
+ module HasVoteFlow
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ helper_method :voter_id, :voter_token, :voter_name, :preview_mode?, :ballot_style_id
13
+ delegate :voter_id, :ballot_style_id, :voter_token, :voter_name, :email, to: :vote_flow
14
+ end
15
+
16
+ def vote_flow
17
+ @vote_flow ||= election.participatory_space.try(:vote_flow_for, election) || default_vote_flow
18
+ end
19
+
20
+ def default_vote_flow
21
+ Decidim::Elections::CurrentUserVoteFlow.new(election, current_user) do
22
+ allowed_to?(:user_vote, :election, election: election)
23
+ end
24
+ end
25
+
26
+ def preview_mode?
27
+ return @preview_mode if defined?(@preview_mode)
28
+
29
+ @preview_mode = !election.published? || !election.started?
30
+ end
31
+
32
+ def can_preview?
33
+ return @can_preview if defined?(@can_preview)
34
+
35
+ @preview_mode = allowed_to?(:preview, :election, election: election)
36
+ end
37
+
38
+ def ballot_questions
39
+ vote_flow.questions_for(election)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module MonitoringCommitteePollingStationClosures
7
+ module Admin
8
+ module Filterable
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ include Decidim::Admin::Filterable
13
+
14
+ private
15
+
16
+ def base_query
17
+ query =
18
+ collection
19
+ # Includes the officers (president and managers) and their correspective decidim users when they(=officers) are present
20
+ .joins("LEFT JOIN decidim_votings_polling_officers president ON president.presided_polling_station_id = decidim_votings_polling_stations.id
21
+ LEFT JOIN decidim_users president_user ON president_user.id = president.decidim_user_id
22
+ LEFT JOIN decidim_votings_polling_officers managers ON managers.managed_polling_station_id = decidim_votings_polling_stations.id
23
+ LEFT JOIN decidim_users manager_user ON manager_user.id = managers.decidim_user_id
24
+ LEFT JOIN decidim_votings_polling_station_closures closure ON closure.decidim_votings_polling_station_id = decidim_votings_polling_stations.id
25
+ AND closure.decidim_elections_election_id = #{election_id}")
26
+
27
+ query = filter_by_validated(query)
28
+ filter_by_signed(query)
29
+ end
30
+
31
+ def election_id
32
+ params[:election_id]
33
+ end
34
+
35
+ def search_field_predicate
36
+ :title_or_address_or_manager_name_or_manager_email_or_manager_nickname_or_president_name_or_president_email_or_president_nickname_cont
37
+ end
38
+
39
+ def extra_allowed_params
40
+ [:election_id, :per_page]
41
+ end
42
+
43
+ def filters
44
+ [:validated_eq, :signed_eq]
45
+ end
46
+
47
+ def filter_by_validated(query)
48
+ case ransack_params[:validated_eq]
49
+ when "false"
50
+ query.where(Arel.sql("closure.validated_at IS NOT NULL"))
51
+ when "true"
52
+ query.where(Arel.sql("closure.validated_at IS NULL"))
53
+ else
54
+ query
55
+ end
56
+ end
57
+
58
+ def filter_by_signed(query)
59
+ case ransack_params[:signed_eq]
60
+ when "false"
61
+ query.where(Arel.sql("closure.signed_at IS NOT NULL"))
62
+ when "true"
63
+ query.where(Arel.sql("closure.signed_at IS NULL"))
64
+ else
65
+ query
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -7,7 +7,7 @@ module Decidim
7
7
  module NeedsVoting
8
8
  def self.enhance_controller(instance_or_module)
9
9
  instance_or_module.class_eval do
10
- helper_method :current_voting
10
+ helper_method :current_participatory_space
11
11
  end
12
12
  end
13
13
 
@@ -22,16 +22,16 @@ module Decidim
22
22
  # context.
23
23
  #
24
24
  # Returns the current Voting.
25
- def current_voting
26
- @current_voting ||= detect_voting
25
+ def current_participatory_space
26
+ @current_participatory_space ||= detect_voting
27
27
  end
28
28
 
29
- alias current_participatory_space current_voting
29
+ alias current_voting current_participatory_space
30
30
 
31
31
  private
32
32
 
33
33
  def detect_voting
34
- request.env["current_voting"] ||
34
+ request.env["current_participatory_space"] ||
35
35
  organization_votings.find_by(slug: params[:voting_slug] || params[:slug])
36
36
  end
37
37
 
@@ -6,7 +6,7 @@ module Decidim
6
6
  # This controller allows to manage the steps of an election.
7
7
  class StepsController < Admin::ApplicationController
8
8
  helper StepsHelper
9
- helper_method :elections, :election, :current_step, :vote_stats
9
+ helper_method :elections, :election, :current_step, :vote_stats, :bulletin_board_server
10
10
 
11
11
  def index
12
12
  enforce_permission_to :read, :steps, election: election
@@ -22,7 +22,6 @@ module Decidim
22
22
  redirect_to election_steps_path(election) && return unless params[:id] == current_step
23
23
 
24
24
  @form = form(current_step_form_class).from_params(params, election: election)
25
-
26
25
  if @form.pending_action
27
26
  Decidim::Elections::Admin::UpdateActionStatus.call(@form.pending_action)
28
27
  return redirect_to election_steps_path(election)
@@ -46,6 +45,10 @@ module Decidim
46
45
 
47
46
  private
48
47
 
48
+ def bulletin_board_server
49
+ Decidim::Elections.bulletin_board.bulletin_board_server
50
+ end
51
+
49
52
  def current_step_form_class
50
53
  @current_step_form_class ||= {
51
54
  "create_election" => SetupForm,
@@ -7,8 +7,9 @@ module Decidim
7
7
  include FilterResource
8
8
  include Paginable
9
9
  include Decidim::Elections::Orderable
10
+ include HasVoteFlow
10
11
 
11
- helper_method :elections, :election, :paginated_elections, :scheduled_elections, :single?, :last_vote
12
+ helper_method :elections, :election, :paginated_elections, :scheduled_elections, :single?, :onboarding, :authority_public_key, :bulletin_board_server, :authority_slug
12
13
 
13
14
  def index
14
15
  redirect_to election_path(single, single: true) if single?
@@ -18,8 +19,12 @@ module Decidim
18
19
  enforce_permission_to :view, :election, election: election
19
20
  end
20
21
 
22
+ def election_log; end
23
+
21
24
  private
22
25
 
26
+ delegate :bulletin_board_server, :authority_slug, to: :bulletin_board_client
27
+
23
28
  def elections
24
29
  @elections ||= Election.where(component: current_component).published
25
30
  end
@@ -28,6 +33,18 @@ module Decidim
28
33
  @election ||= Election.where(component: current_component).find(params[:id])
29
34
  end
30
35
 
36
+ def onboarding
37
+ @onboarding ||= params[:onboarding].present?
38
+ end
39
+
40
+ def bulletin_board_client
41
+ @bulletin_board_client ||= Decidim::Elections.bulletin_board
42
+ end
43
+
44
+ def authority_public_key
45
+ @authority_public_key ||= bulletin_board_client.authority_public_key.to_json
46
+ end
47
+
31
48
  # Public: Checks if the component has only one election resource.
32
49
  #
33
50
  # Returns Boolean.
@@ -39,10 +56,6 @@ module Decidim
39
56
  elections.first if single?
40
57
  end
41
58
 
42
- def last_vote
43
- @last_vote ||= Decidim::Elections::Votes::UserElectionLastVote.new(current_user, election).query
44
- end
45
-
46
59
  def paginated_elections
47
60
  @paginated_elections ||= paginate(search.results.published)
48
61
  @paginated_elections = reorder(@paginated_elections)
@@ -5,6 +5,8 @@ module Decidim
5
5
  # This controller allows a user to give feedback once finished voting
6
6
  class FeedbacksController < Decidim::Elections::ApplicationController
7
7
  include Decidim::Forms::Concerns::HasQuestionnaire
8
+ include HasVoteFlow
9
+
8
10
  helper_method :election
9
11
 
10
12
  def questionnaire_for
@@ -13,7 +15,17 @@ module Decidim
13
15
 
14
16
  # where the questionnaire will be submitted.
15
17
  def update_url
16
- answer_election_feedback_path(election)
18
+ answer_election_feedback_path(election, hash: params[:hash], token: params[:token])
19
+ end
20
+
21
+ # Overwrites the 'after_answer_path' that gets passed to 'redirect_to'
22
+ # after answering the questionnaire. By default it redirects to the questionnaire_for.
23
+ def after_answer_path
24
+ if current_user.nil?
25
+ election_path(election, onboarding: true)
26
+ else
27
+ election_path(election)
28
+ end
17
29
  end
18
30
 
19
31
  private
@@ -23,7 +35,11 @@ module Decidim
23
35
  end
24
36
 
25
37
  def allow_answers?
26
- current_user.present? && election.ongoing?
38
+ can_preview? || (election.ongoing? && valid_token?)
39
+ end
40
+
41
+ def visitor_already_answered?
42
+ election.questionnaire.answered_by?(session_token)
27
43
  end
28
44
 
29
45
  def i18n_flashes_scope
@@ -31,7 +47,25 @@ module Decidim
31
47
  end
32
48
 
33
49
  def enforce_permission_to_answer_questionnaire
34
- enforce_permission_to :answer, :questionnaire, election: election
50
+ can_preview? || valid_token?
51
+ end
52
+
53
+ def allow_unregistered?
54
+ true
55
+ end
56
+
57
+ def valid_token?
58
+ return @valid_token if defined?(@valid_token)
59
+
60
+ @valid_token = vote_flow.voter_id_token(vote.voter_id) == session_token
61
+ end
62
+
63
+ def session_token
64
+ @session_token ||= params[:token]
65
+ end
66
+
67
+ def vote
68
+ @vote ||= Decidim::Elections::Vote.find_by(encrypted_vote_hash: params[:hash])
35
69
  end
36
70
  end
37
71
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module TrusteeZone
6
6
  # Handles the KeyCeremony for trustee users
7
7
  class ElectionsController < Decidim::Elections::TrusteeZone::ApplicationController
8
- helper_method :election
8
+ helper_method :election, :bulletin_board_server, :authority_slug, :authority_public_key, :current_step, :scheme_name
9
9
 
10
10
  def show
11
11
  enforce_permission_to :view, :election, trustee: trustee
@@ -26,9 +26,23 @@ module Decidim
26
26
 
27
27
  private
28
28
 
29
+ delegate :bulletin_board_server, :authority_slug, :scheme_name, to: :bulletin_board_client
30
+
29
31
  def election
30
32
  @election ||= Decidim::Elections::Election.find(params[:election_id])
31
33
  end
34
+
35
+ def bulletin_board_client
36
+ @bulletin_board_client ||= Decidim::Elections.bulletin_board
37
+ end
38
+
39
+ def authority_public_key
40
+ @authority_public_key ||= bulletin_board_client.authority_public_key.to_json
41
+ end
42
+
43
+ def current_step
44
+ @current_step ||= election.bb_status if election.bb_key_ceremony? || election.bb_tally?
45
+ end
32
46
  end
33
47
  end
34
48
  end
@@ -6,80 +6,95 @@ module Decidim
6
6
  class VotesController < Decidim::Elections::ApplicationController
7
7
  layout "decidim/election_votes"
8
8
  include FormFactory
9
+ include HasVoteFlow
9
10
 
10
11
  helper VotesHelper
11
- helper_method :elections, :election, :questions, :questions_count, :booth_mode, :vote
12
+ helper_method :bulletin_board_server, :authority_public_key, :scheme_name, :election_unique_id,
13
+ :exit_path, :elections, :election, :questions, :questions_count, :vote, :valid_questionnaire?
12
14
 
13
15
  delegate :count, to: :questions, prefix: true
14
16
 
15
17
  def new
16
- return redirect_to(return_path, alert: t("votes.messages.not_allowed", scope: "decidim.elections")) if booth_mode.nil?
17
- return redirect_to(pending_vote_path) if pending_vote?
18
+ vote_flow.voter_login(params)
19
+ return unless vote_allowed?
18
20
 
19
- @form = form(Voter::EncryptedVoteForm).instance(election: election)
21
+ @form = form(Voter::VoteForm).from_params({ voter_token: voter_token, voter_id: voter_id },
22
+ election: election, user: vote_flow.user)
20
23
  end
21
24
 
22
- def update
23
- Voter::UpdateVoteStatus.call(vote) do
24
- on(:ok) do
25
- flash[:notice] = I18n.t("votes.update.success", scope: "decidim.elections")
25
+ def create
26
+ vote_flow.voter_from_token(params.require(:vote).permit(:voter_token, :voter_id))
27
+ return unless valid_voter_token?
28
+ return unless vote_allowed?
29
+
30
+ return redirect_to election_vote_path(election, id: params[:vote][:encrypted_data_hash], token: vote_flow.voter_id_token) if preview_mode?
31
+
32
+ @form = form(Voter::VoteForm).from_params(params, election: election, user: vote_flow.user, email: vote_flow.email)
33
+ Voter::CastVote.call(@form) do
34
+ on(:ok) do |vote|
35
+ redirect_to election_vote_path(election, id: vote.encrypted_vote_hash, token: vote_flow.voter_id_token)
26
36
  end
27
37
  on(:invalid) do
28
- flash[:alert] = I18n.t("votes.update.error", scope: "decidim.elections")
38
+ flash[:alert] = I18n.t("votes.create.error", scope: "decidim.elections")
39
+ redirect_to exit_path
29
40
  end
30
41
  end
31
42
  end
32
43
 
33
- def cast
34
- @form = form(Voter::EncryptedVoteForm).from_params(params, election: election)
35
- return render :cast_success, locals: { message_id: "PreviewMessageId", vote_id: nil } if preview?
44
+ def show
45
+ enforce_permission_to :view, :election, election: election
46
+ end
47
+
48
+ def update
49
+ enforce_permission_to :view, :election, election: election
36
50
 
37
- Voter::CastVote.call(@form) do
38
- on(:ok) do |vote|
39
- render :cast_success, locals: { message_id: vote.message_id, vote_id: vote.id }
51
+ Voter::UpdateVoteStatus.call(vote) do
52
+ on(:ok) do
53
+ redirect_to election_vote_path(election, id: vote.encrypted_vote_hash, token: vote_flow.voter_id_token(vote.voter_id))
40
54
  end
41
55
  on(:invalid) do
42
- render :cast_failed
56
+ flash[:alert] = I18n.t("votes.update.error", scope: "decidim.elections")
57
+ redirect_to exit_path
43
58
  end
44
59
  end
45
60
  end
46
61
 
47
62
  def verify
48
- @form = form(Ballot::VerifyVoteForm).instance(election: election)
63
+ enforce_permission_to :view, :election, election: election
64
+
65
+ @form = form(Voter::VerifyVoteForm).instance(election: election)
49
66
  end
50
67
 
51
68
  private
52
69
 
70
+ delegate :bulletin_board_server, :scheme_name, to: :bulletin_board_client
71
+
72
+ def election_unique_id
73
+ @election_unique_id ||= Decidim::BulletinBoard::MessageIdentifier.unique_election_id(bulletin_board_client.authority_slug, election.id)
74
+ end
75
+
53
76
  def vote
54
- @vote ||= Decidim::Elections::Vote.find_by(id: params[:vote_id])
77
+ @vote ||= Decidim::Elections::Vote.find_by(election: election, encrypted_vote_hash: params[:id]) if params[:id]
55
78
  end
56
79
 
57
- def pending_vote?
58
- Decidim::Elections::Votes::PendingVotes.for.exists?(user: current_user, election: election)
80
+ def exit_path
81
+ @exit_path ||= if allowed_to? :view, :election, election: election
82
+ election_path(election)
83
+ else
84
+ elections_path
85
+ end
59
86
  end
60
87
 
61
- def booth_mode
62
- @booth_mode ||= if allowed_to? :vote, :election, election: election
63
- :vote
64
- elsif allowed_to? :preview, :election, election: election
65
- :preview
66
- end
88
+ def pending_vote
89
+ @pending_vote ||= Decidim::Elections::Votes::PendingVotes.for.find_by(voter_id: voter_id, election: election)
67
90
  end
68
91
 
69
- def return_path
70
- @return_path ||= if allowed_to? :view, :election, election: election
71
- election_path(election)
72
- else
73
- elections_path
74
- end
92
+ def bulletin_board_client
93
+ @bulletin_board_client ||= Decidim::Elections.bulletin_board
75
94
  end
76
95
 
77
- def pending_vote_path
78
- @pending_vote_path ||= if allowed_to? :view, :election, election: election
79
- verify_election_vote_path(election)
80
- else
81
- elections_path
82
- end
96
+ def authority_public_key
97
+ @authority_public_key ||= bulletin_board_client.authority_public_key.to_json
83
98
  end
84
99
 
85
100
  def elections
@@ -91,11 +106,56 @@ module Decidim
91
106
  end
92
107
 
93
108
  def questions
94
- @questions ||= election.questions.includes(:answers).order(weight: :asc, id: :asc)
109
+ @questions ||= ballot_questions.includes(:answers).order(weight: :asc, id: :asc)
95
110
  end
96
111
 
97
- def preview?
98
- booth_mode == :preview
112
+ def vote_allowed?
113
+ if preview_mode?
114
+ return true if can_preview?
115
+
116
+ redirect_to(
117
+ exit_path,
118
+ alert: t("votes.messages.not_allowed",
119
+ scope: "decidim.elections")
120
+ )
121
+ return false
122
+ end
123
+
124
+ if pending_vote.present?
125
+ redirect_to(
126
+ election_vote_path(election,
127
+ id: pending_vote.encrypted_vote_hash,
128
+ token: vote_flow.voter_id_token)
129
+ )
130
+ return false
131
+ end
132
+
133
+ vote_check_result = vote_flow.vote_check(online_vote_path: new_election_vote_path)
134
+ unless vote_check_result.allowed?
135
+ redirect_to(
136
+ vote_check_result.exit_path || exit_path,
137
+ alert: vote_check_result.error_message,
138
+ status: :temporary_redirect
139
+ )
140
+
141
+ return false
142
+ end
143
+
144
+ enforce_permission_to :vote, :election, election: election
145
+
146
+ true
147
+ end
148
+
149
+ def valid_voter_token?
150
+ return true if preview_mode? || vote_flow.valid_received_data?
151
+
152
+ redirect_to(exit_path, alert: t("votes.messages.invalid_token", scope: "decidim.elections"))
153
+ end
154
+
155
+ def valid_questionnaire?
156
+ return @valid_questionnaire if defined?(@valid_questionnaire)
157
+
158
+ @valid_questionnaire = election.questionnaire.questions.any?
99
159
  end
100
160
  end
101
161
  end