decidim-initiatives 0.22.0 → 0.23.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/initiatives/admin/initiatives_types.js.es6 +18 -0
  3. data/app/assets/stylesheet/decidim/initiatives/initiatives.scss +6 -0
  4. data/app/cells/decidim/initiatives/initiative_m_cell.rb +14 -0
  5. data/app/cells/decidim/initiatives_votes/vote/show.erb +12 -9
  6. data/app/cells/decidim/initiatives_votes/vote_cell.rb +7 -0
  7. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +3 -1
  8. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +3 -1
  9. data/app/commands/decidim/initiatives/attachment_methods.rb +9 -5
  10. data/app/commands/decidim/initiatives/create_initiative.rb +2 -2
  11. data/app/commands/decidim/initiatives/unvote_initiative.rb +4 -10
  12. data/app/commands/decidim/initiatives/vote_initiative.rb +36 -36
  13. data/app/controllers/decidim/initiatives/admin/answers_controller.rb +2 -3
  14. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +2 -2
  15. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +1 -1
  16. data/app/controllers/decidim/initiatives/initiative_signatures_controller.rb +20 -26
  17. data/app/controllers/decidim/initiatives/initiative_votes_controller.rb +11 -5
  18. data/app/controllers/decidim/initiatives/initiatives_controller.rb +11 -10
  19. data/app/controllers/decidim/initiatives/initiatives_type_scopes_controller.rb +9 -1
  20. data/app/controllers/decidim/initiatives/{initiative_widgets_controller.rb → widgets_controller.rb} +2 -2
  21. data/app/forms/decidim/initiatives/admin/initiative_form.rb +19 -8
  22. data/app/forms/decidim/initiatives/admin/initiative_type_form.rb +3 -0
  23. data/app/forms/decidim/initiatives/initiative_form.rb +23 -2
  24. data/app/forms/decidim/initiatives/vote_form.rb +134 -77
  25. data/app/models/decidim/initiative.rb +123 -52
  26. data/app/models/decidim/initiatives_type.rb +5 -2
  27. data/app/models/decidim/initiatives_type_scope.rb +5 -1
  28. data/app/models/decidim/initiatives_vote.rb +19 -23
  29. data/app/permissions/decidim/initiatives/admin/permissions.rb +2 -2
  30. data/app/permissions/decidim/initiatives/permissions.rb +2 -4
  31. data/app/presenters/decidim/initiatives/admin_log/initiative_presenter.rb +2 -2
  32. data/app/presenters/decidim/initiatives/initiative_stats_presenter.rb +1 -5
  33. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
  34. data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +39 -17
  35. data/app/views/decidim/initiatives/admin/initiatives/export_pdf_signatures.pdf.erb +12 -9
  36. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +35 -10
  37. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +28 -25
  38. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +18 -16
  39. data/app/views/decidim/initiatives/initiative_signatures/error_on_vote.js.erb +5 -0
  40. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +0 -1
  41. data/app/views/decidim/initiatives/initiative_signatures/update_buttons_and_counters.js.erb +1 -1
  42. data/app/views/decidim/initiatives/initiative_votes/update_buttons_and_counters.js.erb +1 -1
  43. data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +36 -2
  44. data/app/views/decidim/initiatives/initiatives/_initiatives.html.erb +10 -0
  45. data/app/views/decidim/initiatives/initiatives/_progress_bar.html.erb +24 -9
  46. data/app/views/decidim/initiatives/initiatives/_vote_cabin.html.erb +1 -13
  47. data/app/views/decidim/initiatives/initiatives/show.html.erb +1 -3
  48. data/app/views/layouts/decidim/initiative.html.erb +1 -0
  49. data/config/locales/am-ET.yml +1 -0
  50. data/config/locales/ar.yml +0 -4
  51. data/config/locales/bg.yml +13 -0
  52. data/config/locales/ca.yml +22 -8
  53. data/config/locales/cs.yml +32 -18
  54. data/config/locales/da.yml +1 -0
  55. data/config/locales/de.yml +69 -43
  56. data/config/locales/el.yml +0 -4
  57. data/config/locales/en.yml +18 -4
  58. data/config/locales/eo.yml +1 -0
  59. data/config/locales/es-MX.yml +18 -4
  60. data/config/locales/es-PY.yml +18 -4
  61. data/config/locales/es.yml +31 -17
  62. data/config/locales/et.yml +1 -0
  63. data/config/locales/eu.yml +0 -14
  64. data/config/locales/fi-plain.yml +18 -4
  65. data/config/locales/fi.yml +18 -4
  66. data/config/locales/fr-CA.yml +32 -4
  67. data/config/locales/fr.yml +36 -8
  68. data/config/locales/gl.yml +7 -17
  69. data/config/locales/hr.yml +1 -0
  70. data/config/locales/hu.yml +5 -4
  71. data/config/locales/id-ID.yml +0 -14
  72. data/config/locales/is-IS.yml +0 -10
  73. data/config/locales/is.yml +251 -0
  74. data/config/locales/it.yml +9 -4
  75. data/config/locales/ja-JP.yml +43 -49
  76. data/config/locales/ja.yml +549 -0
  77. data/config/locales/ko-KR.yml +1 -0
  78. data/config/locales/ko.yml +1 -0
  79. data/config/locales/lt.yml +1 -0
  80. data/config/locales/{lv-LV.yml → lv.yml} +0 -4
  81. data/config/locales/mt.yml +1 -0
  82. data/config/locales/nl.yml +15 -10
  83. data/config/locales/no.yml +69 -6
  84. data/config/locales/om-ET.yml +1 -0
  85. data/config/locales/pl.yml +28 -22
  86. data/config/locales/pt-BR.yml +0 -14
  87. data/config/locales/pt.yml +5 -4
  88. data/config/locales/ro-RO.yml +5 -4
  89. data/config/locales/ru.yml +0 -14
  90. data/config/locales/si-LK.yml +1 -0
  91. data/config/locales/sk.yml +0 -4
  92. data/config/locales/sl.yml +6 -0
  93. data/config/locales/so-SO.yml +1 -0
  94. data/config/locales/sv.yml +28 -8
  95. data/config/locales/sw-KE.yml +1 -0
  96. data/config/locales/ti-ER.yml +1 -0
  97. data/config/locales/tr-TR.yml +204 -122
  98. data/config/locales/uk.yml +0 -14
  99. data/config/locales/vi-VN.yml +1 -0
  100. data/config/locales/vi.yml +1 -0
  101. data/config/locales/zh-CN.yml +549 -0
  102. data/config/locales/zh-TW.yml +1 -0
  103. data/db/migrate/20191106144259_add_settings_to_initiatives_types.rb +8 -0
  104. data/db/migrate/20191107134847_add_scopes_to_initiatives_votes.rb +28 -0
  105. data/db/migrate/20191116170841_allow_multiple_initiative_votes_counter_caches.rb +32 -0
  106. data/db/migrate/20191118105634_allow_multiple_offline_votes.rb +34 -0
  107. data/db/migrate/20200528151456_remove_user_groups_from_initiative_votes.rb +7 -0
  108. data/db/migrate/20200827154214_add_commentable_counter_cache_to_initiatives.rb +9 -0
  109. data/db/seeds/city.jpeg +0 -0
  110. data/lib/decidim/initiatives/admin_engine.rb +1 -0
  111. data/lib/decidim/initiatives/engine.rb +2 -2
  112. data/lib/decidim/initiatives/participatory_space.rb +7 -0
  113. data/lib/decidim/initiatives/test/factories.rb +21 -3
  114. data/lib/decidim/initiatives/version.rb +1 -1
  115. data/lib/tasks/decidim_initiatives.rake +1 -3
  116. metadata +48 -21
  117. data/app/views/decidim/initiatives/initiatives/_supports.html.erb +0 -22
  118. data/app/views/decidim/initiatives/initiatives/signature_identities.html.erb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c17f1f5c3ad33e6ca352c73fc8e551b3e58e486a223598804acfd6819671bb31
4
- data.tar.gz: b6cce6c33ad0ddb6a82473190b019a6808ddbf105fe1644df72b9589032a74b7
3
+ metadata.gz: 57cf106ea81ae642f11134155871a66b640f1c95a6f37094331fd20aff08c389
4
+ data.tar.gz: d558c3358e41320d4fb44387f3a1ba33926412c04abe9a6e6be4a014b7095df7
5
5
  SHA512:
6
- metadata.gz: 077066ebe56b6f9f8fdb094afe847261f70809c23d37d79a90c75aa67107e52dad6f7d875269531198e3a28a5cbea1960484ac04ed7557e03cb4fd4b4d4dc417
7
- data.tar.gz: c5eba0295d92b0be850c4ab997f2bbc3fb854641a57eb44893bbbcfbac25b6fc8a0c74bc7f5e102e1ef6b2650345e3122d74d955c63a79bea0105dbe39a5d296
6
+ metadata.gz: 21bdd6144f748fb7e6c90304a1f92237d1f5e59a158d9032a84ff27b6e0788b314b5382ce70268d95fe8f0878bbc2171f3aefadf3ccff13f73b9aa4285d363d2
7
+ data.tar.gz: de778406deee7f218ccdb2f9f91de5c429434e7d8917fa0b8f13b1ce1ff9894e096bbe0f0cb10c59a14f502334977089eb5ec8dfba1c66d8c411eec290275f94
@@ -6,15 +6,33 @@
6
6
  $scope
7
7
  );
8
8
 
9
+ const $signatureType = $("#initiatives_type_signature_type");
10
+
11
+ const $collectUserDataCheckbox = $("#initiatives_type_collect_user_extra_fields");
12
+
9
13
  const toggleVisibility = () => {
10
14
  if ($promotingCommitteeCheckbox.is(":checked")) {
11
15
  $(".minimum-committee-members-details", $scope).show();
12
16
  } else {
13
17
  $(".minimum-committee-members-details", $scope).hide();
14
18
  }
19
+
20
+ if ($signatureType.val() === "offline") {
21
+ $("#initiatives_type_undo_online_signatures_enabled").parent().parent().hide();
22
+ } else {
23
+ $("#initiatives_type_undo_online_signatures_enabled").parent().parent().show();
24
+ }
25
+
26
+ if ($collectUserDataCheckbox.is(":checked")) {
27
+ $("#initiatives_type-extra_fields_legal_information-tabs").parent().parent().show()
28
+ } else {
29
+ $("#initiatives_type-extra_fields_legal_information-tabs").parent().parent().hide()
30
+ }
15
31
  };
16
32
 
17
33
  $($promotingCommitteeCheckbox).click(() => toggleVisibility());
34
+ $($signatureType).change(() => toggleVisibility());
35
+ $($collectUserDataCheckbox).click(() => toggleVisibility());
18
36
 
19
37
  toggleVisibility();
20
38
  })();
@@ -51,3 +51,9 @@
51
51
  .legal_text{
52
52
  font-size: 8pt;
53
53
  }
54
+
55
+ .progress__bar--horizontal{
56
+ &:last-of-type{
57
+ margin-bottom: 1.5rem;
58
+ }
59
+ }
@@ -59,6 +59,20 @@ module Decidim
59
59
  [present(model).author] +
60
60
  model.committee_members.approved.non_deleted.excluding_author.map { |member| present(member.user) }
61
61
  end
62
+
63
+ def has_image?
64
+ image.present?
65
+ end
66
+
67
+ def image
68
+ @image ||= model.attachments.find do |attachment|
69
+ attachment.file.content_type.start_with?("image")
70
+ end
71
+ end
72
+
73
+ def resource_image_path
74
+ image.url if has_image?
75
+ end
62
76
  end
63
77
  end
64
78
  end
@@ -1,30 +1,33 @@
1
1
  <br>
2
2
  <div class="initiatives-votes-table-row" style="width: 100%; display: inline-block; min-height: 33pt; border-bottom: 1pt solid black;">
3
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
3
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
4
4
  <%= initiative_id %>
5
5
  </div>
6
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
6
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
7
7
  <%= initiative_title %>
8
8
  </div>
9
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
9
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
10
10
  <%= name_and_surname %>
11
11
  </div>
12
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
12
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
13
13
  <%= document_number %>
14
14
  </div>
15
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
15
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
16
16
  <%= date_of_birth %>
17
17
  </div>
18
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
18
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
19
19
  <%= postal_code %>
20
20
  </div>
21
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
21
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
22
22
  <%= time_and_date %>
23
23
  </div>
24
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
24
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
25
25
  <%= timestamp %>
26
26
  </div>
27
- <div class="initiatives-votes-table-cell w11" style="width: 10.8%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
27
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
28
28
  <%= hash_id %>
29
29
  </div>
30
+ <div class="initiatives-votes-table-cell w11" style="width: 9.4%; padding-left: 5pt; word-wrap: break-word; display: inline-block; float: left; min-height: 36pt;">
31
+ <%= scope %>
32
+ </div>
30
33
  </div>
@@ -37,6 +37,13 @@ module Decidim
37
37
  model.created_at
38
38
  end
39
39
 
40
+ def scope
41
+ return I18n.t("decidim.scopes.global") if model.decidim_scope_id.nil?
42
+ return I18n.t("decidim.initiatives.unavailable_scope") if model.scope.blank?
43
+
44
+ translated_attribute(model.scope.name)
45
+ end
46
+
40
47
  protected
41
48
 
42
49
  def encryptor
@@ -51,7 +51,9 @@ module Decidim
51
51
  collect_user_extra_fields: form.collect_user_extra_fields,
52
52
  extra_fields_legal_information: form.extra_fields_legal_information,
53
53
  validate_sms_code_on_votes: form.validate_sms_code_on_votes,
54
- document_number_authorization_handler: form.document_number_authorization_handler
54
+ document_number_authorization_handler: form.document_number_authorization_handler,
55
+ child_scope_threshold_enabled: form.child_scope_threshold_enabled,
56
+ only_global_scope_enabled: form.only_global_scope_enabled
55
57
  )
56
58
 
57
59
  return initiative_type unless initiative_type.valid?
@@ -52,7 +52,9 @@ module Decidim
52
52
  collect_user_extra_fields: form.collect_user_extra_fields,
53
53
  extra_fields_legal_information: form.extra_fields_legal_information,
54
54
  validate_sms_code_on_votes: form.validate_sms_code_on_votes,
55
- document_number_authorization_handler: form.document_number_authorization_handler
55
+ document_number_authorization_handler: form.document_number_authorization_handler,
56
+ child_scope_threshold_enabled: form.child_scope_threshold_enabled,
57
+ only_global_scope_enabled: form.only_global_scope_enabled
56
58
  }
57
59
 
58
60
  result[:banner_image] = form.banner_image unless form.banner_image.nil?
@@ -5,11 +5,14 @@ module Decidim
5
5
  module AttachmentMethods
6
6
  private
7
7
 
8
- def build_attachment
8
+ def build_attachment(attached_to = nil)
9
+ attached_to = @attached_to if attached_to.blank?
10
+ attached_to = form.current_organization if attached_to.blank? && form.respond_to?(:current_organization)
11
+
9
12
  @attachment = Attachment.new(
10
- title: @form.attachment.title,
11
- file: @form.attachment.file,
12
- attached_to: @attached_to
13
+ title: { I18n.locale => @form.attachment.title },
14
+ attached_to: attached_to,
15
+ file: @form.attachment.file # Define attached_to before this
13
16
  )
14
17
  end
15
18
 
@@ -26,7 +29,8 @@ module Decidim
26
29
  end
27
30
 
28
31
  def process_attachments?
29
- @form.attachment && @form.attachment.file.present?
32
+ @form.attachment && @form.attachment.file.present? &&
33
+ !@form.attachment.file.is_a?(Decidim::ApplicationUploader)
30
34
  end
31
35
  end
32
36
  end
@@ -78,8 +78,8 @@ module Decidim
78
78
 
79
79
  def scoped_type
80
80
  InitiativesTypeScope.find_by(
81
- decidim_initiatives_types_id: form.type_id,
82
- decidim_scopes_id: form.scope_id
81
+ type: form.initiative_type,
82
+ scope: form.scope
83
83
  )
84
84
  end
85
85
 
@@ -8,11 +8,9 @@ module Decidim
8
8
  #
9
9
  # initiative - A Decidim::Initiative object.
10
10
  # current_user - The current user.
11
- # group_id - Decidim user group id
12
- def initialize(initiative, current_user, group_id)
11
+ def initialize(initiative, current_user)
13
12
  @initiative = initiative
14
13
  @current_user = current_user
15
- @decidim_user_group_id = group_id
16
14
  end
17
15
 
18
16
  # Executes the command. Broadcasts these events:
@@ -29,13 +27,9 @@ module Decidim
29
27
  private
30
28
 
31
29
  def destroy_initiative_vote
32
- @initiative
33
- .votes
34
- .where(
35
- author: @current_user,
36
- decidim_user_group_id: @decidim_user_group_id
37
- )
38
- .destroy_all
30
+ Initiative.transaction do
31
+ @initiative.votes.where(author: @current_user).destroy_all
32
+ end
39
33
  end
40
34
  end
41
35
  end
@@ -7,11 +7,8 @@ module Decidim
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
10
- # current_user - The current user.
11
- def initialize(form, current_user)
10
+ def initialize(form)
12
11
  @form = form
13
- @initiative = form.initiative
14
- @current_user = current_user
15
12
  end
16
13
 
17
14
  # Executes the command. Broadcasts these events:
@@ -23,41 +20,45 @@ module Decidim
23
20
  def call
24
21
  return broadcast(:invalid) if form.invalid?
25
22
 
26
- build_initiative_vote
27
- set_vote_timestamp
23
+ percentage_before = initiative.percentage
28
24
 
29
- percentage_before = @initiative.percentage
30
- vote.save!
31
- send_notification
32
- percentage_after = @initiative.reload.percentage
25
+ Initiative.transaction do
26
+ create_votes
27
+ end
28
+
29
+ percentage_after = initiative.reload.percentage
33
30
 
31
+ send_notification
34
32
  notify_percentage_change(percentage_before, percentage_after)
35
- notify_support_threshold_reached(percentage_after)
33
+ notify_support_threshold_reached(percentage_before, percentage_after)
36
34
 
37
- broadcast(:ok, vote)
35
+ broadcast(:ok, votes)
38
36
  end
39
37
 
40
- attr_reader :vote
38
+ attr_reader :votes
41
39
 
42
40
  private
43
41
 
44
- attr_reader :form, :current_user
42
+ attr_reader :form
45
43
 
46
- def build_initiative_vote
47
- @vote = @initiative.votes.build(
48
- author: @current_user,
49
- decidim_user_group_id: form.group_id,
50
- encrypted_metadata: form.encrypted_metadata,
51
- hash_id: form.hash_id
52
- )
44
+ delegate :initiative, to: :form
45
+
46
+ def create_votes
47
+ @votes = form.authorized_scopes.map do |scope|
48
+ initiative.votes.create!(
49
+ author: form.signer,
50
+ encrypted_metadata: form.encrypted_metadata,
51
+ timestamp: timestamp,
52
+ hash_id: form.hash_id,
53
+ scope: scope
54
+ )
55
+ end
53
56
  end
54
57
 
55
- def set_vote_timestamp
58
+ def timestamp
56
59
  return unless timestamp_service
57
60
 
58
- @vote.assign_attributes(
59
- timestamp: timestamp_service.new(document: vote.encrypted_metadata).timestamp
60
- )
61
+ @timestamp ||= timestamp_service.new(document: form.encrypted_metadata).timestamp
61
62
  end
62
63
 
63
64
  def timestamp_service
@@ -65,13 +66,11 @@ module Decidim
65
66
  end
66
67
 
67
68
  def send_notification
68
- return if vote.user_group.present?
69
-
70
69
  Decidim::EventsManager.publish(
71
70
  event: "decidim.events.initiatives.initiative_endorsed",
72
71
  event_class: Decidim::Initiatives::EndorseInitiativeEvent,
73
- resource: @initiative,
74
- followers: @initiative.author.followers
72
+ resource: initiative,
73
+ followers: initiative.author.followers
75
74
  )
76
75
  end
77
76
 
@@ -85,28 +84,29 @@ module Decidim
85
84
  Decidim::EventsManager.publish(
86
85
  event: "decidim.events.initiatives.milestone_completed",
87
86
  event_class: Decidim::Initiatives::MilestoneCompletedEvent,
88
- resource: @initiative,
89
- affected_users: [@initiative.author],
90
- followers: @initiative.followers - [@initiative.author],
87
+ resource: initiative,
88
+ affected_users: [initiative.author],
89
+ followers: initiative.followers - [initiative.author],
91
90
  extra: {
92
91
  percentage: percentage
93
92
  }
94
93
  )
95
94
  end
96
95
 
97
- def notify_support_threshold_reached(percentage)
98
- return unless percentage >= 100
96
+ def notify_support_threshold_reached(before, after)
97
+ # Don't need to notify if threshold has already been reached
98
+ return if before == after || after != 100
99
99
 
100
100
  Decidim::EventsManager.publish(
101
101
  event: "decidim.events.initiatives.support_threshold_reached",
102
102
  event_class: Decidim::Initiatives::Admin::SupportThresholdReachedEvent,
103
- resource: @initiative,
103
+ resource: initiative,
104
104
  followers: organization_admins
105
105
  )
106
106
  end
107
107
 
108
108
  def organization_admins
109
- Decidim::User.where(organization: @initiative.organization, admin: true)
109
+ Decidim::User.where(organization: initiative.organization, admin: true)
110
110
  end
111
111
  end
112
112
  end
@@ -24,7 +24,6 @@ module Decidim
24
24
  def update
25
25
  enforce_permission_to :answer, :initiative, initiative: current_initiative
26
26
 
27
- params[:id] = params[:slug]
28
27
  @form = form(Decidim::Initiatives::Admin::InitiativeAnswerForm)
29
28
  .from_params(params, initiative: current_initiative)
30
29
 
@@ -35,8 +34,8 @@ module Decidim
35
34
  end
36
35
 
37
36
  on(:invalid) do
38
- flash.now[:alert] = I18n.t("initiatives.update.error", scope: "decidim.initiatives.admin")
39
- render :edit
37
+ flash[:alert] = I18n.t("initiatives.update.error", scope: "decidim.initiatives.admin")
38
+ redirect_to edit_initiative_answer_path
40
39
  end
41
40
  end
42
41
  end
@@ -136,7 +136,7 @@ module Decidim
136
136
  def export_votes
137
137
  enforce_permission_to :export_votes, :initiative, initiative: current_initiative
138
138
 
139
- votes = current_initiative.votes.votes.map(&:sha1)
139
+ votes = current_initiative.votes.map(&:sha1)
140
140
  csv_data = CSV.generate(headers: false) do |csv|
141
141
  votes.each do |sha1|
142
142
  csv << [sha1]
@@ -152,7 +152,7 @@ module Decidim
152
152
  def export_pdf_signatures
153
153
  enforce_permission_to :export_pdf_signatures, :initiative, initiative: current_initiative
154
154
 
155
- @votes = current_initiative.votes.votes
155
+ @votes = current_initiative.votes
156
156
 
157
157
  output = render_to_string(
158
158
  pdf: "votes_#{current_initiative.id}",
@@ -144,7 +144,7 @@ module Decidim
144
144
  end
145
145
 
146
146
  def scopes
147
- @scopes ||= InitiativesTypeScope.where(decidim_initiatives_types_id: @form.type_id)
147
+ @scopes ||= @form.available_scopes
148
148
  end
149
149
 
150
150
  def current_initiative
@@ -20,39 +20,34 @@ module Decidim
20
20
 
21
21
  # GET /initiatives/:initiative_id/initiative_signatures/:step
22
22
  def show
23
- group_id = params[:group_id] || (session[:initiative_vote_form] ||= {})["group_id"]
24
- enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, group_id: group_id, signature_has_steps: signature_has_steps?
23
+ enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, signature_has_steps: signature_has_steps?
25
24
  send("#{step}_step", initiative_vote_form: session[:initiative_vote_form])
26
25
  end
27
26
 
28
27
  # PUT /initiatives/:initiative_id/initiative_signatures/:step
29
28
  def update
30
- group_id = params.dig(:initiatives_vote, :group_id) || session[:initiative_vote_form]["group_id"]
31
- enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, group_id: group_id, signature_has_steps: signature_has_steps?
29
+ enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, signature_has_steps: signature_has_steps?
32
30
  send("#{step}_step", params)
33
31
  end
34
32
 
35
33
  # POST /initiatives/:initiative_id/initiative_signatures
36
34
  def create
37
- group_id = params[:group_id] || session[:initiative_vote_form]&.dig("group_id")
38
- enforce_permission_to :vote, :initiative, initiative: current_initiative, group_id: group_id
35
+ enforce_permission_to :vote, :initiative, initiative: current_initiative
36
+
39
37
  @form = form(Decidim::Initiatives::VoteForm)
40
38
  .from_params(
41
- initiative_id: current_initiative.id,
42
- author_id: current_user.id,
43
- group_id: group_id
39
+ initiative: current_initiative,
40
+ signer: current_user
44
41
  )
45
42
 
46
- VoteInitiative.call(@form, current_user) do
43
+ VoteInitiative.call(@form) do
47
44
  on(:ok) do
48
45
  current_initiative.reload
49
46
  render :update_buttons_and_counters
50
47
  end
51
48
 
52
49
  on(:invalid) do
53
- render json: {
54
- error: I18n.t("create.error", scope: "decidim.initiatives.initiative_votes")
55
- }, status: :unprocessable_entity
50
+ render :error_on_vote, status: :unprocessable_entity
56
51
  end
57
52
  end
58
53
  end
@@ -62,11 +57,11 @@ module Decidim
62
57
  def fill_personal_data_step(_unused)
63
58
  @form = form(Decidim::Initiatives::VoteForm)
64
59
  .from_params(
65
- initiative_id: current_initiative.id,
66
- author_id: current_user.id,
67
- group_id: params[:group_id]
60
+ initiative: current_initiative,
61
+ signer: current_user
68
62
  )
69
- session[:initiative_vote_form] = { group_id: @form.group_id }
63
+
64
+ session[:initiative_vote_form] = {}
70
65
  skip_step unless initiative_type.collect_user_extra_fields
71
66
  render_wizard
72
67
  end
@@ -128,7 +123,7 @@ module Decidim
128
123
  end
129
124
  end
130
125
 
131
- VoteInitiative.call(@vote_form, current_user) do
126
+ VoteInitiative.call(@vote_form) do
132
127
  on(:ok) do
133
128
  session[:initiative_vote_form] = {}
134
129
  end
@@ -139,25 +134,24 @@ module Decidim
139
134
  jump_to previous_step
140
135
  end
141
136
  end
137
+
142
138
  render_wizard
143
139
  end
144
140
 
145
141
  def build_vote_form(parameters)
146
142
  @vote_form = form(Decidim::Initiatives::VoteForm).from_params(parameters).tap do |form|
147
- form.initiative_id = current_initiative.id
148
- form.author_id = current_user.id
143
+ form.initiative = current_initiative
144
+ form.signer = current_user
149
145
  end
150
146
 
151
- session[:initiative_vote_form] = session[:initiative_vote_form].merge(@vote_form.attributes_with_values)
147
+ session[:initiative_vote_form] ||= {}
148
+ session[:initiative_vote_form] = session[:initiative_vote_form].merge(@vote_form.attributes_with_values.except(:initiative, :signer))
152
149
  end
153
150
 
154
151
  def session_vote_form
155
- raw_birth_date = session[:initiative_vote_form]["date_of_birth"]
156
- return unless raw_birth_date
152
+ attributes = session[:initiative_vote_form].merge(initiative: current_initiative, signer: current_user)
157
153
 
158
- @vote_form = form(Decidim::Initiatives::VoteForm).from_params(
159
- session[:initiative_vote_form].merge("date_of_birth" => Date.parse(raw_birth_date))
160
- )
154
+ @vote_form = form(Decidim::Initiatives::VoteForm).from_params(attributes)
161
155
  end
162
156
 
163
157
  def initiative_type