decidim-initiatives 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) 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 +19 -23
  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 +133 -78
  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/initiative_stats_presenter.rb +1 -5
  32. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
  33. data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +39 -17
  34. data/app/views/decidim/initiatives/admin/initiatives/export_pdf_signatures.pdf.erb +12 -9
  35. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +35 -10
  36. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +28 -25
  37. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +18 -16
  38. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +0 -1
  39. data/app/views/decidim/initiatives/initiative_signatures/update_buttons_and_counters.js.erb +1 -1
  40. data/app/views/decidim/initiatives/initiative_votes/update_buttons_and_counters.js.erb +1 -1
  41. data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +36 -2
  42. data/app/views/decidim/initiatives/initiatives/_initiatives.html.erb +10 -0
  43. data/app/views/decidim/initiatives/initiatives/_progress_bar.html.erb +24 -9
  44. data/app/views/decidim/initiatives/initiatives/_vote_cabin.html.erb +1 -13
  45. data/app/views/decidim/initiatives/initiatives/show.html.erb +1 -3
  46. data/app/views/layouts/decidim/initiative.html.erb +1 -0
  47. data/config/locales/am-ET.yml +1 -0
  48. data/config/locales/ar.yml +0 -4
  49. data/config/locales/bg.yml +13 -0
  50. data/config/locales/ca.yml +22 -8
  51. data/config/locales/cs.yml +18 -4
  52. data/config/locales/da.yml +1 -0
  53. data/config/locales/de.yml +7 -4
  54. data/config/locales/el.yml +0 -4
  55. data/config/locales/en.yml +18 -4
  56. data/config/locales/eo.yml +1 -0
  57. data/config/locales/es-MX.yml +18 -4
  58. data/config/locales/es-PY.yml +18 -4
  59. data/config/locales/es.yml +31 -17
  60. data/config/locales/et.yml +1 -0
  61. data/config/locales/eu.yml +0 -14
  62. data/config/locales/fi-plain.yml +18 -4
  63. data/config/locales/fi.yml +18 -4
  64. data/config/locales/fr-CA.yml +32 -4
  65. data/config/locales/fr.yml +36 -8
  66. data/config/locales/gl.yml +0 -14
  67. data/config/locales/hr.yml +1 -0
  68. data/config/locales/hu.yml +5 -4
  69. data/config/locales/id-ID.yml +0 -14
  70. data/config/locales/is-IS.yml +0 -10
  71. data/config/locales/is.yml +251 -0
  72. data/config/locales/it.yml +9 -4
  73. data/config/locales/ja-JP.yml +43 -49
  74. data/config/locales/ja.yml +549 -0
  75. data/config/locales/ko-KR.yml +1 -0
  76. data/config/locales/ko.yml +1 -0
  77. data/config/locales/lt.yml +1 -0
  78. data/config/locales/{lv-LV.yml → lv.yml} +0 -4
  79. data/config/locales/mt.yml +1 -0
  80. data/config/locales/nl.yml +9 -4
  81. data/config/locales/no.yml +48 -4
  82. data/config/locales/om-ET.yml +1 -0
  83. data/config/locales/pl.yml +28 -22
  84. data/config/locales/pt-BR.yml +0 -14
  85. data/config/locales/pt.yml +5 -4
  86. data/config/locales/ro-RO.yml +5 -4
  87. data/config/locales/ru.yml +0 -14
  88. data/config/locales/sk.yml +0 -4
  89. data/config/locales/sl.yml +6 -0
  90. data/config/locales/so-SO.yml +1 -0
  91. data/config/locales/sv.yml +25 -5
  92. data/config/locales/ti-ER.yml +1 -0
  93. data/config/locales/tr-TR.yml +0 -14
  94. data/config/locales/uk.yml +0 -14
  95. data/config/locales/vi-VN.yml +1 -0
  96. data/config/locales/vi.yml +1 -0
  97. data/config/locales/zh-CN.yml +549 -0
  98. data/config/locales/zh-TW.yml +1 -0
  99. data/db/migrate/20191106144259_add_settings_to_initiatives_types.rb +8 -0
  100. data/db/migrate/20191107134847_add_scopes_to_initiatives_votes.rb +28 -0
  101. data/db/migrate/20191116170841_allow_multiple_initiative_votes_counter_caches.rb +32 -0
  102. data/db/migrate/20191118105634_allow_multiple_offline_votes.rb +34 -0
  103. data/db/migrate/20200528151456_remove_user_groups_from_initiative_votes.rb +7 -0
  104. data/db/migrate/20200827154214_add_commentable_counter_cache_to_initiatives.rb +9 -0
  105. data/db/seeds/city.jpeg +0 -0
  106. data/lib/decidim/initiatives/admin_engine.rb +1 -0
  107. data/lib/decidim/initiatives/engine.rb +2 -2
  108. data/lib/decidim/initiatives/participatory_space.rb +7 -0
  109. data/lib/decidim/initiatives/test/factories.rb +21 -3
  110. data/lib/decidim/initiatives/version.rb +1 -1
  111. data/lib/tasks/decidim_initiatives.rake +1 -3
  112. metadata +42 -18
  113. data/app/views/decidim/initiatives/initiatives/_supports.html.erb +0 -22
  114. 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: d8db51bc1501da471466745ec235929fd21b662ddce6dbb88eef462b1e476c02
4
+ data.tar.gz: 0aadaf993de40321e50400b7dbf76ccd06f71ec24255a2e98190e52688ce6f2a
5
5
  SHA512:
6
- metadata.gz: 077066ebe56b6f9f8fdb094afe847261f70809c23d37d79a90c75aa67107e52dad6f7d875269531198e3a28a5cbea1960484ac04ed7557e03cb4fd4b4d4dc417
7
- data.tar.gz: c5eba0295d92b0be850c4ab997f2bbc3fb854641a57eb44893bbbcfbac25b6fc8a0c74bc7f5e102e1ef6b2650345e3122d74d955c63a79bea0105dbe39a5d296
6
+ metadata.gz: 22090c6da32e3b58852a92c485cd25a309b188e45047a8e30c1a6d9d6d43e5c971fa427804e759673ef0db26e48dfbc262f5b6da3a58893046d15f95a8d87b02
7
+ data.tar.gz: d9a8c3349b8be9f88cebda3a177249823c16cac21390b4e1e8f9db9c1dd8ebbba7ca472526b5853b78656bdc0cd5985f67897e1a4c32bd246e36606f2fa18f7f
@@ -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,30 +20,27 @@ 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
@@ -62,11 +59,11 @@ module Decidim
62
59
  def fill_personal_data_step(_unused)
63
60
  @form = form(Decidim::Initiatives::VoteForm)
64
61
  .from_params(
65
- initiative_id: current_initiative.id,
66
- author_id: current_user.id,
67
- group_id: params[:group_id]
62
+ initiative: current_initiative,
63
+ signer: current_user
68
64
  )
69
- session[:initiative_vote_form] = { group_id: @form.group_id }
65
+
66
+ session[:initiative_vote_form] = {}
70
67
  skip_step unless initiative_type.collect_user_extra_fields
71
68
  render_wizard
72
69
  end
@@ -128,7 +125,7 @@ module Decidim
128
125
  end
129
126
  end
130
127
 
131
- VoteInitiative.call(@vote_form, current_user) do
128
+ VoteInitiative.call(@vote_form) do
132
129
  on(:ok) do
133
130
  session[:initiative_vote_form] = {}
134
131
  end
@@ -139,25 +136,24 @@ module Decidim
139
136
  jump_to previous_step
140
137
  end
141
138
  end
139
+
142
140
  render_wizard
143
141
  end
144
142
 
145
143
  def build_vote_form(parameters)
146
144
  @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
145
+ form.initiative = current_initiative
146
+ form.signer = current_user
149
147
  end
150
148
 
151
- session[:initiative_vote_form] = session[:initiative_vote_form].merge(@vote_form.attributes_with_values)
149
+ session[:initiative_vote_form] ||= {}
150
+ session[:initiative_vote_form] = session[:initiative_vote_form].merge(@vote_form.attributes_with_values.except(:initiative, :signer))
152
151
  end
153
152
 
154
153
  def session_vote_form
155
- raw_birth_date = session[:initiative_vote_form]["date_of_birth"]
156
- return unless raw_birth_date
154
+ attributes = session[:initiative_vote_form].merge(initiative: current_initiative, signer: current_user)
157
155
 
158
- @vote_form = form(Decidim::Initiatives::VoteForm).from_params(
159
- session[:initiative_vote_form].merge("date_of_birth" => Date.parse(raw_birth_date))
160
- )
156
+ @vote_form = form(Decidim::Initiatives::VoteForm).from_params(attributes)
161
157
  end
162
158
 
163
159
  def initiative_type