decidim-core 0.31.4 → 0.31.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/amendable/amend_button_card/show.erb +2 -2
  3. data/app/cells/decidim/author_cell.rb +0 -4
  4. data/app/cells/decidim/content_blocks/cta_settings_form/show.erb +1 -1
  5. data/app/cells/decidim/content_blocks/hero_settings_form/show.erb +2 -2
  6. data/app/cells/decidim/content_blocks/highlighted_content_banner_cell.rb +1 -1
  7. data/app/cells/decidim/content_blocks/highlighted_content_banner_settings_form/show.erb +1 -1
  8. data/app/cells/decidim/content_blocks/highlighted_participatory_spaces_cell.rb +1 -1
  9. data/app/cells/decidim/content_blocks/html_cell.rb +1 -1
  10. data/app/cells/decidim/content_blocks/participatory_space_hero_settings_form/show.erb +1 -1
  11. data/app/cells/decidim/content_blocks/static_page/section_cell.rb +1 -1
  12. data/app/cells/decidim/content_blocks/static_page/section_settings_form/show.erb +3 -1
  13. data/app/cells/decidim/content_blocks/static_page/summary_cell.rb +1 -1
  14. data/app/cells/decidim/content_blocks/static_page/summary_settings_form/show.erb +3 -1
  15. data/app/cells/decidim/content_blocks/static_page/two_pane_section_cell.rb +2 -2
  16. data/app/cells/decidim/content_blocks/static_page/two_pane_section_settings_form/show.erb +4 -2
  17. data/app/cells/decidim/data_consent/category.erb +5 -5
  18. data/app/cells/decidim/resource_types_filter/show.erb +2 -2
  19. data/app/cells/decidim/upload_modal_cell.rb +5 -0
  20. data/app/commands/decidim/destroy_account.rb +12 -1
  21. data/app/commands/decidim/multiple_attachments_methods.rb +28 -27
  22. data/app/controllers/concerns/decidim/devise_controllers.rb +10 -0
  23. data/app/controllers/decidim/download_your_data_controller.rb +1 -1
  24. data/app/controllers/decidim/notifications_subscriptions_controller.rb +8 -0
  25. data/app/controllers/decidim/private_downloads_controller.rb +29 -0
  26. data/app/jobs/decidim/process_inactive_participant_job.rb +0 -7
  27. data/app/mailers/decidim/delete_user_mailer.rb +14 -0
  28. data/app/mailers/decidim/participants_account_mailer.rb +0 -16
  29. data/app/models/decidim/attachment.rb +20 -2
  30. data/app/models/decidim/authorization.rb +7 -0
  31. data/app/models/decidim/moderation.rb +1 -1
  32. data/app/models/decidim/participatory_space_private_user.rb +1 -1
  33. data/app/models/decidim/private_download.rb +61 -0
  34. data/app/models/decidim/private_export.rb +6 -0
  35. data/app/models/decidim/user_base_entity.rb +17 -2
  36. data/app/models/decidim/user_moderation.rb +1 -1
  37. data/app/packs/src/decidim/controllers/form_validator/form_validator.js +6 -6
  38. data/app/packs/src/decidim/controllers/form_validator/form_validator.test.js +23 -1
  39. data/app/packs/src/decidim/controllers/mention/controller.js +296 -140
  40. data/app/packs/src/decidim/controllers/mention/input_mentions.test.js +120 -457
  41. data/app/packs/src/decidim/controllers/multiple_mentions/controller.js +68 -32
  42. data/app/packs/src/decidim/controllers/multiple_mentions/input_multiple_mentions.test.js +30 -23
  43. data/app/packs/src/decidim/direct_uploads/upload_field.js +4 -4
  44. data/app/packs/src/decidim/direct_uploads/upload_modal.js +11 -7
  45. data/app/packs/src/decidim/geocoding/reverse_geocoding.js +15 -5
  46. data/app/packs/src/decidim/geocoding/reverse_geocoding.test.js +197 -0
  47. data/app/packs/src/decidim/index.js +4 -3
  48. data/app/packs/src/decidim/sw/push-permissions.js +48 -13
  49. data/app/packs/src/decidim/sw/sw.js +1 -1
  50. data/app/packs/src/decidim/utilities/text.js +6 -6
  51. data/app/packs/stylesheets/decidim/_conversations.scss +14 -0
  52. data/app/packs/stylesheets/decidim/_editor_suggestions.scss +49 -0
  53. data/app/packs/stylesheets/decidim/_floating_help.scss +1 -1
  54. data/app/packs/stylesheets/decidim/_tom_select.scss +23 -0
  55. data/app/packs/stylesheets/decidim/application.scss +2 -0
  56. data/app/packs/stylesheets/decidim/editor.scss +2 -33
  57. data/app/packs/stylesheets/decidim/geocoding_addons.scss +10 -2
  58. data/app/presenters/decidim/menu_item_presenter.rb +9 -3
  59. data/app/presenters/decidim/stats_presenter.rb +1 -1
  60. data/app/services/decidim/notifications_subscriptions_persistor.rb +6 -0
  61. data/app/services/decidim/push_subscription_endpoint_validator.rb +34 -0
  62. data/app/services/decidim/send_push_notification.rb +5 -1
  63. data/app/uploaders/decidim/image_uploader.rb +1 -1
  64. data/app/views/decidim/delete_user_mailer/delete.html.erb +6 -0
  65. data/app/views/decidim/gamification/badges/index.html.erb +1 -1
  66. data/app/views/decidim/homepage/show.html.erb +1 -1
  67. data/app/views/decidim/last_activities/index.html.erb +1 -1
  68. data/app/views/decidim/messaging/conversations/_error_modal.html.erb +11 -19
  69. data/app/views/decidim/messaging/conversations/error.js.erb +12 -7
  70. data/app/views/decidim/newsletters/unsubscribe.html.erb +1 -1
  71. data/app/views/decidim/notifications_settings/show.html.erb +5 -5
  72. data/app/views/decidim/offline/show.html.erb +1 -1
  73. data/app/views/decidim/pages/index.html.erb +1 -1
  74. data/app/views/decidim/profiles/show.html.erb +1 -1
  75. data/app/views/decidim/shared/_resource_actions.html.erb +4 -4
  76. data/app/views/decidim/user_activities/index.html.erb +1 -1
  77. data/app/views/layouts/decidim/_wrapper.html.erb +2 -2
  78. data/app/views/layouts/decidim/header/_menu_breadcrumb_mobile_tablet.html.erb +1 -1
  79. data/app/views/layouts/decidim/shared/_layout_center.html.erb +1 -1
  80. data/app/views/layouts/decidim/shared/_layout_item.html.erb +1 -1
  81. data/app/views/layouts/decidim/shared/_layout_two_col.html.erb +1 -1
  82. data/config/locales/ar.yml +0 -5
  83. data/config/locales/bg.yml +0 -6
  84. data/config/locales/ca-IT.yml +10 -10
  85. data/config/locales/ca.yml +10 -10
  86. data/config/locales/cs.yml +4 -13
  87. data/config/locales/de.yml +5 -17
  88. data/config/locales/el.yml +0 -4
  89. data/config/locales/en.yml +9 -9
  90. data/config/locales/es-MX.yml +9 -9
  91. data/config/locales/es-PY.yml +9 -9
  92. data/config/locales/es.yml +9 -9
  93. data/config/locales/eu.yml +49 -49
  94. data/config/locales/fi-plain.yml +9 -9
  95. data/config/locales/fi.yml +11 -11
  96. data/config/locales/fr-CA.yml +10 -9
  97. data/config/locales/fr.yml +10 -9
  98. data/config/locales/gl.yml +0 -3
  99. data/config/locales/hu.yml +0 -5
  100. data/config/locales/id-ID.yml +0 -3
  101. data/config/locales/it.yml +11 -3
  102. data/config/locales/ja.yml +24 -21
  103. data/config/locales/lb.yml +0 -5
  104. data/config/locales/lt.yml +0 -5
  105. data/config/locales/lv.yml +0 -3
  106. data/config/locales/nl.yml +0 -5
  107. data/config/locales/no.yml +0 -5
  108. data/config/locales/pl.yml +2 -8
  109. data/config/locales/pt-BR.yml +3 -16
  110. data/config/locales/pt.yml +0 -5
  111. data/config/locales/ro-RO.yml +1 -14
  112. data/config/locales/sk.yml +1408 -4
  113. data/config/locales/sv.yml +3 -11
  114. data/config/locales/tr-TR.yml +0 -6
  115. data/config/locales/zh-CN.yml +0 -5
  116. data/config/locales/zh-TW.yml +0 -5
  117. data/config/routes.rb +1 -0
  118. data/lib/decidim/api/functions/user_entity_list.rb +2 -0
  119. data/lib/decidim/attachment_attributes.rb +58 -9
  120. data/lib/decidim/command.rb +1 -1
  121. data/lib/decidim/content_renderers/base_renderer.rb +112 -0
  122. data/lib/decidim/content_renderers/blob_renderer.rb +4 -7
  123. data/lib/decidim/content_renderers/mention_resource_renderer.rb +10 -6
  124. data/lib/decidim/content_renderers/resource_renderer.rb +16 -7
  125. data/lib/decidim/content_renderers/user_renderer.rb +11 -9
  126. data/lib/decidim/core/content_blocks/registry_manager.rb +4 -4
  127. data/lib/decidim/core/engine.rb +8 -0
  128. data/lib/decidim/core/test/factories.rb +3 -0
  129. data/lib/decidim/core/test/shared_examples/admin_resource_gallery_examples.rb +10 -10
  130. data/lib/decidim/core/test/shared_examples/comments_examples.rb +6 -6
  131. data/lib/decidim/core/version.rb +1 -1
  132. data/lib/decidim/map/autocomplete.rb +4 -3
  133. data/lib/decidim/searchable.rb +5 -0
  134. data/lib/decidim/view_model.rb +1 -1
  135. data/lib/tasks/decidim_mailers_tasks.rake +31 -9
  136. metadata +14 -10
  137. data/app/commands/decidim/gallery_methods.rb +0 -107
  138. data/app/packs/src/decidim/vendor/tribute.js +0 -1890
  139. data/app/packs/stylesheets/decidim/_tribute.scss +0 -36
  140. data/app/views/decidim/participants_account_mailer/removal_notification.html.erb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 513dc9560cc17e12439bcef89efbb034edc6300b791810f2037bbb64191805a6
4
- data.tar.gz: 99d7f076a772765592d34f5164659c5f4d0826edb4d146d5917fff28e02dc922
3
+ metadata.gz: 1625dd1f860a4431caaae18f96ec93ee1751d8d135bde4da819eddbf4976e0d3
4
+ data.tar.gz: ff6293ab292f7c3a18d663a524a099754d63c59dbc4d15e81ca7664f6fc74bff
5
5
  SHA512:
6
- metadata.gz: d8928571dc994667af951c63981ce2472ce1be5db0c477beb27cadfc2ac43b6cfa87f1a8ab6854483cd00ce46fb1856adacf593ad4e159e7e1a46dc3ae099b87
7
- data.tar.gz: e03706f2aadaac2165c6a513a5b1284011bda181ab5a29683fe5983e616c880fd9c7a6ff15cbf1619fb6d6f658eb30df40e4d151cb81f12b0bdbd16c7848b224
6
+ metadata.gz: 4403452ffb2df3d9ef2c5c1dd911321cffcfcfaa89ab1d4bf1b32542acc6a2a3e15ad6410a23538bd98cb33ec57496d58de2015022f3a1ce52f77a901d776d99
7
+ data.tar.gz: c385ae7331b4c38b6a2b3a0679340e4739ee9da30535daea878690279776b68e1b5652951bc2151b06959935343a56dd0cbd0d7e066ccc97329dcf4712694862
@@ -1,5 +1,5 @@
1
- <li role="menuitem" class="dropdown__item">
2
- <%= action_authorized_link_to :amend, new_amend_path, resource: model, data: { "redirect_url" => new_amend_path }, id: "amend-button", class: "dropdown__button" do %>
1
+ <li role="presentation" class="dropdown__item">
2
+ <%= action_authorized_link_to :amend, new_amend_path, resource: model, data: { "redirect_url" => new_amend_path }, id: "amend-button", class: "dropdown__button", role: "menuitem" do %>
3
3
  <span><%= t("button", scope: "decidim.amendments.amendable", model_name: nil) %></span>
4
4
  <%= icon "pencil-line" %>
5
5
  <% end %>
@@ -31,10 +31,6 @@ module Decidim
31
31
  render unless current_user == model
32
32
  end
33
33
 
34
- def perform_caching?
35
- true
36
- end
37
-
38
34
  def raw_model
39
35
  model.try(:__getobj__) || model
40
36
  end
@@ -4,6 +4,6 @@
4
4
  <%= settings_fields.translated :text_field, :description, label: t("decidim.content_blocks.cta_settings_form.description") %>
5
5
  <% end %>
6
6
 
7
- <% form.fields_for :images, form.object.images do |images_fields| %>
7
+ <% form.fields_for :images, content_block.images_container do |images_fields| %>
8
8
  <%= images_fields.upload :background_image, label: t("decidim.content_blocks.cta_settings_form.background_image") %>
9
9
  <% end %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  <div class="row column" data-controller="slug">
7
7
  <%= settings_fields.translated :text_field, :cta_button_path, label: t(".cta_button_path") %>
8
- <p class="help-text"><%= t(".cta_button_path_help", url: decidim_form_slug_url("", translated_attribute(form.object.settings.cta_button_path))) %></p>
8
+ <p class="help-text"><%= t(".cta_button_path_help", url: decidim_form_slug_url("", translated_attribute(form.object.settings["cta_button_path"]))) %></p>
9
9
  </div>
10
10
 
11
11
  <div class="row column">
@@ -14,7 +14,7 @@
14
14
  </div>
15
15
  <% end %>
16
16
 
17
- <% form.fields_for :images, form.object.images do |images_fields| %>
17
+ <% form.fields_for :images, content_block.images_container do |images_fields| %>
18
18
  <div class="row column">
19
19
  <%= images_fields.upload :background_image, label: t(".background_image"), button_class: "button button__sm button__transparent-secondary" %>
20
20
  </div>
@@ -32,7 +32,7 @@ module Decidim
32
32
  private
33
33
 
34
34
  def render?
35
- required_keys = [:title, :short_description, :action_button_title, :action_button_subtitle, :action_button_url]
35
+ required_keys = [:title, :action_button_title, :action_button_subtitle, :action_button_url]
36
36
  required_keys.all? { |key| model.settings.public_send(key).present? }
37
37
  end
38
38
  end
@@ -20,7 +20,7 @@
20
20
  </div>
21
21
  <% end %>
22
22
 
23
- <% form.fields_for :images, form.object.images do |images_fields| %>
23
+ <% form.fields_for :images, content_block.images_container do |images_fields| %>
24
24
  <div class="row column">
25
25
  <%= images_fields.upload :background_image, label: t(".background_image"), button_class: "button button__sm button__transparent-secondary" %>
26
26
  </div>
@@ -28,7 +28,7 @@ module Decidim
28
28
  private
29
29
 
30
30
  def cache_hash
31
- [I18n.locale, highlighted_spaces.map(&:cache_key_with_version)].join(Decidim.cache_key_separator)
31
+ [I18n.locale, model.cache_key_with_version, highlighted_spaces.map(&:cache_key_with_version)].join(Decidim.cache_key_separator)
32
32
  end
33
33
 
34
34
  def section_class
@@ -8,7 +8,7 @@ module Decidim
8
8
  end
9
9
 
10
10
  def html_content
11
- translated_attribute(model.settings.html_content).html_safe
11
+ decidim_sanitize_editor_admin(translated_attribute(model.settings.html_content))
12
12
  end
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@
8
8
  </div>
9
9
  <% end %>
10
10
 
11
- <% form.fields_for :images, form.object.images do |images_fields| %>
11
+ <% form.fields_for :images, content_block.images_container do |images_fields| %>
12
12
  <div class="row column">
13
13
  <%= images_fields.upload :background_image, label: t("decidim.content_blocks.cta_settings_form.background_image"), button_class: "button button__sm button__transparent-secondary" %>
14
14
  </div>
@@ -5,7 +5,7 @@ module Decidim
5
5
  module StaticPage
6
6
  class SectionCell < Decidim::ViewModel
7
7
  def content
8
- translated_attribute(model.settings.content).html_safe
8
+ decidim_sanitize_editor_admin(translated_attribute(model.settings.content))
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,5 @@
1
1
  <% form.fields_for :settings, form.object.settings do |settings_fields| %>
2
- <%= settings_fields.translated :editor, :content, label: %>
2
+ <div class="row column">
3
+ <%= settings_fields.translated :editor, :content, label: %>
4
+ </div>
3
5
  <% end %>
@@ -5,7 +5,7 @@ module Decidim
5
5
  module StaticPage
6
6
  class SummaryCell < Decidim::ViewModel
7
7
  def content
8
- translated_attribute(model.settings.summary).html_safe
8
+ decidim_sanitize_editor_admin(translated_attribute(model.settings.summary))
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,5 @@
1
1
  <% form.fields_for :settings, form.object.settings do |settings_fields| %>
2
- <%= settings_fields.translated :editor, :summary, label: %>
2
+ <div class="row column">
3
+ <%= settings_fields.translated :editor, :summary, label: %>
4
+ </div>
3
5
  <% end %>
@@ -5,11 +5,11 @@ module Decidim
5
5
  module StaticPage
6
6
  class TwoPaneSectionCell < Decidim::ViewModel
7
7
  def left_column
8
- translated_attribute(model.settings.left_column).html_safe
8
+ decidim_sanitize_editor_admin(translated_attribute(model.settings.left_column))
9
9
  end
10
10
 
11
11
  def right_column
12
- translated_attribute(model.settings.right_column).html_safe
12
+ decidim_sanitize_editor_admin(translated_attribute(model.settings.right_column))
13
13
  end
14
14
  end
15
15
  end
@@ -1,4 +1,6 @@
1
1
  <% form.fields_for :settings, form.object.settings do |settings_fields| %>
2
- <%= settings_fields.translated :editor, :left_column, label: label_left_column %>
3
- <%= settings_fields.translated :editor, :right_column, label: label_right_column %>
2
+ <div class="row column">
3
+ <%= settings_fields.translated :editor, :left_column, label: label_left_column %>
4
+ <%= settings_fields.translated :editor, :right_column, label: label_right_column %>
5
+ </div>
4
6
  <% end %>
@@ -13,12 +13,12 @@
13
13
  <%= icon "close-line", class: "cookies__category-toggle-icon" %>
14
14
  </label>
15
15
 
16
- <div id="accordion-trigger-<%= category[:slug] %>" data-controls="accordion-panel-<%= category[:slug] %>" aria-labelledby="accordion-title-<%= category[:slug] %>">
17
- <h3 id="accordion-title-<%= category[:slug] %>" class="cookies__category-trigger-title">
18
- <%= category[:title] %>
19
- </h3>
16
+ <h3 id="accordion-title-<%= category[:slug] %>" class="cookies__category-trigger-title">
17
+ <%= category[:title] %>
18
+ </h3>
20
19
 
21
- <span>
20
+ <div id="accordion-trigger-<%= category[:slug] %>" role="group" data-controls="accordion-panel-<%= category[:slug] %>" aria-labelledby="accordion-title-<%= category[:slug] %>">
21
+ <span aria-hidden="true">
22
22
  <%= icon "arrow-down-s-line", class: "cookies__category-trigger-arrow" %>
23
23
  <%= icon "arrow-up-s-line", class: "cookies__category-trigger-arrow" %>
24
24
  </span>
@@ -10,8 +10,8 @@
10
10
  </button>
11
11
  <ul id="dropdown-menu-resource">
12
12
  <% resource_types.each do |resource_type| %>
13
- <li role="menuitem">
14
- <%= link_to filter_url(resource_type[0]), class: "filter#{" is-active" if filter_param == resource_type[0]}" do %>
13
+ <li role="presentation">
14
+ <%= link_to filter_url(resource_type[0]), class: "filter#{" is-active" if filter_param == resource_type[0]}", role: "menuitem" do %>
15
15
  <span class="sr-only"><%= resource_type[1] %></span>
16
16
  <%= text_with_resource_icon(*resource_type) %>
17
17
  <% end %>
@@ -177,6 +177,11 @@ module Decidim
177
177
 
178
178
  def file_attachment_path(attachment)
179
179
  return unless attachment
180
+
181
+ if attachment.respond_to?(:record) && attachment.record.is_a?(Decidim::Authorization) && attachment.name.to_s == "verification_attachment"
182
+ return decidim.private_download_path(Decidim::PrivateDownload.for(attachment.record, attachment_name: attachment.name).token)
183
+ end
184
+
180
185
  return Rails.application.routes.url_helpers.rails_blob_url(attachment, only_path: true) if attachment.is_a? ActiveStorage::Blob
181
186
 
182
187
  if attachment.try(:attached?)
@@ -15,7 +15,7 @@ module Decidim
15
15
  def call
16
16
  return broadcast(:invalid) unless @form.valid?
17
17
 
18
- Decidim::User.transaction do
18
+ with_events(with_transaction: true) do
19
19
  destroy_user_account!
20
20
  destroy_user_identities
21
21
  destroy_follows
@@ -110,5 +110,16 @@ module Decidim
110
110
  space_manifest.invoke_on_destroy_account(current_user)
111
111
  end
112
112
  end
113
+
114
+ # We use memoization in this particular email, as we want to have the data available before the actual anonymization
115
+ def event_arguments
116
+ @event_arguments ||= {
117
+ user_id: current_user.id,
118
+ user_email: current_user.email,
119
+ user_name: current_user.name,
120
+ locale: current_user.locale,
121
+ organization: current_user.organization
122
+ }
123
+ end
113
124
  end
114
125
  end
@@ -5,16 +5,16 @@ module Decidim
5
5
  private
6
6
 
7
7
  def build_attachments
8
- @documents = []
9
- @form.add_documents.compact_blank.each do |attachment|
8
+ @attachments = []
9
+ @form.add_attachments.compact_blank.each do |attachment|
10
10
  if attachment.is_a?(Hash) && attachment.has_key?(:id)
11
11
  update_attachment_title_for(attachment)
12
12
  next
13
13
  end
14
14
 
15
- @documents << Attachment.new(
15
+ @attachments << Attachment.new(
16
16
  title: title_for(attachment),
17
- attached_to: @attached_to || documents_attached_to,
17
+ attached_to: @attached_to || attachments_attached_to,
18
18
  file: signed_id_for(attachment),
19
19
  content_type: content_type_for(attachment)
20
20
  )
@@ -26,11 +26,11 @@ module Decidim
26
26
  end
27
27
 
28
28
  def attachments_invalid?
29
- @documents.each do |document|
30
- next if document.valid? || !document.errors.has_key?(:file)
29
+ @attachments.each do |attachment|
30
+ next if attachment.valid? || !attachment.errors.has_key?(:file)
31
31
 
32
- document.errors[:file].each do |error|
33
- @form.errors.add(:add_documents, error)
32
+ attachment.errors[:file].each do |error|
33
+ @form.errors.add(:add_attachments, error)
34
34
  end
35
35
 
36
36
  return true
@@ -41,37 +41,38 @@ module Decidim
41
41
 
42
42
  def create_attachments(first_weight: 0)
43
43
  weight = first_weight
44
- # Add the weights first to the old documents
45
- document_ids = keep_ids
46
- Decidim::Attachment.where(id: document_ids).each do |document|
47
- document.update!(weight:)
44
+ # Add the weights first to the old attachments
45
+ attachment_ids = keep_ids
46
+ Decidim::Attachment.where(id: attachment_ids).each do |attachment|
47
+ attachment.update!(weight:)
48
48
  weight += 1
49
49
  end
50
- @documents.map! do |document|
51
- document.weight = weight
52
- document.attached_to = documents_attached_to
53
- document.save!
50
+ @attachments.map! do |attachment|
51
+ attachment.weight = weight
52
+ attachment.attached_to = attachments_attached_to
53
+ attachment.save!
54
54
  weight += 1
55
- @form.documents << document
55
+ @form.attachments << attachment
56
56
  end
57
57
  end
58
58
 
59
- def document_cleanup!(include_all_attachments: false)
60
- documents = include_all_attachments ? documents_attached_to.attachments.with_attached_file : documents_attached_to.documents
59
+ def attachment_cleanup!(include_all_attachments: false)
60
+ attachments = include_all_attachments ? attachments_attached_to.attachments.with_attached_file : attachments_attached_to.attachments
61
61
 
62
- documents.each do |document|
63
- document.destroy! unless keep_ids.include?(document.id)
62
+ attachments.each do |attachment|
63
+ attachment.destroy! unless keep_ids.include?(attachment.id)
64
64
  end
65
65
 
66
- documents_attached_to.reload
67
- documents_attached_to.instance_variable_set(:@documents, nil)
66
+ attachments_attached_to.reload
67
+ attachments_attached_to.instance_variable_set(:@attachments, nil)
68
+ attachments_attached_to.instance_variable_set(:@photos, nil)
68
69
  end
69
70
 
70
71
  def process_attachments?
71
- @form.add_documents.any?
72
+ @form.add_attachments.any?
72
73
  end
73
74
 
74
- def documents_attached_to
75
+ def attachments_attached_to
75
76
  return @attached_to if @attached_to.present?
76
77
  return form.current_organization if form.respond_to?(:current_organization)
77
78
 
@@ -101,8 +102,8 @@ module Decidim
101
102
  end
102
103
 
103
104
  def keep_ids
104
- documents_array = Array(@form.documents)
105
- documents_array.map do |doc|
105
+ attachments_array = Array(@form.attachments)
106
+ attachments_array.map do |doc|
106
107
  case doc
107
108
  when Decidim::Attachment
108
109
  doc.id
@@ -41,6 +41,10 @@ module Decidim
41
41
 
42
42
  layout "layouts/decidim/application"
43
43
 
44
+ # Ensure locale is set before Devise's own prepended callbacks and reset
45
+ # after the request finishes.
46
+ prepend_around_action :set_current_locale
47
+
44
48
  # Saves the location before loading each page so we can return to the
45
49
  # right page.
46
50
  before_action :store_current_location
@@ -58,6 +62,12 @@ module Decidim
58
62
 
59
63
  store_location_for(:user, redirect_url)
60
64
  end
65
+
66
+ def set_current_locale(&)
67
+ locale = detect_locale
68
+ locale = default_locale unless available_locales.include?(locale)
69
+ I18n.with_locale(locale, &)
70
+ end
61
71
  end
62
72
  end
63
73
  end
@@ -50,7 +50,7 @@ module Decidim
50
50
  flash[:error] = t("decidim.account.download_your_data_export.export_expired")
51
51
  redirect_to download_your_data_path
52
52
  elsif private_export.file.attached?
53
- redirect_to Rails.application.routes.url_helpers.rails_blob_url(private_export.file.blob, only_path: true)
53
+ redirect_to private_download_path(Decidim::PrivateDownload.for(private_export, attachment_name: :file).token)
54
54
  else
55
55
  flash[:error] = t("decidim.account.download_your_data_export.file_no_exists")
56
56
  redirect_to download_your_data_path
@@ -3,6 +3,8 @@
3
3
  module Decidim
4
4
  # The controller to handle the subscriptions to push notifications
5
5
  class NotificationsSubscriptionsController < Decidim::ApplicationController
6
+ rescue_from Decidim::NotificationsSubscriptionsPersistor::UnsupportedPushSubscriptionEndpointError, with: :unsupported_browser
7
+
6
8
  def create
7
9
  Decidim::NotificationsSubscriptionsPersistor.new(current_user).add_subscription(params)
8
10
  head :ok
@@ -12,5 +14,11 @@ module Decidim
12
14
  Decidim::NotificationsSubscriptionsPersistor.new(current_user).delete_subscription(params[:auth])
13
15
  head :ok
14
16
  end
17
+
18
+ private
19
+
20
+ def unsupported_browser
21
+ render json: { error: I18n.t("notifications_settings.show.push_notifications_unsupported_browser", scope: "decidim") }, status: :unprocessable_entity
22
+ end
15
23
  end
16
24
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class PrivateDownloadsController < Decidim::ApplicationController
5
+ before_action :authenticate_user!
6
+
7
+ def show
8
+ return head :not_found unless private_download.attached?
9
+ return head :not_found unless private_download.authorized_for?(current_user)
10
+
11
+ disposition = private_download.attachment.content_type.start_with?("image/") ? :inline : :attachment
12
+
13
+ send_data(
14
+ private_download.attachment.download,
15
+ filename: private_download.attachment.filename.to_s,
16
+ type: private_download.attachment.content_type,
17
+ disposition:
18
+ )
19
+ rescue Decidim::PrivateDownload::InvalidTokenError
20
+ head :not_found
21
+ end
22
+
23
+ private
24
+
25
+ def private_download
26
+ @private_download ||= Decidim::PrivateDownload.from_token(params[:id])
27
+ end
28
+ end
29
+ end
@@ -31,13 +31,6 @@ module Decidim
31
31
  end
32
32
 
33
33
  def process_remove_user(user)
34
- email = user.email
35
- name = user.name
36
- locale = user.locale
37
- organization = user.organization
38
-
39
- ParticipantsAccountMailer.removal_notification(email, name, locale, organization).deliver_later
40
-
41
34
  Decidim::DestroyAccount.call(
42
35
  Decidim::DeleteAccountForm.from_params(
43
36
  delete_reason: I18n.t("decidim.account.destroy.inactive_account_removal_reason", inactivity_period: Decidim.delete_inactive_users_after_days)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class DeleteUserMailer < ApplicationMailer
5
+ # This email is being sent when a user deletes his own account, or when the user was inactive for too long.
6
+ def delete(user_email:, user_name:, locale:, organization:)
7
+ I18n.with_locale(locale) do
8
+ @user_name = user_name
9
+ @organization = organization
10
+ mail(to: user_email, subject: I18n.t("decidim.delete_user_mailer.subject"))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -18,21 +18,5 @@ module Decidim
18
18
  mail(to: user.email, subject:)
19
19
  end
20
20
  end
21
-
22
- # Notify user about account removal due to inactivity
23
- def removal_notification(email, name, locale, organization)
24
- @email = email
25
- @user_name = name
26
- @organization = organization
27
-
28
- I18n.with_locale(locale) do
29
- subject = I18n.t(
30
- "decidim.participants_account_mailer.removal_notification.subject",
31
- organization_name: organization_name(@organization)
32
- )
33
-
34
- mail(to: email, subject:)
35
- end
36
- end
37
21
  end
38
22
  end
@@ -88,7 +88,7 @@ module Decidim
88
88
  # Returns String.
89
89
  def file_type
90
90
  if file?
91
- url&.split(".")&.last&.split("&")&.first&.downcase
91
+ file.filename.extension&.downcase
92
92
  elsif link?
93
93
  "link"
94
94
  end
@@ -100,7 +100,13 @@ module Decidim
100
100
  def url
101
101
  @url ||=
102
102
  if file?
103
- attached_uploader(:file).url
103
+ if private_download_required?
104
+ Decidim::Core::Engine.routes.url_helpers.private_download_path(
105
+ Decidim::PrivateDownload.for(self, attachment_name: :file).token
106
+ )
107
+ else
108
+ attached_uploader(:file).url
109
+ end
104
110
  elsif link?
105
111
  link
106
112
  end
@@ -144,5 +150,17 @@ module Decidim
144
150
 
145
151
  attached_to.can_participate?(user)
146
152
  end
153
+
154
+ def private_download_authorized?(user, requested_attachment_name)
155
+ return false unless requested_attachment_name.to_s == "file"
156
+
157
+ can_participate?(user)
158
+ end
159
+
160
+ def private_download_required?
161
+ return attached_to.private_space? if attached_to.respond_to?(:private_space?)
162
+
163
+ attached_to.respond_to?(:component) && attached_to.component&.private_non_transparent_space?
164
+ end
147
165
  end
148
166
  end
@@ -91,6 +91,13 @@ module Decidim
91
91
  Decidim::AuthorizationTransfer.perform!(self, handler)
92
92
  end
93
93
 
94
+ def private_download_authorized?(user, requested_attachment_name)
95
+ return false unless requested_attachment_name.to_s == "verification_attachment"
96
+ return true if user&.admin? && user.organization == organization
97
+
98
+ user == self.user
99
+ end
100
+
94
101
  private
95
102
 
96
103
  def active_handler?
@@ -32,7 +32,7 @@ module Decidim
32
32
  end
33
33
 
34
34
  def self.ransackable_attributes(_auth_object = nil)
35
- %w(reported_id_string reported_content created_at)
35
+ %w(reported_id_string reported_content created_at report_count)
36
36
  end
37
37
 
38
38
  def self.ransackable_associations(_auth_object = nil)
@@ -39,7 +39,7 @@ module Decidim
39
39
  def self.ransackable_attributes(auth_object = nil)
40
40
  return [] unless auth_object&.admin?
41
41
 
42
- %w(name nickname email invitation_accepted_at last_sign_in_at invitation_sent_at role)
42
+ %w(name nickname email invitation_accepted_at last_sign_in_at invitation_sent_at role published)
43
43
  end
44
44
 
45
45
  def self.ransackable_associations(_auth_object = nil)
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class PrivateDownload
5
+ class InvalidTokenError < StandardError; end
6
+
7
+ VERIFIER_PURPOSE = :private_download
8
+
9
+ def self.for(record, attachment_name:)
10
+ new(record:, attachment_name:)
11
+ end
12
+
13
+ def self.from_token(token)
14
+ payload = verifier.verify(token, purpose: VERIFIER_PURPOSE).with_indifferent_access
15
+ record = GlobalID::Locator.locate(payload[:gid])
16
+
17
+ raise InvalidTokenError if record.blank?
18
+
19
+ new(record:, attachment_name: payload[:attachment_name])
20
+ rescue ActiveSupport::MessageVerifier::InvalidSignature, TypeError
21
+ raise InvalidTokenError
22
+ end
23
+
24
+ def self.verifier
25
+ @verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.secret_key_base, serializer: JSON)
26
+ end
27
+
28
+ def initialize(record:, attachment_name:)
29
+ @record = record
30
+ @attachment_name = attachment_name.to_s
31
+ end
32
+
33
+ def token
34
+ self.class.verifier.generate(
35
+ {
36
+ gid: record.to_global_id.to_s,
37
+ attachment_name:
38
+ },
39
+ purpose: VERIFIER_PURPOSE
40
+ )
41
+ end
42
+
43
+ def attachment
44
+ record.public_send(attachment_name)
45
+ end
46
+
47
+ def attached?
48
+ attachment.respond_to?(:attached?) && attachment.attached?
49
+ end
50
+
51
+ def authorized_for?(user)
52
+ return false unless record.respond_to?(:private_download_authorized?)
53
+
54
+ record.private_download_authorized?(user, attachment_name)
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :record, :attachment_name
60
+ end
61
+ end
@@ -24,5 +24,11 @@ module Decidim
24
24
  self.content_type = file.content_type
25
25
  self.file_size = file.byte_size
26
26
  end
27
+
28
+ def private_download_authorized?(user, requested_attachment_name)
29
+ return false unless requested_attachment_name.to_s == "file"
30
+
31
+ attached_to == user
32
+ end
27
33
  end
28
34
  end