decidim-elections 0.26.2 → 0.27.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) 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 +1 -1
  4. data/app/cells/decidim/votings/content_blocks/highlighted_votings_cell.rb +4 -4
  5. data/app/cells/decidim/votings/content_blocks/landing_page/header_cell.rb +1 -1
  6. data/app/commands/decidim/elections/admin/add_user_as_trustee.rb +1 -1
  7. data/app/commands/decidim/elections/admin/create_answer.rb +1 -1
  8. data/app/commands/decidim/elections/admin/create_election.rb +1 -1
  9. data/app/commands/decidim/elections/admin/create_question.rb +1 -2
  10. data/app/commands/decidim/elections/admin/destroy_answer.rb +1 -1
  11. data/app/commands/decidim/elections/admin/destroy_election.rb +1 -1
  12. data/app/commands/decidim/elections/admin/destroy_question.rb +1 -1
  13. data/app/commands/decidim/elections/admin/end_vote.rb +1 -1
  14. data/app/commands/decidim/elections/admin/import_proposals_to_elections.rb +1 -1
  15. data/app/commands/decidim/elections/admin/publish_election.rb +1 -1
  16. data/app/commands/decidim/elections/admin/publish_results.rb +1 -1
  17. data/app/commands/decidim/elections/admin/remove_trustee_from_participatory_space.rb +1 -1
  18. data/app/commands/decidim/elections/admin/report_missing_trustee.rb +1 -1
  19. data/app/commands/decidim/elections/admin/setup_election.rb +4 -2
  20. data/app/commands/decidim/elections/admin/start_key_ceremony.rb +1 -1
  21. data/app/commands/decidim/elections/admin/start_tally.rb +1 -1
  22. data/app/commands/decidim/elections/admin/start_vote.rb +1 -1
  23. data/app/commands/decidim/elections/admin/unpublish_election.rb +1 -1
  24. data/app/commands/decidim/elections/admin/update_action_status.rb +1 -1
  25. data/app/commands/decidim/elections/admin/update_answer.rb +1 -1
  26. data/app/commands/decidim/elections/admin/update_answer_selection.rb +1 -1
  27. data/app/commands/decidim/elections/admin/update_election.rb +1 -1
  28. data/app/commands/decidim/elections/admin/update_question.rb +1 -2
  29. data/app/commands/decidim/elections/admin/update_trustee_participatory_space.rb +1 -1
  30. data/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb +1 -1
  31. data/app/commands/decidim/elections/trustee_zone/update_trustee.rb +1 -1
  32. data/app/commands/decidim/elections/voter/cast_vote.rb +1 -1
  33. data/app/commands/decidim/elections/voter/update_vote_status.rb +2 -2
  34. data/app/commands/decidim/votings/admin/create_ballot_style.rb +1 -1
  35. data/app/commands/decidim/votings/admin/create_monitoring_committee_member.rb +1 -1
  36. data/app/commands/decidim/votings/admin/create_polling_officer.rb +1 -1
  37. data/app/commands/decidim/votings/admin/create_voting.rb +3 -2
  38. data/app/commands/decidim/votings/admin/destroy_ballot_style.rb +1 -1
  39. data/app/commands/decidim/votings/admin/destroy_monitoring_committee_member.rb +1 -1
  40. data/app/commands/decidim/votings/admin/destroy_polling_officer.rb +1 -1
  41. data/app/commands/decidim/votings/admin/destroy_polling_station.rb +1 -1
  42. data/app/commands/decidim/votings/admin/manage_polling_station.rb +2 -2
  43. data/app/commands/decidim/votings/admin/monitoring_committee_validate_polling_station_closure.rb +1 -1
  44. data/app/commands/decidim/votings/admin/publish_voting.rb +1 -1
  45. data/app/commands/decidim/votings/admin/unpublish_voting.rb +1 -1
  46. data/app/commands/decidim/votings/admin/update_ballot_style.rb +1 -1
  47. data/app/commands/decidim/votings/admin/update_voting.rb +3 -2
  48. data/app/commands/decidim/votings/census/admin/create_dataset.rb +22 -19
  49. data/app/commands/decidim/votings/census/admin/create_datum.rb +1 -1
  50. data/app/commands/decidim/votings/census/admin/destroy_dataset.rb +1 -1
  51. data/app/commands/decidim/votings/census/admin/increment_dataset_processed_rows.rb +1 -1
  52. data/app/commands/decidim/votings/census/admin/launch_access_codes_export.rb +1 -1
  53. data/app/commands/decidim/votings/census/admin/launch_access_codes_generation.rb +1 -1
  54. data/app/commands/decidim/votings/census/admin/update_dataset.rb +1 -1
  55. data/app/commands/decidim/votings/certify_polling_station_closure.rb +1 -1
  56. data/app/commands/decidim/votings/check_census.rb +1 -1
  57. data/app/commands/decidim/votings/create_polling_station_closure.rb +1 -1
  58. data/app/commands/decidim/votings/create_polling_station_results.rb +1 -1
  59. data/app/commands/decidim/votings/send_access_code.rb +1 -1
  60. data/app/commands/decidim/votings/sign_polling_station_closure.rb +1 -1
  61. data/app/commands/decidim/votings/voter/in_person_vote.rb +1 -1
  62. data/app/commands/decidim/votings/voter/update_in_person_vote_status.rb +1 -1
  63. data/app/controllers/decidim/elections/admin/steps_controller.rb +2 -2
  64. data/app/controllers/decidim/elections/elections_controller.rb +10 -12
  65. data/app/controllers/decidim/elections/trustee_zone/elections_controller.rb +1 -1
  66. data/app/controllers/decidim/votings/votings_controller.rb +10 -13
  67. data/app/forms/decidim/elections/admin/question_form.rb +0 -2
  68. data/app/forms/decidim/elections/admin/setup_form.rb +4 -3
  69. data/app/forms/decidim/elections/admin/vote_period_form.rb +2 -2
  70. data/app/forms/decidim/votings/admin/ballot_style_form.rb +1 -1
  71. data/app/forms/decidim/votings/admin/voting_form.rb +4 -3
  72. data/app/forms/decidim/votings/census/admin/dataset_form.rb +2 -5
  73. data/app/forms/decidim/votings/census/admin/datum_form.rb +1 -1
  74. data/app/helpers/decidim/elections/application_helper.rb +1 -1
  75. data/app/helpers/decidim/votings/votings_helper.rb +1 -1
  76. data/app/models/decidim/elections/answer.rb +1 -6
  77. data/app/models/decidim/elections/election.rb +13 -2
  78. data/app/models/decidim/elections/question.rb +2 -7
  79. data/app/models/decidim/votings/polling_station.rb +2 -3
  80. data/app/models/decidim/votings/voting.rb +15 -0
  81. data/app/packs/entrypoints/{decidim_elections_trustee_tally.js → decidim_elections_trustee_tally_started.js} +0 -0
  82. data/app/packs/src/decidim/elections/trustee/tally.js +1 -1
  83. data/app/packs/src/decidim/elections/voter/setup-vote.js +7 -0
  84. data/app/permissions/decidim/votings/admin/permissions.rb +2 -14
  85. data/app/permissions/decidim/votings/permissions.rb +1 -3
  86. data/app/presenters/decidim/votings/voting_stats_presenter.rb +4 -1
  87. data/app/queries/decidim/elections/admin/pending_actions.rb +1 -1
  88. data/app/queries/decidim/elections/admin/votes_for_statistics.rb +1 -1
  89. data/app/queries/decidim/elections/elections_finished_to_end.rb +1 -1
  90. data/app/queries/decidim/elections/elections_ready_to_start.rb +1 -1
  91. data/app/queries/decidim/elections/filtered_elections.rb +1 -1
  92. data/app/queries/decidim/elections/trustees/by_participatory_space.rb +1 -1
  93. data/app/queries/decidim/elections/trustees/by_participatory_space_trustee_ids.rb +1 -1
  94. data/app/queries/decidim/elections/votes/last_vote_for_voter.rb +1 -1
  95. data/app/queries/decidim/elections/votes/pending_votes.rb +1 -1
  96. data/app/queries/decidim/votings/admin/admin_users.rb +1 -1
  97. data/app/queries/decidim/votings/admin/ballot_style_by_voting_code.rb +1 -1
  98. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations.rb +1 -1
  99. data/app/queries/decidim/votings/admin/polling_officers_join_polling_stations_and_user.rb +2 -2
  100. data/app/queries/decidim/votings/admin/polling_officers_join_user.rb +1 -1
  101. data/app/queries/decidim/votings/organization_prioritized_votings.rb +2 -2
  102. data/app/queries/decidim/votings/organization_promoted_votings.rb +1 -1
  103. data/app/queries/decidim/votings/organization_published_votings.rb +2 -2
  104. data/app/queries/decidim/votings/organization_votings.rb +1 -1
  105. data/app/queries/decidim/votings/prioritized_votings.rb +1 -1
  106. data/app/queries/decidim/votings/published_votings.rb +1 -1
  107. data/app/queries/decidim/votings/votes/in_person_vote_for_voter.rb +1 -1
  108. data/app/queries/decidim/votings/votes/pending_in_person_votes.rb +1 -1
  109. data/app/services/decidim/votings/census_vote_flow.rb +1 -3
  110. data/app/views/decidim/elections/admin/questions/_form.html.erb +0 -4
  111. data/app/views/decidim/elections/admin/steps/{_tally.html.erb → _tally_started.html.erb} +1 -1
  112. data/app/views/decidim/elections/elections/_filters.html.erb +2 -2
  113. data/app/views/decidim/elections/elections/election_log.html.erb +3 -1
  114. data/app/views/decidim/elections/trustee_zone/elections/{_tally_steps.html.erb → _tally_started_steps.html.erb} +0 -0
  115. data/app/views/decidim/elections/trustee_zone/elections/show.html.erb +3 -1
  116. data/app/views/decidim/elections/trustee_zone/trustees/show.html.erb +3 -1
  117. data/app/views/decidim/elections/votes/_onboarding_modal.html.erb +3 -1
  118. data/app/views/decidim/elections/votes/_server_error_modal.html.erb +28 -0
  119. data/app/views/decidim/elections/votes/_show_casting.html.erb +3 -1
  120. data/app/views/decidim/elections/votes/new.html.erb +11 -5
  121. data/app/views/decidim/elections/votes/verify.html.erb +4 -1
  122. data/app/views/decidim/votings/admin/votings/_form.html.erb +9 -0
  123. data/app/views/decidim/votings/polling_officer_zone/closures/_certify_form.html.erb +3 -1
  124. data/app/views/decidim/votings/polling_officer_zone/closures/_sign_form.html.erb +3 -1
  125. data/app/views/decidim/votings/polling_officer_zone/closures/edit.html.erb +3 -1
  126. data/app/views/decidim/votings/polling_officer_zone/closures/new.html.erb +3 -1
  127. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/_complete_voting.html.erb +8 -2
  128. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/new.html.erb +3 -1
  129. data/app/views/decidim/votings/polling_officer_zone/in_person_votes/show.html.erb +3 -1
  130. data/app/views/decidim/votings/votings/_filters.html.erb +2 -3
  131. data/app/views/layouts/decidim/election_votes.html.erb +3 -1
  132. data/config/assets.rb +1 -1
  133. data/config/locales/am-ET.yml +1 -0
  134. data/config/locales/ar.yml +2 -3
  135. data/config/locales/bg.yml +1 -0
  136. data/config/locales/ca.yml +47 -27
  137. data/config/locales/cs.yml +48 -24
  138. data/config/locales/da.yml +1 -0
  139. data/config/locales/de.yml +6 -31
  140. data/config/locales/el.yml +1 -1
  141. data/config/locales/en.yml +45 -24
  142. data/config/locales/eo.yml +1 -0
  143. data/config/locales/es-MX.yml +48 -28
  144. data/config/locales/es-PY.yml +48 -28
  145. data/config/locales/es.yml +50 -30
  146. data/config/locales/et.yml +1 -0
  147. data/config/locales/eu.yml +5 -34
  148. data/config/locales/fi-plain.yml +46 -26
  149. data/config/locales/fi.yml +48 -28
  150. data/config/locales/fr-CA.yml +37 -27
  151. data/config/locales/fr.yml +35 -25
  152. data/config/locales/ga-IE.yml +1 -15
  153. data/config/locales/gl.yml +22 -26
  154. data/config/locales/hr.yml +1 -0
  155. data/config/locales/hu.yml +21 -13
  156. data/config/locales/id-ID.yml +1 -0
  157. data/config/locales/is-IS.yml +2 -1
  158. data/config/locales/it.yml +5 -28
  159. data/config/locales/ja.yml +41 -30
  160. data/config/locales/ko.yml +1 -0
  161. data/config/locales/lb.yml +1 -0
  162. data/config/locales/lt.yml +1 -0
  163. data/config/locales/lv.yml +1 -1
  164. data/config/locales/mt.yml +1 -0
  165. data/config/locales/nl.yml +10 -45
  166. data/config/locales/no.yml +11 -39
  167. data/config/locales/om-ET.yml +1 -0
  168. data/config/locales/pl.yml +16 -29
  169. data/config/locales/pt-BR.yml +7 -29
  170. data/config/locales/pt.yml +12 -34
  171. data/config/locales/ro-RO.yml +11 -25
  172. data/config/locales/ru.yml +1 -0
  173. data/config/locales/si-LK.yml +1 -0
  174. data/config/locales/sk.yml +1 -0
  175. data/config/locales/sl.yml +1 -0
  176. data/config/locales/so-SO.yml +1 -0
  177. data/config/locales/sr-CS.yml +1 -0
  178. data/config/locales/sv.yml +62 -11
  179. data/config/locales/sw-KE.yml +1 -0
  180. data/config/locales/ti-ER.yml +1 -0
  181. data/config/locales/tr-TR.yml +4 -14
  182. data/config/locales/uk.yml +1 -0
  183. data/config/locales/val-ES.yml +1 -0
  184. data/config/locales/vi.yml +1 -0
  185. data/config/locales/zh-CN.yml +1 -5
  186. data/config/locales/zh-TW.yml +1 -0
  187. data/db/migrate/20220404112802_rename_bb_status_tally_to_tally_started.rb +19 -0
  188. data/db/migrate/20220424121541_add_show_check_census_to_votings.rb +7 -0
  189. data/db/migrate/20220615102642_remove_description_from_elections_questions.rb +7 -0
  190. data/lib/decidim/api/election_question_type.rb +0 -1
  191. data/lib/decidim/elections/component.rb +4 -16
  192. data/lib/decidim/elections/test/factories.rb +4 -5
  193. data/lib/decidim/elections/version.rb +1 -1
  194. data/lib/decidim/votings/participatory_space.rb +3 -3
  195. data/lib/decidim/votings/test/factories.rb +2 -1
  196. metadata +29 -27
  197. data/app/services/decidim/elections/election_search.rb +0 -35
  198. data/app/services/decidim/votings/voting_search.rb +0 -46
@@ -8,7 +8,9 @@ module Decidim
8
8
  module Admin
9
9
  # A command with the business logic to create census dataset for a
10
10
  # voting space.
11
- class CreateDataset < Rectify::Command
11
+ class CreateDataset < Decidim::Command
12
+ include Decidim::ProcessesFileLocally
13
+
12
14
  def initialize(form, current_user)
13
15
  @form = form
14
16
  @current_user = current_user
@@ -23,23 +25,28 @@ module Decidim
23
25
  def call
24
26
  return broadcast(:invalid) unless form.valid?
25
27
 
26
- dataset = create_census_dataset!
28
+ process_file_locally(form.file) do |file_path|
29
+ @file_path = file_path
30
+ dataset = create_census_dataset!
27
31
 
28
- if csv_header_invalid?
29
- dataset.destroy!
30
- return broadcast(:invalid_csv_header)
31
- end
32
+ if csv_header_invalid?
33
+ dataset.destroy!
34
+ return broadcast(:invalid_csv_header)
35
+ end
32
36
 
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)
37
+ if dataset
38
+ CSV.foreach(file_path, col_sep: ";", headers: true, converters: ->(f) { f&.strip }) do |row|
39
+ CreateDatumJob.perform_later(current_user, dataset, row.fields)
40
+ end
36
41
  end
37
42
  end
38
43
 
39
44
  broadcast(:ok)
40
45
  end
41
46
 
42
- attr_reader :form, :current_user
47
+ private
48
+
49
+ attr_reader :form, :current_user, :file_path
43
50
  attr_accessor :dataset
44
51
 
45
52
  def create_census_dataset!
@@ -48,7 +55,7 @@ module Decidim
48
55
  current_user,
49
56
  {
50
57
  voting: form.current_participatory_space,
51
- file: form.file.original_filename,
58
+ file: form.file,
52
59
  csv_row_raw_count: csv_row_count,
53
60
  status: :creating_data
54
61
  },
@@ -57,7 +64,7 @@ module Decidim
57
64
  end
58
65
 
59
66
  def csv_header_invalid?
60
- CSV.parse_line(File.open(form.file.tempfile.path), col_sep: ";", headers: true, header_converters: :symbol).headers != expected_headers
67
+ CSV.parse_line(File.open(file_path), col_sep: ";", headers: true, header_converters: :symbol).headers != expected_headers
61
68
  end
62
69
 
63
70
  def headers
@@ -72,16 +79,12 @@ module Decidim
72
79
  @expected_headers ||= form.current_participatory_space.has_ballot_styles? ? ballot_style_headers : headers
73
80
  end
74
81
 
75
- def csv_rows
76
- @csv_rows ||= CSV.read(form.file.tempfile.path)
77
- end
78
-
79
82
  def csv_row_count
80
- @csv_row_count ||= file_lines_count(form.file.tempfile.path) - 1
83
+ @csv_row_count ||= file_lines_count - 1
81
84
  end
82
85
 
83
- def file_lines_count(file_path)
84
- `wc -l "#{file_path.shellescape}"`.strip.split(" ")[0].to_i
86
+ def file_lines_count
87
+ `wc -l "#{file_path.shellescape}"`.strip.split.first.to_i
85
88
  end
86
89
  end
87
90
  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
@@ -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
@@ -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
@@ -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
@@ -34,15 +34,16 @@ module Decidim
34
34
  [:minimum_answers, {}, election.minimum_answers?],
35
35
  [:max_selections, {}, election.valid_questions?],
36
36
  [:published, {}, election.published_at.present?],
37
+ [:component_published, {}, election.component.published?],
37
38
  [:time_before, { hours: Decidim::Elections.setup_minimum_hours_before_start }, election.minimum_hours_before_start?],
38
39
  [:trustees_number, { number: bulletin_board.number_of_trustees }, participatory_space_trustees_with_public_key.size >= bulletin_board.number_of_trustees]
39
40
  ].freeze
40
41
  end
41
42
 
42
43
  def messages
43
- @messages ||= validations.map do |message, t_args, _valid|
44
+ @messages ||= validations.to_h do |message, t_args, _valid|
44
45
  [message, I18n.t("steps.create_election.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
45
- end.to_h
46
+ end
46
47
  end
47
48
 
48
49
  def participatory_space_trustees
@@ -64,7 +65,7 @@ module Decidim
64
65
  private
65
66
 
66
67
  def choose_random_trustees
67
- return @trustee_ids if @trustee_ids.any? || defined?(@trustees)
68
+ return @trustee_ids if @trustee_ids&.any? || defined?(@trustees)
68
69
 
69
70
  @trustees = if participatory_space_trustees_with_public_key.count >= bulletin_board.number_of_trustees
70
71
  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
@@ -14,10 +14,11 @@ module Decidim
14
14
  include Traceable
15
15
  include Loggable
16
16
  include Decidim::Forms::HasQuestionnaire
17
+ include Decidim::FilterableResource
17
18
 
18
19
  translatable_fields :title, :description
19
20
 
20
- enum bb_status: [:created, :key_ceremony, :key_ceremony_ended, :vote, :vote_ended, :tally, :tally_ended, :results_published].index_with(&:to_s), _prefix: :bb
21
+ enum bb_status: [:created, :key_ceremony, :key_ceremony_ended, :vote, :vote_ended, :tally_started, :tally_ended, :results_published].index_with(&:to_s), _prefix: :bb
21
22
 
22
23
  component_manifest_name "elections"
23
24
 
@@ -43,6 +44,8 @@ module Decidim
43
44
  .where("end_time < ?", Time.current)
44
45
  }
45
46
 
47
+ scope_search_multi :with_any_date, [:active, :upcoming, :finished]
48
+
46
49
  def self.log_presenter_class_for(_log)
47
50
  Decidim::Elections::AdminLog::ElectionPresenter
48
51
  end
@@ -124,7 +127,7 @@ module Decidim
124
127
  end
125
128
 
126
129
  def trustee_action_required?
127
- bb_key_ceremony? || bb_tally?
130
+ bb_key_ceremony? || bb_tally_started?
128
131
  end
129
132
 
130
133
  # Public: Checks if the election has a blocked_at value
@@ -138,6 +141,14 @@ module Decidim
138
141
  def allow_resource_permissions?
139
142
  true
140
143
  end
144
+
145
+ # Create i18n ransackers for :title and :description.
146
+ # Create the :search_text ransacker alias for searching from both of these.
147
+ ransacker_i18n_multi :search_text, [:title, :description]
148
+
149
+ def self.ransackable_scopes(_auth_object = nil)
150
+ [:with_any_date]
151
+ end
141
152
  end
142
153
  end
143
154
  end
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Elections
5
5
  # The data store for a Question in the Decidim::Elections component. It stores a
6
- # title, description and a maximum number of selection that voters can choose.
6
+ # title and a maximum number of selection that voters can choose.
7
7
  class Question < ApplicationRecord
8
8
  include Decidim::Resourceable
9
9
  include Traceable
@@ -41,12 +41,7 @@ module Decidim
41
41
  # A result percentage relative to the question
42
42
  # Returns a Float.
43
43
  def blank_votes_percentage
44
- @blank_votes_percentage ||= begin
45
- return 0 unless results_total.positive?
46
-
47
- result = blank_votes.to_f / results_total * 100.0
48
- result.round
49
- end
44
+ @blank_votes_percentage ||= results_total.positive? ? (blank_votes.to_f / results_total * 100.0).round : 0
50
45
  end
51
46
 
52
47
  def slug
@@ -7,6 +7,7 @@ module Decidim
7
7
  include Traceable
8
8
  include Loggable
9
9
  include Decidim::TranslatableResource
10
+ include Decidim::FilterableResource
10
11
 
11
12
  translatable_fields :title, :location, :location_hints
12
13
 
@@ -37,9 +38,7 @@ module Decidim
37
38
  alias participatory_space voting
38
39
 
39
40
  # Allow ransacker to search for a key in a hstore column (`title`.`en`)
40
- ransacker :title do |parent|
41
- Arel::Nodes::InfixOperation.new("->>", parent.table[:title], Arel::Nodes.build_quoted(I18n.locale.to_s))
42
- end
41
+ ransacker_i18n :title
43
42
 
44
43
  [:manager, :president].each do |role|
45
44
  [:name, :email, :nickname].each do |field|