decidim-elections 0.26.2 → 0.27.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/cells/decidim/votings/content_blocks/highlighted_votings/show.erb +2 -2
  4. data/app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb +1 -4
  5. data/app/cells/decidim/votings/content_blocks/landing_page/description/show.erb +1 -1
  6. data/app/cells/decidim/votings/content_blocks/landing_page/header/show.erb +2 -2
  7. data/app/cells/decidim/votings/content_blocks/landing_page/header_cell.rb +1 -1
  8. data/app/commands/decidim/elections/admin/add_user_as_trustee.rb +1 -1
  9. data/app/commands/decidim/elections/admin/create_answer.rb +1 -1
  10. data/app/commands/decidim/elections/admin/create_election.rb +1 -1
  11. data/app/commands/decidim/elections/admin/create_question.rb +1 -2
  12. data/app/commands/decidim/elections/admin/destroy_answer.rb +1 -1
  13. data/app/commands/decidim/elections/admin/destroy_election.rb +1 -1
  14. data/app/commands/decidim/elections/admin/destroy_question.rb +1 -1
  15. data/app/commands/decidim/elections/admin/end_vote.rb +1 -1
  16. data/app/commands/decidim/elections/admin/import_proposals_to_elections.rb +1 -1
  17. data/app/commands/decidim/elections/admin/publish_election.rb +1 -1
  18. data/app/commands/decidim/elections/admin/publish_results.rb +1 -1
  19. data/app/commands/decidim/elections/admin/remove_trustee_from_participatory_space.rb +1 -1
  20. data/app/commands/decidim/elections/admin/report_missing_trustee.rb +1 -1
  21. data/app/commands/decidim/elections/admin/setup_election.rb +4 -2
  22. data/app/commands/decidim/elections/admin/start_key_ceremony.rb +1 -1
  23. data/app/commands/decidim/elections/admin/start_tally.rb +1 -1
  24. data/app/commands/decidim/elections/admin/start_vote.rb +1 -1
  25. data/app/commands/decidim/elections/admin/unpublish_election.rb +1 -1
  26. data/app/commands/decidim/elections/admin/update_action_status.rb +1 -1
  27. data/app/commands/decidim/elections/admin/update_answer.rb +1 -1
  28. data/app/commands/decidim/elections/admin/update_answer_selection.rb +1 -1
  29. data/app/commands/decidim/elections/admin/update_election.rb +1 -1
  30. data/app/commands/decidim/elections/admin/update_question.rb +1 -2
  31. data/app/commands/decidim/elections/admin/update_trustee_participatory_space.rb +1 -1
  32. data/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb +1 -1
  33. data/app/commands/decidim/elections/trustee_zone/update_trustee.rb +1 -1
  34. data/app/commands/decidim/elections/voter/cast_vote.rb +1 -1
  35. data/app/commands/decidim/elections/voter/update_vote_status.rb +2 -2
  36. data/app/commands/decidim/votings/admin/create_ballot_style.rb +1 -1
  37. data/app/commands/decidim/votings/admin/create_monitoring_committee_member.rb +1 -1
  38. data/app/commands/decidim/votings/admin/create_polling_officer.rb +1 -1
  39. data/app/commands/decidim/votings/admin/create_voting.rb +3 -2
  40. data/app/commands/decidim/votings/admin/destroy_ballot_style.rb +1 -1
  41. data/app/commands/decidim/votings/admin/destroy_monitoring_committee_member.rb +1 -1
  42. data/app/commands/decidim/votings/admin/destroy_polling_officer.rb +1 -1
  43. data/app/commands/decidim/votings/admin/destroy_polling_station.rb +1 -1
  44. data/app/commands/decidim/votings/admin/manage_polling_station.rb +2 -2
  45. data/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb +1 -1
  46. data/app/commands/decidim/votings/admin/publish_voting.rb +1 -1
  47. data/app/commands/decidim/votings/admin/unpublish_voting.rb +1 -1
  48. data/app/commands/decidim/votings/admin/update_ballot_style.rb +1 -1
  49. data/app/commands/decidim/votings/admin/update_voting.rb +3 -2
  50. data/app/commands/decidim/votings/census/admin/create_dataset.rb +32 -21
  51. data/app/commands/decidim/votings/census/admin/create_datum.rb +1 -1
  52. data/app/commands/decidim/votings/census/admin/destroy_dataset.rb +1 -1
  53. data/app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb +1 -1
  54. data/app/commands/decidim/votings/census/admin/launch_access_codes_export.rb +4 -2
  55. data/app/commands/decidim/votings/census/admin/launch_access_codes_generation.rb +2 -2
  56. data/app/commands/decidim/votings/census/admin/update_dataset.rb +1 -1
  57. data/app/commands/decidim/votings/certify_polling_station_closure.rb +1 -1
  58. data/app/commands/decidim/votings/check_census.rb +1 -1
  59. data/app/commands/decidim/votings/create_polling_station_closure.rb +1 -1
  60. data/app/commands/decidim/votings/create_polling_station_results.rb +1 -1
  61. data/app/commands/decidim/votings/send_access_code.rb +1 -1
  62. data/app/commands/decidim/votings/sign_polling_station_closure.rb +1 -1
  63. data/app/commands/decidim/votings/voter/in_person_vote.rb +1 -1
  64. data/app/commands/decidim/votings/voter/update_in_person_vote_status.rb +1 -1
  65. data/app/controllers/decidim/elections/admin/steps_controller.rb +2 -2
  66. data/app/controllers/decidim/elections/elections_controller.rb +10 -12
  67. data/app/controllers/decidim/elections/trustee_zone/elections_controller.rb +1 -1
  68. data/app/controllers/decidim/votings/census/admin/census_controller.rb +6 -2
  69. data/app/controllers/decidim/votings/votings_controller.rb +10 -13
  70. data/app/forms/decidim/elections/admin/question_form.rb +0 -2
  71. data/app/forms/decidim/elections/admin/setup_form.rb +46 -3
  72. data/app/forms/decidim/elections/admin/vote_period_form.rb +2 -2
  73. data/app/forms/decidim/votings/admin/ballot_style_form.rb +1 -1
  74. data/app/forms/decidim/votings/admin/voting_form.rb +4 -3
  75. data/app/forms/decidim/votings/census/admin/dataset_form.rb +2 -5
  76. data/app/forms/decidim/votings/census/admin/datum_form.rb +1 -1
  77. data/app/helpers/decidim/elections/application_helper.rb +1 -1
  78. data/app/helpers/decidim/votings/votings_helper.rb +1 -1
  79. data/app/models/decidim/elections/answer.rb +1 -6
  80. data/app/models/decidim/elections/election.rb +15 -4
  81. data/app/models/decidim/elections/question.rb +2 -7
  82. data/app/models/decidim/votings/census/dataset.rb +1 -1
  83. data/app/models/decidim/votings/polling_station.rb +2 -3
  84. data/app/models/decidim/votings/voting.rb +15 -0
  85. data/app/packs/entrypoints/{decidim_elections_trustee_tally.js → decidim_elections_trustee_tally_started.js} +0 -0
  86. data/app/packs/src/decidim/elections/admin/pending_action.js +2 -0
  87. data/app/packs/src/decidim/elections/admin/trustees_process.js +2 -0
  88. data/app/packs/src/decidim/elections/broken_promises_handler.js +11 -0
  89. data/app/packs/src/decidim/elections/trustee/key_ceremony.js +3 -0
  90. data/app/packs/src/decidim/elections/trustee/tally.js +4 -1
  91. data/app/packs/src/decidim/elections/voter/casting-vote.js +3 -0
  92. data/app/packs/src/decidim/elections/voter/setup-vote.js +3 -0
  93. data/app/packs/src/decidim/votings/admin/update_census_dataset_status.js +2 -2
  94. data/app/packs/src/decidim/votings/in-person-vote.js +3 -0
  95. data/app/permissions/decidim/votings/admin/permissions.rb +2 -14
  96. data/app/permissions/decidim/votings/permissions.rb +1 -3
  97. data/app/presenters/decidim/votings/voting_stats_presenter.rb +4 -1
  98. data/app/queries/decidim/elections/admin/pending_actions.rb +1 -1
  99. data/app/queries/decidim/elections/admin/votes_for_statistics.rb +1 -1
  100. data/app/queries/decidim/elections/elections_finished_to_end.rb +1 -1
  101. data/app/queries/decidim/elections/elections_ready_to_start.rb +1 -1
  102. data/app/queries/decidim/elections/filtered_elections.rb +1 -1
  103. data/app/queries/decidim/elections/trustees/by_participatory_space.rb +1 -1
  104. data/app/queries/decidim/elections/trustees/by_participatory_space_trustee_ids.rb +1 -1
  105. data/app/queries/decidim/elections/votes/last_vote_for_voter.rb +1 -1
  106. data/app/queries/decidim/elections/votes/pending_votes.rb +1 -1
  107. data/app/queries/decidim/votings/admin/admin_users.rb +1 -1
  108. data/app/queries/decidim/votings/admin/ballot_style_by_voting_code.rb +1 -1
  109. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb +1 -1
  110. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations_and_user.rb +2 -2
  111. data/app/queries/decidim/votings/admin/polling_officers_join_user.rb +1 -1
  112. data/app/queries/decidim/votings/organization_prioritized_votings.rb +2 -2
  113. data/app/queries/decidim/votings/organization_promoted_votings.rb +1 -1
  114. data/app/queries/decidim/votings/organization_published_votings.rb +2 -2
  115. data/app/queries/decidim/votings/organization_votings.rb +1 -1
  116. data/app/queries/decidim/votings/prioritized_votings.rb +1 -1
  117. data/app/queries/decidim/votings/published_votings.rb +1 -1
  118. data/app/queries/decidim/votings/votes/in_person_vote_for_voter.rb +1 -1
  119. data/app/queries/decidim/votings/votes/pending_in_person_votes.rb +1 -1
  120. data/app/services/decidim/votings/census_vote_flow.rb +1 -3
  121. data/app/views/decidim/elections/admin/questions/_form.html.erb +0 -4
  122. data/app/views/decidim/elections/admin/steps/_create_election.html.erb +14 -1
  123. data/app/views/decidim/elections/admin/steps/{_tally.html.erb → _tally_started.html.erb} +1 -1
  124. data/app/views/decidim/elections/admin/steps/index.html.erb +2 -0
  125. data/app/views/decidim/elections/elections/_filters.html.erb +2 -2
  126. data/app/views/decidim/elections/elections/election_log.html.erb +3 -1
  127. data/app/views/decidim/elections/shared/_broken_promises_modal.html.erb +33 -0
  128. data/app/views/decidim/elections/trustee_zone/elections/{_tally_steps.html.erb → _tally_started_steps.html.erb} +0 -0
  129. data/app/views/decidim/elections/trustee_zone/elections/show.html.erb +5 -1
  130. data/app/views/decidim/elections/trustee_zone/trustees/show.html.erb +3 -1
  131. data/app/views/decidim/elections/votes/_onboarding_modal.html.erb +3 -1
  132. data/app/views/decidim/elections/votes/_show_casting.html.erb +5 -1
  133. data/app/views/decidim/elections/votes/new.html.erb +11 -5
  134. data/app/views/decidim/elections/votes/verify.html.erb +4 -1
  135. data/app/views/decidim/votings/admin/votings/_form.html.erb +9 -0
  136. data/app/views/decidim/votings/census/admin/census/_creating_data.html.erb +1 -1
  137. data/app/views/decidim/votings/census/admin/census/_exporting_codes.html.erb +1 -1
  138. data/app/views/decidim/votings/census/admin/census/_freeze.html.erb +2 -0
  139. data/app/views/decidim/votings/census/admin/census/_generate_codes.html.erb +14 -4
  140. data/app/views/decidim/votings/census/admin/census/show.html.erb +1 -1
  141. data/app/views/decidim/votings/polling_officer_zone/closures/_certify_form.html.erb +3 -1
  142. data/app/views/decidim/votings/polling_officer_zone/closures/_sign_form.html.erb +3 -1
  143. data/app/views/decidim/votings/polling_officer_zone/closures/edit.html.erb +3 -1
  144. data/app/views/decidim/votings/polling_officer_zone/closures/new.html.erb +3 -1
  145. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/_complete_voting.html.erb +8 -2
  146. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/new.html.erb +5 -1
  147. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/show.html.erb +5 -1
  148. data/app/views/decidim/votings/votings/_filters.html.erb +2 -3
  149. data/app/views/decidim/votings/votings/_promoted_voting.html.erb +1 -1
  150. data/app/views/layouts/decidim/election_votes.html.erb +3 -1
  151. data/config/assets.rb +1 -1
  152. data/config/locales/ar.yml +2 -3
  153. data/config/locales/bg.yml +1 -0
  154. data/config/locales/ca.yml +64 -30
  155. data/config/locales/cs.yml +66 -27
  156. data/config/locales/de.yml +53 -30
  157. data/config/locales/el.yml +1 -1
  158. data/config/locales/en.yml +63 -27
  159. data/config/locales/es-MX.yml +65 -31
  160. data/config/locales/es-PY.yml +65 -31
  161. data/config/locales/es.yml +67 -33
  162. data/config/locales/eu.yml +5 -40
  163. data/config/locales/fi-plain.yml +64 -29
  164. data/config/locales/fi.yml +66 -31
  165. data/config/locales/fr-CA.yml +64 -29
  166. data/config/locales/fr.yml +62 -27
  167. data/config/locales/ga-IE.yml +1 -15
  168. data/config/locales/gl.yml +22 -32
  169. data/config/locales/hu.yml +28 -13
  170. data/config/locales/it.yml +5 -34
  171. data/config/locales/ja.yml +65 -33
  172. data/config/locales/lb.yml +1 -0
  173. data/config/locales/lt.yml +1445 -0
  174. data/config/locales/lv.yml +1 -1
  175. data/config/locales/nl.yml +10 -51
  176. data/config/locales/no.yml +11 -39
  177. data/config/locales/pl.yml +16 -35
  178. data/config/locales/pt-BR.yml +6 -34
  179. data/config/locales/pt.yml +12 -40
  180. data/config/locales/ro-RO.yml +11 -25
  181. data/config/locales/sl.yml +1 -0
  182. data/config/locales/sv.yml +60 -11
  183. data/config/locales/tr-TR.yml +4 -14
  184. data/config/locales/zh-CN.yml +1 -5
  185. data/db/migrate/20220404112802_rename_bb_status_tally_to_tally_started.rb +19 -0
  186. data/db/migrate/20220424121541_add_show_check_census_to_votings.rb +7 -0
  187. data/db/migrate/20220615102642_remove_description_from_elections_questions.rb +7 -0
  188. data/db/migrate/20220711112802_rename_dataset_file_to_filename.rb +7 -0
  189. data/lib/decidim/api/election_question_type.rb +0 -1
  190. data/lib/decidim/elections/component.rb +4 -16
  191. data/lib/decidim/elections/test/factories.rb +4 -5
  192. data/lib/decidim/elections/version.rb +1 -1
  193. data/lib/decidim/votings/participatory_space.rb +3 -3
  194. data/lib/decidim/votings/test/factories.rb +3 -2
  195. metadata +31 -27
  196. data/app/services/decidim/elections/election_search.rb +0 -35
  197. data/app/services/decidim/votings/voting_search.rb +0 -46
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "English"
3
4
  require "csv"
4
5
 
5
6
  module Decidim
@@ -8,7 +9,9 @@ module Decidim
8
9
  module Admin
9
10
  # A command with the business logic to create census dataset for a
10
11
  # voting space.
11
- class CreateDataset < Rectify::Command
12
+ class CreateDataset < Decidim::Command
13
+ include Decidim::ProcessesFileLocally
14
+
12
15
  def initialize(form, current_user)
13
16
  @form = form
14
17
  @current_user = current_user
@@ -23,23 +26,28 @@ module Decidim
23
26
  def call
24
27
  return broadcast(:invalid) unless form.valid?
25
28
 
26
- dataset = create_census_dataset!
29
+ process_file_locally(form.file) do |file_path|
30
+ @file_path = file_path
31
+ dataset = create_census_dataset!
27
32
 
28
- if csv_header_invalid?
29
- dataset.destroy!
30
- return broadcast(:invalid_csv_header)
31
- end
33
+ if csv_header_invalid?
34
+ dataset.destroy!
35
+ return broadcast(:invalid_csv_header)
36
+ end
32
37
 
33
- if dataset
34
- CSV.foreach(form.file.tempfile.path, col_sep: ";", headers: true, converters: ->(f) { f&.strip }) do |row|
35
- CreateDatumJob.perform_later(current_user, dataset, row.fields)
38
+ if dataset
39
+ CSV.foreach(file_path, col_sep: ";", headers: true, converters: ->(f) { f&.strip }) do |row|
40
+ CreateDatumJob.perform_later(current_user, dataset, row.fields)
41
+ end
36
42
  end
37
43
  end
38
44
 
39
45
  broadcast(:ok)
40
46
  end
41
47
 
42
- attr_reader :form, :current_user
48
+ private
49
+
50
+ attr_reader :form, :current_user, :file_path
43
51
  attr_accessor :dataset
44
52
 
45
53
  def create_census_dataset!
@@ -48,7 +56,7 @@ module Decidim
48
56
  current_user,
49
57
  {
50
58
  voting: form.current_participatory_space,
51
- file: form.file.original_filename,
59
+ filename: form.file.filename.to_s,
52
60
  csv_row_raw_count: csv_row_count,
53
61
  status: :creating_data
54
62
  },
@@ -57,31 +65,34 @@ module Decidim
57
65
  end
58
66
 
59
67
  def csv_header_invalid?
60
- CSV.parse_line(File.open(form.file.tempfile.path), col_sep: ";", headers: true, header_converters: :symbol).headers != expected_headers
68
+ headers.blank? || headers != expected_headers
61
69
  end
62
70
 
63
71
  def headers
72
+ @headers ||= CSV.parse_line(File.open(file_path), col_sep: ";", headers: true, header_converters: :symbol)&.headers
73
+ end
74
+
75
+ def no_ballot_headers
64
76
  [:document_id, :document_type, :date_of_birth, :full_name, :full_address, :postal_code, :mobile_phone_number, :email_address]
65
77
  end
66
78
 
67
79
  def ballot_style_headers
68
- headers.push(:ballot_style_code)
80
+ no_ballot_headers.push(:ballot_style_code)
69
81
  end
70
82
 
71
83
  def expected_headers
72
- @expected_headers ||= form.current_participatory_space.has_ballot_styles? ? ballot_style_headers : headers
73
- end
74
-
75
- def csv_rows
76
- @csv_rows ||= CSV.read(form.file.tempfile.path)
84
+ @expected_headers ||= form.current_participatory_space.has_ballot_styles? ? ballot_style_headers : no_ballot_headers
77
85
  end
78
86
 
79
87
  def csv_row_count
80
- @csv_row_count ||= file_lines_count(form.file.tempfile.path) - 1
88
+ @csv_row_count ||= file_lines_count - 1
81
89
  end
82
90
 
83
- def file_lines_count(file_path)
84
- `wc -l "#{file_path.shellescape}"`.strip.split(" ")[0].to_i
91
+ # count lines in the most resource-efficient way using ruby, handles milions of lines with minimal memory footprint
92
+ def file_lines_count
93
+ lines = 0
94
+ File.foreach(file_path) { lines += 1 }
95
+ lines
85
96
  end
86
97
  end
87
98
  end
@@ -6,7 +6,7 @@ module Decidim
6
6
  module Admin
7
7
  # A command with the business logic to create the datum for a
8
8
  # dataset row.
9
- class CreateDatum < Rectify::Command
9
+ class CreateDatum < Decidim::Command
10
10
  def initialize(form, dataset)
11
11
  @form = form
12
12
  @dataset = dataset
@@ -8,7 +8,7 @@ module Decidim
8
8
  module Admin
9
9
  # A command with the business logic to destroy a census dataset
10
10
  # from the admin panel.
11
- class DestroyDataset < Rectify::Command
11
+ class DestroyDataset < Decidim::Command
12
12
  def initialize(dataset, current_user)
13
13
  @dataset = dataset
14
14
  @current_user = current_user
@@ -6,7 +6,7 @@ module Decidim
6
6
  module Admin
7
7
  # A command with the business logic to create increment the dataset
8
8
  # processed rows and change the state when the last is processed
9
- class IncrementDatasetProcessedRows < Rectify::Command
9
+ class IncrementDatasetProcessedRows < Decidim::Command
10
10
  def initialize(dataset)
11
11
  @dataset = dataset
12
12
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Census
6
6
  module Admin
7
7
  # A command to launch the access codes export
8
- class LaunchAccessCodesExport < Rectify::Command
8
+ class LaunchAccessCodesExport < Decidim::Command
9
9
  def initialize(dataset, user)
10
10
  @dataset = dataset
11
11
  @user = user
@@ -19,6 +19,8 @@ module Decidim
19
19
  def call
20
20
  return broadcast(:invalid) unless valid?
21
21
 
22
+ UpdateDataset.call(dataset, { status: :exporting_codes }, user)
23
+
22
24
  ExportAccessCodesJob.perform_later(dataset, user)
23
25
 
24
26
  broadcast(:ok)
@@ -29,7 +31,7 @@ module Decidim
29
31
  private
30
32
 
31
33
  def valid?
32
- user.present? && dataset&.data&.present? && dataset.codes_generated?
34
+ user.present? && dataset&.data&.exists? && dataset.codes_generated?
33
35
  end
34
36
  end
35
37
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Census
6
6
  module Admin
7
7
  # A command to launch the access codes generation
8
- class LaunchAccessCodesGeneration < Rectify::Command
8
+ class LaunchAccessCodesGeneration < Decidim::Command
9
9
  def initialize(dataset, user)
10
10
  @dataset = dataset
11
11
  @user = user
@@ -31,7 +31,7 @@ module Decidim
31
31
  private
32
32
 
33
33
  def valid?
34
- user.present? && dataset&.data&.present? && dataset.data_created?
34
+ user.present? && dataset&.data&.exists? && dataset.data_created?
35
35
  end
36
36
 
37
37
  def update_dataset_status(dataset, status, user)
@@ -11,7 +11,7 @@ module Decidim
11
11
  # dataset - the Decidim::Votings::Census::Dataset to update
12
12
  # attributes - the hash of attibutes to update
13
13
  # user - the user performing the action (used for tracing)
14
- class UpdateDataset < Rectify::Command
14
+ class UpdateDataset < Decidim::Command
15
15
  def initialize(dataset, attributes, user)
16
16
  @dataset = dataset
17
17
  @attributes = attributes
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command with all the business logic when signing a closure of a polling station
6
- class CertifyPollingStationClosure < Rectify::Command
6
+ class CertifyPollingStationClosure < Decidim::Command
7
7
  include ::Decidim::AttachmentMethods
8
8
  include ::Decidim::GalleryMethods
9
9
  # Public: Initializes the command.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command to check if census data is given
6
- class CheckCensus < Rectify::Command
6
+ class CheckCensus < Decidim::Command
7
7
  def initialize(form)
8
8
  @form = form
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command with all the business logic when creating a closure for a polling station
6
- class CreatePollingStationClosure < Rectify::Command
6
+ class CreatePollingStationClosure < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command with all the business logic when creating results for a polling station
6
- class CreatePollingStationResults < Rectify::Command
6
+ class CreatePollingStationResults < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command to send the access code
6
- class SendAccessCode < Rectify::Command
6
+ class SendAccessCode < Decidim::Command
7
7
  def initialize(datum, medium)
8
8
  @datum = datum
9
9
  @medium = medium
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Votings
5
5
  # A command with all the business logic when signing a closure of a polling station
6
- class SignPollingStationClosure < Rectify::Command
6
+ class SignPollingStationClosure < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -4,7 +4,7 @@ module Decidim
4
4
  module Votings
5
5
  module Voter
6
6
  # This command allows the user to register an in person vote.
7
- class InPersonVote < Rectify::Command
7
+ class InPersonVote < Decidim::Command
8
8
  # Public: Initializes the command.
9
9
  #
10
10
  # form - A form with necessary info to register an in person vote.
@@ -4,7 +4,7 @@ module Decidim
4
4
  module Votings
5
5
  module Voter
6
6
  # This command updates the in person vote status
7
- class UpdateInPersonVoteStatus < Rectify::Command
7
+ class UpdateInPersonVoteStatus < Decidim::Command
8
8
  # Public: Initializes the command.
9
9
  #
10
10
  # in_person_vote - the in person vote that has been updated
@@ -73,7 +73,7 @@ module Decidim
73
73
  "key_ceremony_ended" => VotePeriodForm,
74
74
  "vote" => VotePeriodForm,
75
75
  "vote_ended" => ActionForm,
76
- "tally" => ReportMissingTrusteeForm,
76
+ "tally_started" => ReportMissingTrusteeForm,
77
77
  "tally_ended" => ActionForm
78
78
  }[current_step]
79
79
  end
@@ -85,7 +85,7 @@ module Decidim
85
85
  "key_ceremony_ended" => StartVote,
86
86
  "vote" => EndVote,
87
87
  "vote_ended" => StartTally,
88
- "tally" => ReportMissingTrustee,
88
+ "tally_started" => ReportMissingTrustee,
89
89
  "tally_ended" => PublishResults
90
90
  }[current_step]
91
91
  end
@@ -26,10 +26,12 @@ module Decidim
26
26
  delegate :bulletin_board_server, :authority_slug, to: :bulletin_board_client
27
27
 
28
28
  def elections
29
- @elections ||= Election.where(component: current_component).published
29
+ @elections ||= search_collection
30
30
  end
31
31
 
32
32
  def election
33
+ # The single election is searched from non-published records on purpose
34
+ # to allow previewing for admins.
33
35
  @election ||= Election.where(component: current_component).find(params[:id])
34
36
  end
35
37
 
@@ -57,26 +59,26 @@ module Decidim
57
59
  end
58
60
 
59
61
  def paginated_elections
60
- @paginated_elections ||= paginate(search.results.published)
62
+ @paginated_elections ||= paginate(search.result.published)
61
63
  @paginated_elections = reorder(@paginated_elections)
62
64
  end
63
65
 
64
66
  def scheduled_elections
65
- @scheduled_elections ||= search_klass.new(search_params.merge(state: %w(active upcoming))).results
67
+ @scheduled_elections ||= search_with(filter_params.merge(with_any_date: %w(active upcoming))).result
66
68
  end
67
69
 
68
- def search_klass
69
- ElectionSearch
70
+ def search_collection
71
+ Election.where(component: current_component).published
70
72
  end
71
73
 
72
74
  def default_filter_params
73
75
  {
74
- search_text: "",
75
- state: default_filter_state_params
76
+ search_text_cont: "",
77
+ with_any_date: default_filter_date_params
76
78
  }
77
79
  end
78
80
 
79
- def default_filter_state_params
81
+ def default_filter_date_params
80
82
  if elections.active.any?
81
83
  %w(active)
82
84
  elsif elections.upcoming.any?
@@ -85,10 +87,6 @@ module Decidim
85
87
  %w()
86
88
  end
87
89
  end
88
-
89
- def context_params
90
- { component: current_component, organization: current_organization }
91
- end
92
90
  end
93
91
  end
94
92
  end
@@ -41,7 +41,7 @@ module Decidim
41
41
  end
42
42
 
43
43
  def current_step
44
- @current_step ||= election.bb_status if election.bb_key_ceremony? || election.bb_tally?
44
+ @current_step ||= election.bb_status if election.bb_key_ceremony? || election.bb_tally_started?
45
45
  end
46
46
  end
47
47
  end
@@ -8,12 +8,12 @@ module Decidim
8
8
  class CensusController < Admin::ApplicationController
9
9
  helper_method :votings, :current_participatory_space, :current_census, :census_steps, :current_census_action_view,
10
10
  :user_email, :ballot_style_callout_text, :ballot_style_callout_level, :ballot_style_code_header
11
- helper_method :admin_voting_census_path, :admin_status_voting_census_path, :generate_access_codes_path, :export_access_codes_path
11
+ helper_method :admin_voting_census_path, :admin_status_voting_census_path, :generate_access_codes_path, :export_access_codes_path, :waiting_status?
12
12
 
13
13
  def show
14
14
  enforce_permission_to :manage, :census, voting: current_participatory_space
15
15
 
16
- flash[:notice] = "Finished processing #{current_census.file}" if current_census.data_created?
16
+ flash[:notice] = "Finished processing #{current_census.filename}" if current_census.data_created?
17
17
 
18
18
  @form = form(DatasetForm).instance
19
19
  end
@@ -184,6 +184,10 @@ module Decidim
184
184
  def ballot_style_code_header
185
185
  "Ballot Style Code"
186
186
  end
187
+
188
+ def waiting_status?
189
+ current_census.creating_data? || current_census.generating_codes? || current_census.exporting_codes?
190
+ end
187
191
  end
188
192
  end
189
193
  end
@@ -49,11 +49,15 @@ module Decidim
49
49
  end
50
50
 
51
51
  def show_check_census
52
+ raise ActionController::RoutingError, "Not Found" unless current_participatory_space.check_census_enabled?
53
+
52
54
  @form = form(Census::CheckForm).instance
53
55
  render :check_census, locals: { success: false, not_found: false }
54
56
  end
55
57
 
56
58
  def check_census
59
+ raise ActionController::RoutingError, "Not Found" unless current_participatory_space.check_census_enabled?
60
+
57
61
  @form = form(Census::CheckForm).from_params(params).with_context(
58
62
  current_participatory_space: current_participatory_space
59
63
  )
@@ -129,7 +133,7 @@ module Decidim
129
133
  end
130
134
 
131
135
  def paginated_votings
132
- @paginated_votings ||= paginate(search.results.published)
136
+ @paginated_votings ||= paginate(search.result.published)
133
137
  @paginated_votings = reorder(@paginated_votings)
134
138
  end
135
139
 
@@ -138,7 +142,7 @@ module Decidim
138
142
  end
139
143
 
140
144
  def finished_votings
141
- @finished_votings ||= search_klass.new(search_params.merge(state: ["finished"])).results
145
+ @finished_votings ||= search_with(filter_params.merge(with_any_date: %w(finished))).result
142
146
  end
143
147
 
144
148
  def only_finished_votings?
@@ -147,21 +151,14 @@ module Decidim
147
151
  published_votings.count == finished_votings.count
148
152
  end
149
153
 
150
- def search_klass
151
- VotingSearch
154
+ def search_collection
155
+ Voting.where(organization: current_organization).published
152
156
  end
153
157
 
154
158
  def default_filter_params
155
159
  {
156
- search_text: "",
157
- state: [""]
158
- }
159
- end
160
-
161
- def context_params
162
- {
163
- organization: current_organization,
164
- current_user: current_user
160
+ search_text_cont: "",
161
+ with_any_date: [""]
165
162
  }
166
163
  end
167
164
 
@@ -8,14 +8,12 @@ module Decidim
8
8
  include TranslatableAttributes
9
9
 
10
10
  translatable_attribute :title, String
11
- translatable_attribute :description, String
12
11
  attribute :max_selections, Integer, default: 1
13
12
  attribute :weight, Integer, default: 0
14
13
  attribute :random_answers_order, Boolean, default: true
15
14
  attribute :min_selections, Integer, default: 1
16
15
 
17
16
  validates :title, translatable_presence: true
18
- validates :description, translatable_presence: true
19
17
  validates :max_selections, presence: true, numericality: { greater_than_or_equal_to: 1 }
20
18
 
21
19
  def election
@@ -13,6 +13,12 @@ module Decidim
13
13
  validations.each do |message, t_args, valid|
14
14
  errors.add(message, I18n.t("steps.create_election.errors.#{message}", **t_args, scope: "decidim.elections.admin")) unless valid
15
15
  end
16
+
17
+ if needs_census?
18
+ census_validations.each do |message, t_args, valid|
19
+ errors.add(message, I18n.t("steps.create_election.errors.#{message}", **t_args, scope: "decidim.elections.admin")) unless valid
20
+ end
21
+ end
16
22
  end
17
23
 
18
24
  def current_step; end
@@ -34,15 +40,32 @@ module Decidim
34
40
  [:minimum_answers, {}, election.minimum_answers?],
35
41
  [:max_selections, {}, election.valid_questions?],
36
42
  [:published, {}, election.published_at.present?],
43
+ [:component_published, {}, election.component.published?],
37
44
  [:time_before, { hours: Decidim::Elections.setup_minimum_hours_before_start }, election.minimum_hours_before_start?],
38
45
  [:trustees_number, { number: bulletin_board.number_of_trustees }, participatory_space_trustees_with_public_key.size >= bulletin_board.number_of_trustees]
39
46
  ].freeze
40
47
  end
41
48
 
49
+ def census_validations
50
+ return [] unless needs_census?
51
+
52
+ @census_validations ||= [
53
+ [:census_uploaded, {}, census.present? && census.data.exists?],
54
+ [:census_codes_generated, {}, census_codes_generated?],
55
+ [:census_frozen, {}, census&.freeze?]
56
+ ].freeze
57
+ end
58
+
42
59
  def messages
43
- @messages ||= validations.map do |message, t_args, _valid|
60
+ @messages ||= validations.to_h do |message, t_args, _valid|
44
61
  [message, I18n.t("steps.create_election.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
45
- end.to_h
62
+ end
63
+ end
64
+
65
+ def census_messages
66
+ @census_messages ||= census_validations.to_h do |message, t_args, _valid|
67
+ [message, I18n.t("steps.create_election.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
68
+ end
46
69
  end
47
70
 
48
71
  def participatory_space_trustees
@@ -57,6 +80,26 @@ module Decidim
57
80
  @bulletin_board ||= context[:bulletin_board] || Decidim::Elections.bulletin_board
58
81
  end
59
82
 
83
+ def needs_census?
84
+ vote_flow.is_a?(Decidim::Votings::CensusVoteFlow)
85
+ end
86
+
87
+ def vote_flow
88
+ @vote_flow ||= election.participatory_space.try(:vote_flow_for, election)
89
+ end
90
+
91
+ def census_codes_generated?
92
+ return unless needs_census?
93
+
94
+ census&.codes_generated? || census&.exporting_codes? || census&.freeze?
95
+ end
96
+
97
+ def census
98
+ return unless needs_census?
99
+
100
+ @census ||= election.component.participatory_space.dataset
101
+ end
102
+
60
103
  def main_button?
61
104
  true
62
105
  end
@@ -64,7 +107,7 @@ module Decidim
64
107
  private
65
108
 
66
109
  def choose_random_trustees
67
- return @trustee_ids if @trustee_ids.any? || defined?(@trustees)
110
+ return @trustee_ids if @trustee_ids&.any? || defined?(@trustees)
68
111
 
69
112
  @trustees = if participatory_space_trustees_with_public_key.count >= bulletin_board.number_of_trustees
70
113
  participatory_space_trustees_with_public_key.sample(bulletin_board.number_of_trustees)
@@ -27,9 +27,9 @@ module Decidim
27
27
  end
28
28
 
29
29
  def messages
30
- @messages ||= validations.map do |message, t_args, _valid|
30
+ @messages ||= validations.to_h do |message, t_args, _valid|
31
31
  [message, I18n.t("steps.#{current_step}.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
32
- end.to_h
32
+ end
33
33
  end
34
34
  end
35
35
  end
@@ -11,7 +11,7 @@ module Decidim
11
11
  validates :code, presence: true
12
12
 
13
13
  def code
14
- @code&.upcase
14
+ super&.upcase
15
15
  end
16
16
  end
17
17
  end
@@ -15,11 +15,12 @@ module Decidim
15
15
  attribute :scope_id, Integer
16
16
  attribute :promoted, Boolean
17
17
  attribute :remove_banner_image, Boolean, default: false
18
- attribute :banner_image, String
18
+ attribute :banner_image
19
19
  attribute :remove_introductory_image, Boolean, default: false
20
- attribute :introductory_image, String
20
+ attribute :introductory_image
21
21
  attribute :voting_type, String
22
22
  attribute :census_contact_information, String
23
+ attribute :show_check_census, Boolean, default: false
23
24
 
24
25
  validates :title, translatable_presence: true
25
26
  validates :description, translatable_presence: true
@@ -29,7 +30,7 @@ module Decidim
29
30
  validates :end_time, presence: true, date: { after: :start_time }
30
31
  validates :banner_image, passthru: { to: Decidim::Votings::Voting }
31
32
  validates :introductory_image, passthru: { to: Decidim::Votings::Voting }
32
- validates :voting_type, presence: true, inclusion: { in: Votings::Voting.voting_types, message: "%{value} is not a valid voting type" }
33
+ validates :voting_type, presence: true, inclusion: { in: Votings::Voting.voting_types }
33
34
 
34
35
  validates :scope, presence: true, if: proc { |object| object.scope_id.present? }
35
36
 
@@ -6,14 +6,11 @@ module Decidim
6
6
  module Admin
7
7
  # A form to temporaly upload csv census data
8
8
  class DatasetForm < Form
9
- include Decidim::HasUploadValidations
10
-
11
9
  mimic :dataset
12
10
 
13
- attribute :file
11
+ attribute :file, Decidim::Attributes::Blob
14
12
 
15
- validates_upload :file
16
- validates :file, presence: true
13
+ validates :file, presence: true, file_content_type: { allow: ["text/csv"] }
17
14
 
18
15
  def organization
19
16
  context.current_participatory_space&.organization
@@ -25,7 +25,7 @@ module Decidim
25
25
  presence: true
26
26
 
27
27
  def ballot_style_code
28
- @ballot_style_code&.upcase
28
+ super&.upcase
29
29
  end
30
30
  end
31
31
  end
@@ -7,7 +7,7 @@ module Decidim
7
7
  module ApplicationHelper
8
8
  include Decidim::CheckBoxesTreeHelper
9
9
 
10
- def state_filter_values
10
+ def date_filter_values
11
11
  TreeNode.new(
12
12
  TreePoint.new("", t("elections.elections.filters.all", scope: "decidim")),
13
13
  [
@@ -5,7 +5,7 @@ module Decidim
5
5
  module VotingsHelper
6
6
  include Decidim::CheckBoxesTreeHelper
7
7
 
8
- def filter_states_values
8
+ def date_filter_values
9
9
  TreeNode.new(
10
10
  TreePoint.new("", t("votings.filters.all", scope: "decidim.votings")),
11
11
  [
@@ -39,12 +39,7 @@ module Decidim
39
39
  # A result percentage relative to the question
40
40
  # Returns a Float.
41
41
  def results_percentage
42
- @results_percentage ||= begin
43
- return 0 unless results_total.positive?
44
-
45
- result = results_total.to_f / question.results_total * 100.0
46
- result.round
47
- end
42
+ @results_percentage ||= results_total.positive? ? (results_total.to_f / question.results_total * 100.0).round : 0
48
43
  end
49
44
  end
50
45
  end