decidim-elections 0.23.5 → 0.24.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (326) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/app/assets/config/admin/decidim_votings_manifest.css +0 -0
  4. data/app/assets/config/admin/decidim_votings_manifest.js +4 -0
  5. data/app/assets/config/decidim_elections_manifest.css +3 -0
  6. data/app/assets/config/decidim_elections_manifest.js +6 -0
  7. data/app/assets/config/decidim_votings_manifest.css +3 -0
  8. data/app/assets/config/decidim_votings_manifest.js +0 -0
  9. data/app/assets/images/decidim/votings/icon.svg +1 -0
  10. data/app/assets/javascripts/decidim/elections/admin/pending_action.js.es6 +16 -0
  11. data/app/assets/javascripts/decidim/elections/admin/vote_statistics.js.es6 +11 -0
  12. data/app/assets/javascripts/decidim/elections/trustee_zone.js.es6 +54 -0
  13. data/app/assets/javascripts/decidim/elections/trustee_zone/key_ceremony.js.es6 +126 -0
  14. data/app/assets/javascripts/decidim/elections/trustee_zone/tally.js.es6 +104 -0
  15. data/app/assets/javascripts/decidim/elections/vote.js.es6 +107 -160
  16. data/app/assets/javascripts/decidim/elections/vote_questions.component.js.es6 +129 -0
  17. data/app/assets/javascripts/decidim/elections/vote_verify.js.es6 +71 -0
  18. data/app/assets/javascripts/decidim/votings/admin/monitoring_committee_members_form.js.es6 +35 -0
  19. data/app/assets/javascripts/decidim/votings/admin/polling_officers_form.js.es6 +35 -0
  20. data/app/assets/javascripts/decidim/votings/admin/polling_officers_picker.js.es6 +35 -0
  21. data/app/assets/javascripts/decidim/votings/admin/polling_stations_form.js.es6 +5 -0
  22. data/app/assets/stylesheets/decidim/elections/elections.scss +0 -4
  23. data/app/assets/stylesheets/decidim/elections/focus/_accordion.scss +36 -0
  24. data/app/assets/stylesheets/decidim/elections/focus/_evote.scss +58 -0
  25. data/app/assets/stylesheets/decidim/elections/trustee_zone.scss +24 -0
  26. data/app/assets/stylesheets/decidim/votings/votings.scss +1 -0
  27. data/app/assets/stylesheets/decidim/votings/votings/_votings-header.scss +99 -0
  28. data/app/assets/stylesheets/decidim/votings/votings/_votings-home-banner.scss +11 -0
  29. data/app/cells/decidim/votings/content_block_cell.rb +17 -0
  30. data/app/cells/decidim/votings/content_blocks/highlighted_votings/show.erb +30 -0
  31. data/app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb +33 -0
  32. data/app/cells/decidim/votings/content_blocks/highlighted_votings_settings_form/show.erb +3 -0
  33. data/app/cells/decidim/votings/content_blocks/highlighted_votings_settings_form_cell.rb +19 -0
  34. data/app/cells/decidim/votings/content_blocks/landing_page/attachments_and_folders_cell.rb +15 -0
  35. data/app/cells/decidim/votings/content_blocks/landing_page/description_cell.rb +15 -0
  36. data/app/cells/decidim/votings/content_blocks/landing_page/elections_cell.rb +15 -0
  37. data/app/cells/decidim/votings/content_blocks/landing_page/header_cell.rb +15 -0
  38. data/app/cells/decidim/votings/content_blocks/landing_page/metrics_cell.rb +15 -0
  39. data/app/cells/decidim/votings/content_blocks/landing_page/polling_stations_cell.rb +15 -0
  40. data/app/cells/decidim/votings/content_blocks/landing_page/stats_cell.rb +15 -0
  41. data/app/cells/decidim/votings/content_blocks/landing_page/timeline_cell.rb +15 -0
  42. data/app/cells/decidim/votings/polling_officers/polling_officers_picker/polling_officers.erb +12 -0
  43. data/app/cells/decidim/votings/polling_officers/polling_officers_picker/show.erb +14 -0
  44. data/app/cells/decidim/votings/polling_officers/polling_officers_picker_cell.rb +73 -0
  45. data/app/cells/decidim/votings/voting_cell.rb +19 -0
  46. data/app/cells/decidim/votings/voting_m/data.erb +21 -0
  47. data/app/cells/decidim/votings/voting_m/footer.erb +5 -0
  48. data/app/cells/decidim/votings/voting_m_cell.rb +94 -0
  49. data/app/commands/decidim/elections/admin/add_user_as_trustee.rb +81 -0
  50. data/app/commands/decidim/elections/admin/create_election.rb +2 -1
  51. data/app/commands/decidim/elections/admin/end_vote.rb +63 -0
  52. data/app/commands/decidim/elections/admin/publish_results.rb +59 -0
  53. data/app/commands/decidim/elections/admin/remove_trustee_from_participatory_space.rb +37 -0
  54. data/app/commands/decidim/elections/admin/setup_election.rb +160 -0
  55. data/app/commands/decidim/elections/admin/start_key_ceremony.rb +63 -0
  56. data/app/commands/decidim/elections/admin/start_tally.rb +63 -0
  57. data/app/commands/decidim/elections/admin/start_vote.rb +63 -0
  58. data/app/commands/decidim/elections/admin/update_action_status.rb +47 -0
  59. data/app/commands/decidim/elections/admin/update_answer_selection.rb +41 -0
  60. data/app/commands/decidim/elections/admin/update_trustee_participatory_space.rb +40 -0
  61. data/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb +39 -0
  62. data/app/commands/decidim/elections/trustee_zone/update_trustee.rb +41 -0
  63. data/app/commands/decidim/elections/voter/cast_vote.rb +59 -0
  64. data/app/commands/decidim/elections/voter/update_vote_status.rb +70 -0
  65. data/app/commands/decidim/votings/admin/create_monitoring_committee_member.rb +99 -0
  66. data/app/commands/decidim/votings/admin/create_polling_officer.rb +99 -0
  67. data/app/commands/decidim/votings/admin/create_polling_station.rb +59 -0
  68. data/app/commands/decidim/votings/admin/create_voting.rb +59 -0
  69. data/app/commands/decidim/votings/admin/destroy_monitoring_committee_member.rb +51 -0
  70. data/app/commands/decidim/votings/admin/destroy_polling_officer.rb +52 -0
  71. data/app/commands/decidim/votings/admin/destroy_polling_station.rb +40 -0
  72. data/app/commands/decidim/votings/admin/manage_polling_station.rb +64 -0
  73. data/app/commands/decidim/votings/admin/publish_voting.rb +40 -0
  74. data/app/commands/decidim/votings/admin/unpublish_voting.rb +40 -0
  75. data/app/commands/decidim/votings/admin/update_polling_station.rb +50 -0
  76. data/app/commands/decidim/votings/admin/update_voting.rb +85 -0
  77. data/app/constraints/decidim/votings/current_component.rb +28 -0
  78. data/app/constraints/decidim/votings/current_voting.rb +43 -0
  79. data/app/controllers/concerns/decidim/elections/orderable.rb +2 -2
  80. data/app/controllers/concerns/decidim/polling_officers/admin/filterable.rb +58 -0
  81. data/app/controllers/concerns/decidim/polling_stations/admin/filterable.rb +57 -0
  82. data/app/controllers/concerns/decidim/votings/admin/filterable.rb +27 -0
  83. data/app/controllers/concerns/decidim/votings/admin/voting_admin.rb +48 -0
  84. data/app/controllers/concerns/decidim/votings/needs_voting.rb +44 -0
  85. data/app/controllers/concerns/decidim/votings/orderable.rb +32 -0
  86. data/app/controllers/decidim/elections/admin/answers_controller.rb +32 -0
  87. data/app/controllers/decidim/elections/admin/elections_controller.rb +2 -2
  88. data/app/controllers/decidim/elections/admin/feedback_forms_controller.rb +55 -0
  89. data/app/controllers/decidim/elections/admin/steps_controller.rb +96 -0
  90. data/app/controllers/decidim/elections/admin/trustees_participatory_spaces_controller.rb +89 -0
  91. data/app/controllers/decidim/elections/elections_controller.rb +5 -1
  92. data/app/controllers/decidim/elections/feedbacks_controller.rb +38 -0
  93. data/app/controllers/decidim/elections/trustee_zone/application_controller.rb +45 -0
  94. data/app/controllers/decidim/elections/trustee_zone/elections_controller.rb +35 -0
  95. data/app/controllers/decidim/elections/trustee_zone/trustees_controller.rb +36 -0
  96. data/app/controllers/decidim/elections/votes_controller.rb +54 -2
  97. data/app/controllers/decidim/votings/admin/application_controller.rb +26 -0
  98. data/app/controllers/decidim/votings/admin/component_permissions_controller.rb +13 -0
  99. data/app/controllers/decidim/votings/admin/components_controller.rb +15 -0
  100. data/app/controllers/decidim/votings/admin/monitoring_committee_members_controller.rb +62 -0
  101. data/app/controllers/decidim/votings/admin/polling_officers_controller.rb +66 -0
  102. data/app/controllers/decidim/votings/admin/polling_stations_controller.rb +92 -0
  103. data/app/controllers/decidim/votings/admin/voting_attachment_collections_controller.rb +22 -0
  104. data/app/controllers/decidim/votings/admin/voting_attachments_controller.rb +21 -0
  105. data/app/controllers/decidim/votings/admin/votings_controller.rb +124 -0
  106. data/app/controllers/decidim/votings/admin/votings_landing_page_content_blocks_controller.rb +44 -0
  107. data/app/controllers/decidim/votings/admin/votings_landing_page_controller.rb +46 -0
  108. data/app/controllers/decidim/votings/application_controller.rb +26 -0
  109. data/app/controllers/decidim/votings/polling_officer_zone/application_controller.rb +33 -0
  110. data/app/controllers/decidim/votings/polling_officer_zone/polling_officers_controller.rb +17 -0
  111. data/app/controllers/decidim/votings/polling_officer_zone/polling_stations_controller.rb +22 -0
  112. data/app/controllers/decidim/votings/votings_controller.rb +98 -0
  113. data/app/events/decidim/elections/trustees/notify_new_trustee_event.rb +28 -0
  114. data/app/events/decidim/elections/trustees/notify_trustee_new_election_event.rb +14 -0
  115. data/app/events/decidim/elections/votes/vote_accepted_event.rb +24 -0
  116. data/app/events/decidim/votings/polling_officers/polling_station_assigned_event.rb +44 -0
  117. data/app/forms/decidim/elections/admin/action_form.rb +34 -0
  118. data/app/forms/decidim/elections/admin/answer_form.rb +3 -2
  119. data/app/forms/decidim/elections/admin/election_form.rb +3 -2
  120. data/app/forms/decidim/elections/admin/setup_form.rb +79 -0
  121. data/app/forms/decidim/elections/admin/trustees_participatory_space_form.rb +22 -0
  122. data/app/forms/decidim/elections/admin/vote_period_form.rb +37 -0
  123. data/app/forms/decidim/elections/ballot/verify_vote_form.rb +29 -0
  124. data/app/forms/decidim/elections/trustee_zone/trustee_form.rb +26 -0
  125. data/app/forms/decidim/elections/voter/encrypted_vote_form.rb +49 -0
  126. data/app/forms/decidim/votings/admin/monitoring_committee_member_form.rb +27 -0
  127. data/app/forms/decidim/votings/admin/polling_officer_form.rb +27 -0
  128. data/app/forms/decidim/votings/admin/polling_station_form.rb +58 -0
  129. data/app/forms/decidim/votings/admin/voting_form.rb +71 -0
  130. data/app/helpers/decidim/elections/admin/answers_helper.rb +19 -0
  131. data/app/helpers/decidim/elections/admin/steps_helper.rb +23 -0
  132. data/app/helpers/decidim/elections/admin/trustees_participatory_spaces_helper.rb +31 -0
  133. data/app/helpers/decidim/elections/elections_helper.rb +29 -0
  134. data/app/helpers/decidim/votings/admin/polling_officers_picker_helper.rb +29 -0
  135. data/app/helpers/decidim/votings/votings_helper.rb +20 -0
  136. data/app/models/decidim/elections/action.rb +13 -0
  137. data/app/models/decidim/elections/election.rb +54 -3
  138. data/app/models/decidim/elections/elections_trustee.rb +11 -0
  139. data/app/models/decidim/elections/question.rb +19 -0
  140. data/app/models/decidim/elections/trustee.rb +26 -0
  141. data/app/models/decidim/elections/trustees_participatory_space.rb +13 -0
  142. data/app/models/decidim/elections/vote.rb +15 -0
  143. data/app/models/decidim/votings/monitoring_committee_member.rb +24 -0
  144. data/app/models/decidim/votings/polling_officer.rb +76 -0
  145. data/app/models/decidim/votings/polling_station.rb +64 -0
  146. data/app/models/decidim/votings/voting.rb +138 -0
  147. data/app/permissions/decidim/elections/admin/permissions.rb +50 -10
  148. data/app/permissions/decidim/elections/permissions.rb +20 -2
  149. data/app/permissions/decidim/elections/trustee_zone/permissions.rb +32 -0
  150. data/app/permissions/decidim/votings/admin/permissions.rb +127 -0
  151. data/app/permissions/decidim/votings/permissions.rb +40 -0
  152. data/app/permissions/decidim/votings/polling_officer_zone/permissions.rb +32 -0
  153. data/app/presenters/decidim/elections/admin_log/election_presenter.rb +1 -1
  154. data/app/presenters/decidim/elections/trustee_presenter.rb +24 -0
  155. data/app/presenters/decidim/votings/admin_log/voting_presenter.rb +45 -0
  156. data/app/presenters/decidim/votings/polling_station_presenter.rb +27 -0
  157. data/app/presenters/decidim/votings/voting_presenter.rb +36 -0
  158. data/app/queries/decidim/elections/admin/pending_actions.rb +20 -0
  159. data/app/queries/decidim/elections/admin/votes_for_statistics.rb +24 -0
  160. data/app/queries/decidim/elections/elections_finished_to_end.rb +19 -0
  161. data/app/queries/decidim/elections/elections_ready_to_start.rb +25 -0
  162. data/app/queries/decidim/elections/trustees/by_participatory_space.rb +24 -0
  163. data/app/queries/decidim/elections/trustees/by_participatory_space_trustee_ids.rb +24 -0
  164. data/app/queries/decidim/elections/votes/election_votes.rb +19 -0
  165. data/app/queries/decidim/elections/votes/pending_votes.rb +20 -0
  166. data/app/queries/decidim/elections/votes/user_election_last_vote.rb +26 -0
  167. data/app/queries/decidim/elections/votes/user_votes.rb +19 -0
  168. data/app/queries/decidim/votings/admin/admin_users.rb +39 -0
  169. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb +33 -0
  170. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations_and_user.rb +34 -0
  171. data/app/queries/decidim/votings/admin/polling_officers_join_user.rb +32 -0
  172. data/app/queries/decidim/votings/organization_prioritized_votings.rb +21 -0
  173. data/app/queries/decidim/votings/organization_promoted_votings.rb +16 -0
  174. data/app/queries/decidim/votings/organization_published_votings.rb +19 -0
  175. data/app/queries/decidim/votings/organization_votings.rb +16 -0
  176. data/app/queries/decidim/votings/prioritized_votings.rb +13 -0
  177. data/app/queries/decidim/votings/published_votings.rb +12 -0
  178. data/app/services/decidim/votings/voting_search.rb +46 -0
  179. data/app/views/decidim/elections/admin/answers/index.html.erb +12 -0
  180. data/app/views/decidim/elections/admin/elections/index.html.erb +13 -1
  181. data/app/views/decidim/elections/admin/proposals_imports/new.html.erb +1 -1
  182. data/app/views/decidim/elections/admin/questions/index.html.erb +5 -1
  183. data/app/views/decidim/elections/admin/shared/_trustees_secondary_nav.html.erb +3 -0
  184. data/app/views/decidim/elections/admin/steps/_create_election.html.erb +38 -0
  185. data/app/views/decidim/elections/admin/steps/_created.html.erb +16 -0
  186. data/app/views/decidim/elections/admin/steps/_key_ceremony.html.erb +16 -0
  187. data/app/views/decidim/elections/admin/steps/_key_ceremony_ended.html.erb +15 -0
  188. data/app/views/decidim/elections/admin/steps/_tally.html.erb +17 -0
  189. data/app/views/decidim/elections/admin/steps/_tally_ended.html.erb +9 -0
  190. data/app/views/decidim/elections/admin/steps/_vote.html.erb +21 -0
  191. data/app/views/decidim/elections/admin/steps/_vote_ended.html.erb +15 -0
  192. data/app/views/decidim/elections/admin/steps/_vote_stats.html.erb +31 -0
  193. data/app/views/decidim/elections/admin/steps/index.html.erb +43 -0
  194. data/app/views/decidim/elections/admin/trustees_participatory_spaces/_form.html.erb +19 -0
  195. data/app/views/decidim/elections/admin/trustees_participatory_spaces/index.html.erb +64 -0
  196. data/app/views/decidim/elections/admin/trustees_participatory_spaces/new.html.erb +7 -0
  197. data/app/views/decidim/elections/elections/_filters_small_view.html.erb +1 -1
  198. data/app/views/decidim/elections/elections/_preview.html.erb +26 -0
  199. data/app/views/decidim/elections/elections/_results.html.erb +47 -0
  200. data/app/views/decidim/elections/elections/show.html.erb +43 -18
  201. data/app/views/decidim/elections/trustee_zone/elections/_backup_modal.html.erb +24 -0
  202. data/app/views/decidim/elections/trustee_zone/elections/_key_ceremony_steps.html.erb +44 -0
  203. data/app/views/decidim/elections/trustee_zone/elections/_restore_modal.html.erb +25 -0
  204. data/app/views/decidim/elections/trustee_zone/elections/_tally_steps.html.erb +43 -0
  205. data/app/views/decidim/elections/trustee_zone/elections/show.html.erb +38 -0
  206. data/app/views/decidim/elections/trustee_zone/elections/update.js.erb +5 -0
  207. data/app/views/decidim/elections/trustee_zone/trustees/show.html.erb +102 -0
  208. data/app/views/decidim/elections/votes/_election_votes_confirmed.html.erb +38 -17
  209. data/app/views/decidim/elections/votes/_election_votes_failed.html.erb +21 -0
  210. data/app/views/decidim/elections/votes/_election_votes_question.html.erb +4 -4
  211. data/app/views/decidim/elections/votes/cast_failed.js.erb +1 -0
  212. data/app/views/decidim/elections/votes/cast_success.js.erb +1 -0
  213. data/app/views/decidim/elections/votes/new.html.erb +41 -33
  214. data/app/views/decidim/elections/votes/verify.html.erb +78 -0
  215. data/app/views/decidim/votings/admin/monitoring_committee_members/_form.html.erb +27 -0
  216. data/app/views/decidim/votings/admin/monitoring_committee_members/index.html.erb +41 -0
  217. data/app/views/decidim/votings/admin/monitoring_committee_members/new.html.erb +7 -0
  218. data/app/views/decidim/votings/admin/polling_officers/_form.html.erb +27 -0
  219. data/app/views/decidim/votings/admin/polling_officers/index.html.erb +50 -0
  220. data/app/views/decidim/votings/admin/polling_officers/new.html.erb +7 -0
  221. data/app/views/decidim/votings/admin/polling_stations/_form.html.erb +40 -0
  222. data/app/views/decidim/votings/admin/polling_stations/edit.html.erb +7 -0
  223. data/app/views/decidim/votings/admin/polling_stations/index.html.erb +55 -0
  224. data/app/views/decidim/votings/admin/polling_stations/new.html.erb +7 -0
  225. data/app/views/decidim/votings/admin/votings/_form.html.erb +63 -0
  226. data/app/views/decidim/votings/admin/votings/edit.html.erb +31 -0
  227. data/app/views/decidim/votings/admin/votings/index.html.erb +87 -0
  228. data/app/views/decidim/votings/admin/votings/new.html.erb +13 -0
  229. data/app/views/decidim/votings/admin/votings/polling_officers_picker.html.erb +2 -0
  230. data/app/views/decidim/votings/polling_officer_zone/polling_officers/show.html.erb +42 -0
  231. data/app/views/decidim/votings/polling_officer_zone/polling_stations/show.html.erb +1 -0
  232. data/app/views/decidim/votings/votings/_count.html.erb +1 -0
  233. data/app/views/decidim/votings/votings/_filters.html.erb +25 -0
  234. data/app/views/decidim/votings/votings/_filters_small_view.html.erb +23 -0
  235. data/app/views/decidim/votings/votings/_promoted_voting.html.erb +27 -0
  236. data/app/views/decidim/votings/votings/_voting_details.html.erb +7 -0
  237. data/app/views/decidim/votings/votings/_votings.html.erb +25 -0
  238. data/app/views/decidim/votings/votings/index.html.erb +42 -0
  239. data/app/views/decidim/votings/votings/index.js.erb +10 -0
  240. data/app/views/decidim/votings/votings/show.html.erb +20 -0
  241. data/app/views/layouts/decidim/_voting_header.html.erb +16 -0
  242. data/app/views/layouts/decidim/admin/voting.html.erb +101 -0
  243. data/app/views/layouts/decidim/voting.html.erb +16 -0
  244. data/config/initializers/decidim_bulletin_board.rb +23 -0
  245. data/config/locales/ca.yml +650 -20
  246. data/config/locales/cs.yml +644 -6
  247. data/config/locales/de.yml +636 -6
  248. data/config/locales/el.yml +0 -2
  249. data/config/locales/en.yml +636 -6
  250. data/config/locales/es-MX.yml +636 -6
  251. data/config/locales/es-PY.yml +636 -6
  252. data/config/locales/es.yml +646 -16
  253. data/config/locales/fi-plain.yml +636 -6
  254. data/config/locales/fi.yml +636 -6
  255. data/config/locales/fr-CA.yml +423 -6
  256. data/config/locales/fr.yml +423 -6
  257. data/config/locales/gl.yml +85 -7
  258. data/config/locales/it.yml +94 -6
  259. data/config/locales/ja.yml +8 -6
  260. data/config/locales/lv.yml +0 -2
  261. data/config/locales/nl.yml +503 -6
  262. data/config/locales/no.yml +2 -5
  263. data/config/locales/pl.yml +644 -6
  264. data/config/locales/pt.yml +0 -6
  265. data/config/locales/ro-RO.yml +176 -6
  266. data/config/locales/sv.yml +257 -6
  267. data/config/locales/tr-TR.yml +111 -6
  268. data/config/locales/zh-CN.yml +0 -6
  269. data/db/migrate/20200915142713_add_questionnaire_to_existing_elections.rb +29 -0
  270. data/db/migrate/20200918153813_create_decidim_elections_trustees_participatory_spaces.rb +13 -0
  271. data/db/migrate/20200918153824_create_decidim_elections_elections_trustees.rb +10 -0
  272. data/db/migrate/20200918153835_create_decidim_elections_trustees.rb +12 -0
  273. data/db/migrate/20201026163334_add_blocked_at_and_bb_status_to_elections.rb +8 -0
  274. data/db/migrate/20201028090110_add_votes_to_decidim_elections_answers.rb +7 -0
  275. data/db/migrate/20201028135614_add_selected_to_decidim_elections_answers.rb +7 -0
  276. data/db/migrate/20201209110653_create_decidim_elections_votes.rb +14 -0
  277. data/db/migrate/20201216091123_add_name_to_trustees.rb +7 -0
  278. data/db/migrate/20210113113818_add_message_id_to_decidim_elections_votes.rb +7 -0
  279. data/db/migrate/20210113120115_create_decidim_elections_votings.rb +20 -0
  280. data/db/migrate/20210114100749_add_published_at_to_decidim_votings_votings.rb +7 -0
  281. data/db/migrate/20210114111850_add_user_to_decidim_elections_votes.rb +7 -0
  282. data/db/migrate/20210120164634_add_promoted_to_voting.rb +7 -0
  283. data/db/migrate/20210125124801_add_voting_type_to_voting_voting.rb +7 -0
  284. data/db/migrate/20210129124956_create_decidim_elections_actions.rb +14 -0
  285. data/db/migrate/20210204132111_add_votings_polling_stations.rb +19 -0
  286. data/db/migrate/20210208090441_add_polling_officers_to_votings.rb +12 -0
  287. data/db/migrate/20210210090738_add_votings_polling_station_references_to_votings_polling_officer.rb +8 -0
  288. data/db/migrate/20210216074707_add_monitoring_committee_member.rb +12 -0
  289. data/db/migrate/20210310120708_add_followable_counter_cache_to_votings.rb +16 -0
  290. data/db/seeds/city.jpeg +0 -0
  291. data/lib/decidim/api/election_answer_type.rb +23 -0
  292. data/lib/decidim/api/election_question_type.rb +22 -0
  293. data/lib/decidim/api/election_type.rb +27 -0
  294. data/lib/decidim/api/elections_type.rb +32 -0
  295. data/lib/decidim/api/trustee_type.rb +16 -0
  296. data/lib/decidim/api/voting_type.rb +20 -0
  297. data/lib/decidim/elections.rb +19 -2
  298. data/lib/decidim/elections/admin_engine.rb +42 -1
  299. data/lib/decidim/elections/answer_serializer.rb +48 -0
  300. data/lib/decidim/elections/api.rb +11 -0
  301. data/lib/decidim/elections/component.rb +367 -24
  302. data/lib/decidim/elections/engine.rb +8 -1
  303. data/lib/decidim/elections/test/factories.rb +201 -4
  304. data/lib/decidim/elections/trustee_zone.rb +10 -0
  305. data/lib/decidim/elections/trustee_zone_engine.rb +35 -0
  306. data/lib/decidim/elections/version.rb +1 -1
  307. data/lib/decidim/votings.rb +16 -0
  308. data/lib/decidim/votings/admin.rb +10 -0
  309. data/lib/decidim/votings/admin_engine.rb +71 -0
  310. data/lib/decidim/votings/api.rb +7 -0
  311. data/lib/decidim/votings/engine.rb +147 -0
  312. data/lib/decidim/votings/participatory_space.rb +92 -0
  313. data/lib/decidim/votings/polling_officer_zone.rb +10 -0
  314. data/lib/decidim/votings/polling_officer_zone_engine.rb +33 -0
  315. data/lib/decidim/votings/query_extensions.rb +43 -0
  316. data/lib/decidim/votings/test/capybara_polling_officers_picker.rb +49 -0
  317. data/lib/decidim/votings/test/factories.rb +83 -0
  318. data/lib/decidim/votings/voting_serializer.rb +54 -0
  319. data/lib/tasks/decidim_elections.rake +68 -5
  320. metadata +303 -19
  321. data/app/types/decidim/elections/election_answer_type.rb +0 -24
  322. data/app/types/decidim/elections/election_question_type.rb +0 -25
  323. data/app/types/decidim/elections/election_type.rb +0 -27
  324. data/app/types/decidim/elections/elections_type.rb +0 -32
  325. data/config/i18n-tasks.yml +0 -10
  326. data/lib/decidim/elections/bulletin_board_client.rb +0 -35
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Votings
5
+ # This cell renders the card for an instance of a Voting
6
+ # the default size is the Medium Card (:m)
7
+ class VotingCell < Decidim::ViewModel
8
+ def show
9
+ cell card_size, model, options
10
+ end
11
+
12
+ private
13
+
14
+ def card_size
15
+ "decidim/votings/voting_m"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ <div class="card__icondata">
2
+ <ul class="card-data">
3
+ <li class="card-data__item">
4
+ <%= icon "datetime", class: "icon--big", role: "img", aria_label: t("decidim.votings.votings.show.dates") %>
5
+ </li>
6
+ <li class="card-data__item">
7
+ <div class="card-data__item--centerblock">
8
+ <strong><%= t("activemodel.attributes.voting.start_time") %></strong>
9
+ <br>
10
+ <%= start_time ? l(start_time, format: :decidim_short) : t("decidim.votings.votings_m.unspecified") %>
11
+ </div>
12
+ </li>
13
+ <li class="card-data__item">
14
+ <div class="card-data__item--centerblock">
15
+ <strong><%= t("activemodel.attributes.voting.end_time") %></strong>
16
+ <br>
17
+ <%= end_time ? l(end_time, format: :decidim_short) : t("decidim.votings.votings_m.unspecified") %>
18
+ </div>
19
+ </li>
20
+ </ul>
21
+ </div>
@@ -0,0 +1,5 @@
1
+ <div class="card__footer card__footer--spaces">
2
+ <div class="card__support">
3
+ <%= link_to footer_button_text, resource_path, class: "card__button button--sc light button small" %>
4
+ </div>
5
+ </div>
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Votings
5
+ # This cell renders the Medium (:m) voting card
6
+ # for an given instance of a Voting
7
+ class VotingMCell < Decidim::CardMCell
8
+ private
9
+
10
+ def has_state?
11
+ true
12
+ end
13
+
14
+ def state_classes
15
+ if model.upcoming?
16
+ ["warning"]
17
+ elsif model.active?
18
+ ["success"]
19
+ else
20
+ ["muted"]
21
+ end
22
+ end
23
+
24
+ # Even though we need to render the badge, we can't do it in the normal
25
+ # way, because the paragraph comes from a user input and contains HTML.
26
+ # This causes the badge and the paragraph to appear in different lines.
27
+ # In order to fix it, check the `description` method.
28
+ def has_badge?
29
+ false
30
+ end
31
+
32
+ def badge_name
33
+ text = model.period_status
34
+ return unless text
35
+
36
+ I18n.t(text, scope: "decidim.votings.votings_m.badge_name")
37
+ end
38
+
39
+ # In order to render the badge inline with the paragraph text we need to
40
+ # find the opening `<p>` tag and include the badge right after it. This
41
+ # makes the layout look good.
42
+ def description
43
+ text = super
44
+ text.gsub!(/^<p>/, "<p>#{render :badge}")
45
+ html_truncate(text, length: 100)
46
+ end
47
+
48
+ def resource_path
49
+ Decidim::Votings::Engine.routes.url_helpers.voting_path(model)
50
+ end
51
+
52
+ def resource_image_path
53
+ model.banner_image.url
54
+ end
55
+
56
+ def has_image?
57
+ model.banner_image.url.present?
58
+ end
59
+
60
+ def start_time
61
+ model.start_time
62
+ end
63
+
64
+ def end_time
65
+ model.end_time
66
+ end
67
+
68
+ def statuses
69
+ [:voting_type, :follow]
70
+ end
71
+
72
+ def voting_type_status
73
+ content = content_tag(:strong, t(:voting_types_label, scope: "decidim.votings.votings_m"))
74
+ content << if model.hybrid_voting?
75
+ t(:hybrid, scope: "decidim.votings.votings_m.voting_type")
76
+ elsif model.in_person_voting?
77
+ t(:in_person, scope: "decidim.votings.votings_m.voting_type")
78
+ else
79
+ t(:online, scope: "decidim.votings.votings_m.voting_type")
80
+ end
81
+ end
82
+
83
+ def footer_button_text
84
+ if model.active?
85
+ t(:vote, scope: "decidim.votings.votings_m.footer_button_text")
86
+ elsif model.upcoming?
87
+ t(:participate, scope: "decidim.votings.votings_m.footer_button_text")
88
+ elsif model.finished?
89
+ t(:view, scope: "decidim.votings.votings_m.footer_button_text")
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Elections
5
+ module Admin
6
+ # This command is executed when the admin user creates a trustee
7
+ # from the admin panel.
8
+ class AddUserAsTrustee < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - A form object with the params.
12
+ def initialize(form, current_user)
13
+ @form = form
14
+ @current_user = current_user
15
+ end
16
+
17
+ # Creates the trustee if valid.
18
+ #
19
+ # Broadcasts :ok if successful, :invalid otherwise.
20
+ def call
21
+ return broadcast(:invalid) if form.invalid?
22
+ return broadcast(:exists) if existing_trustee_participatory_spaces?
23
+
24
+ transaction do
25
+ add_user_as_trustee! if new_trustee?
26
+ add_participatory_space
27
+ notify_user_about_trustee_role if new_trustee?
28
+ end
29
+
30
+ broadcast(:ok)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :form, :current_user, :trustee
36
+
37
+ def add_user_as_trustee!
38
+ @trustee = Decidim.traceability.create!(
39
+ Trustee,
40
+ form.current_user,
41
+ user: form.user
42
+ )
43
+ end
44
+
45
+ # If a trustee exists for this participatory space, it won't get created again
46
+ def existing_trustee_participatory_spaces?
47
+ trustees_space = TrusteesParticipatorySpace.where(participatory_space: form.current_participatory_space).includes(:trustee)
48
+ @existing_trustee_participatory_spaces ||= Decidim::Elections::Trustee.joins(:trustees_participatory_spaces)
49
+ .includes([:user])
50
+ .where(trustees_participatory_spaces: trustees_space)
51
+ .where(decidim_user_id: form.user.id).any?
52
+ end
53
+
54
+ # if there's no user - trustee relation, the trustee gets created and the notification
55
+ # gets send.
56
+ def new_trustee?
57
+ return @new_trustee if defined?(@new_trustee)
58
+
59
+ @new_trustee = Decidim::Elections::Trustee.where(decidim_user_id: form.user.id).empty?
60
+ end
61
+
62
+ def add_participatory_space
63
+ trustee = Decidim::Elections::Trustee.find_by(decidim_user_id: form.user.id)
64
+ trustee.trustees_participatory_spaces.create!(
65
+ participatory_space: form.current_participatory_space
66
+ )
67
+ end
68
+
69
+ def notify_user_about_trustee_role
70
+ data = {
71
+ event: "decidim.events.elections.trustees.new_trustee",
72
+ event_class: Decidim::Elections::Trustees::NotifyNewTrusteeEvent,
73
+ resource: form.current_participatory_space,
74
+ affected_users: [form.user]
75
+ }
76
+ Decidim::EventsManager.publish(data)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -42,7 +42,8 @@ module Decidim
42
42
  description: form.description,
43
43
  start_time: form.start_time,
44
44
  end_time: form.end_time,
45
- component: form.current_component
45
+ component: form.current_component,
46
+ questionnaire: Decidim::Forms::Questionnaire.new
46
47
  }
47
48
 
48
49
  @election = Decidim.traceability.create!(
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Elections
5
+ module Admin
6
+ # This command gets called to end the voting period in the Bulletin Board.
7
+ class EndVote < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A VotePeriodForm object with the information needed to start or end the vote period
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Public: Ends the voting period for the Election.
16
+ #
17
+ # Broadcasts :ok if setup, :invalid otherwise.
18
+ def call
19
+ return broadcast(:invalid) if form.invalid?
20
+
21
+ transaction do
22
+ log_action
23
+ end_vote
24
+ end
25
+
26
+ broadcast(:ok)
27
+ rescue StandardError => e
28
+ broadcast(:invalid, e.message)
29
+ end
30
+
31
+ private
32
+
33
+ attr_accessor :form
34
+
35
+ delegate :election, :bulletin_board, to: :form
36
+
37
+ def log_action
38
+ Decidim.traceability.perform_action!(
39
+ :end_vote,
40
+ election,
41
+ form.current_user,
42
+ visibility: "all"
43
+ )
44
+ end
45
+
46
+ def end_vote
47
+ bulletin_board.end_vote(election.id) do |message_id|
48
+ create_election_action(message_id)
49
+ end
50
+ end
51
+
52
+ def create_election_action(message_id)
53
+ Decidim::Elections::Action.create!(
54
+ election: election,
55
+ action: :end_vote,
56
+ message_id: message_id,
57
+ status: :pending
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Elections
5
+ module Admin
6
+ # This command gets called to publish the election results in the Bulletin Board.
7
+ class PublishResults < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - An ActionForm object with the information needed to publish the results
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Public: Publish the results for the Election.
16
+ #
17
+ # Broadcasts :ok if setup, :invalid otherwise.
18
+ def call
19
+ return broadcast(:invalid) if form.invalid?
20
+
21
+ transaction do
22
+ log_action
23
+ update_election
24
+ publish_results
25
+ end
26
+
27
+ broadcast(:ok)
28
+ rescue StandardError => e
29
+ broadcast(:invalid, e.message)
30
+ end
31
+
32
+ private
33
+
34
+ attr_accessor :form
35
+
36
+ delegate :election, :bulletin_board, to: :form
37
+
38
+ def log_action
39
+ Decidim.traceability.perform_action!(
40
+ :publish_results,
41
+ election,
42
+ form.current_user,
43
+ visibility: "all"
44
+ )
45
+ end
46
+
47
+ def publish_results
48
+ bb_election = bulletin_board.publish_results(election.id)
49
+
50
+ raise StandardError, "Wrong status for the election with published results" if bb_election.status != "results_published"
51
+ end
52
+
53
+ def update_election
54
+ election.bb_results_published!
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Elections
5
+ module Admin
6
+ # This command is executed when the admin user removes a trustee
7
+ # from a participatory space from the admin panel.
8
+ class RemoveTrusteeFromParticipatorySpace < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # trustee_participatory_space - A trustee_participatory_space
12
+ def initialize(trustee_participatory_space)
13
+ @trustee_participatory_space = trustee_participatory_space
14
+ end
15
+
16
+ # Removes the trustee from participatory space if valid.
17
+ #
18
+ # Broadcasts :ok if successful, :invalid otherwise.
19
+ def call
20
+ return broadcast(:invalid) if !trustee_participatory_space || trustee_participatory_space.trustee.elections.any?
21
+
22
+ remove_trustee_from_participatory_space!
23
+
24
+ broadcast(:ok, trustee_participatory_space.trustee)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :trustee_participatory_space
30
+
31
+ def remove_trustee_from_participatory_space!
32
+ trustee_participatory_space.trustee.delete
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Elections
5
+ module Admin
6
+ # This command gets called when a election is setup from the admin panel.
7
+ class SetupElection < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A SetupForm object with the information needed to setup the election
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Public: Setup the Election.
16
+ #
17
+ # Broadcasts :ok if setup, :invalid otherwise.
18
+ def call
19
+ return broadcast(:invalid) if form.invalid?
20
+
21
+ transaction do
22
+ log_action
23
+ update_election
24
+ notify_trustee_about_election
25
+ setup_election
26
+ end
27
+
28
+ broadcast(:ok, election)
29
+ rescue StandardError => e
30
+ broadcast(:invalid, e.message)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :form
36
+
37
+ delegate :election, :bulletin_board, :current_organization, to: :form
38
+
39
+ def questions
40
+ @questions ||= election.questions
41
+ end
42
+
43
+ def answers
44
+ Decidim::Elections::Answer.where(question: questions)
45
+ end
46
+
47
+ def trustees
48
+ @trustees ||= Decidim::Elections::Trustee.where(id: form.trustee_ids).order(:id)
49
+ end
50
+
51
+ def update_election
52
+ return if election.trustees.exists?(id: form.trustee_ids)
53
+
54
+ election.trustees << trustees
55
+ election.blocked_at = Time.current
56
+ election.bb_created!
57
+ end
58
+
59
+ def election_data
60
+ {
61
+ iat: Time.current.to_i,
62
+ scheme: bulletin_board.scheme,
63
+ authority: {
64
+ name: bulletin_board.authority_name,
65
+ public_key: bulletin_board.public_key
66
+ },
67
+ trustees:
68
+ trustees.collect do |trustee|
69
+ {
70
+ name: trustee.name,
71
+ public_key: trustee.public_key
72
+ }
73
+ end,
74
+ description: {
75
+ name: {
76
+ text: [{
77
+ value: election.title[current_organization.default_locale.to_s],
78
+ language: current_organization.default_locale.to_s
79
+ }]
80
+ },
81
+ start_date: election.start_time,
82
+ end_date: election.end_time,
83
+ candidates:
84
+ answers.collect do |answer|
85
+ {
86
+ object_id: answer.id.to_s,
87
+ ballot_name: {
88
+ text: [{
89
+ value: answer.title[current_organization.default_locale.to_s],
90
+ language: current_organization.default_locale.to_s
91
+ }]
92
+ }
93
+ }
94
+ end,
95
+ contests:
96
+ questions.collect do |question|
97
+ {
98
+ "@type": "CandidateContest",
99
+ object_id: question.id.to_s,
100
+ sequence_order: question.weight,
101
+ vote_variation: question.vote_variation,
102
+ name: question.title[current_organization.default_locale.to_s],
103
+ number_elected: question.answers.count,
104
+ votes_allowed: 1,
105
+ ballot_title: {
106
+ text: [{
107
+ value: question.title[current_organization.default_locale.to_s],
108
+ language: current_organization.default_locale.to_s
109
+ }]
110
+ },
111
+ ballot_subtitle: {
112
+ text: [{
113
+ value: question.description[current_organization.default_locale.to_s],
114
+ language: current_organization.default_locale.to_s
115
+ }]
116
+ },
117
+ ballot_selections:
118
+ question.answers.collect do |answer|
119
+ {
120
+ object_id: answer.id.to_s,
121
+ sequence_order: answer.weight,
122
+ candidate_id: answer.id.to_s
123
+ }
124
+ end
125
+ }
126
+ end
127
+ }
128
+ }.to_h
129
+ end
130
+
131
+ def setup_election
132
+ bb_election = bulletin_board.create_election(election.id, election_data)
133
+
134
+ raise StandardError, "Wrong status for the created election" if bb_election.status != "created"
135
+ end
136
+
137
+ def log_action
138
+ Decidim.traceability.perform_action!(
139
+ :setup,
140
+ election,
141
+ form.current_user,
142
+ visibility: "all"
143
+ )
144
+ end
145
+
146
+ def notify_trustee_about_election
147
+ trustee = trustees.collect(&:user)
148
+ data = {
149
+ event: "decidim.events.elections.trustees.new_election",
150
+ event_class: Decidim::Elections::Trustees::NotifyTrusteeNewElectionEvent,
151
+ resource: election,
152
+ affected_users: trustee
153
+ }
154
+
155
+ Decidim::EventsManager.publish(data)
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end