decidim-core 0.32.1 → 0.32.3

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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/address_cell.rb +7 -3
  3. data/app/cells/decidim/card_metadata_cell.rb +3 -1
  4. data/app/cells/decidim/content_blocks/participatory_space_main_data/title.erb +1 -14
  5. data/app/cells/decidim/date_range/show.erb +6 -6
  6. data/app/cells/decidim/date_range_cell.rb +7 -2
  7. data/app/cells/decidim/following_cell.rb +1 -1
  8. data/app/cells/decidim/member/show.erb +1 -1
  9. data/app/cells/decidim/nav_links/show.erb +3 -1
  10. data/app/cells/decidim/share_text_widget/modal.erb +1 -0
  11. data/app/cells/decidim/share_widget/modal.erb +1 -0
  12. data/app/cells/decidim/share_widget/qr_code_modal.erb +2 -4
  13. data/app/commands/decidim/create_follow.rb +2 -3
  14. data/app/commands/decidim/create_omniauth_registration.rb +19 -7
  15. data/app/commands/decidim/create_user_report.rb +1 -1
  16. data/app/commands/decidim/destroy_account.rb +6 -6
  17. data/app/commands/decidim/destroy_ephemeral_user.rb +2 -0
  18. data/app/commands/decidim/invite_user.rb +1 -1
  19. data/app/commands/decidim/multiple_attachments_methods.rb +17 -3
  20. data/app/commands/decidim/update_resources_taxonomies.rb +2 -1
  21. data/app/controllers/concerns/decidim/devise_authentication_methods.rb +4 -0
  22. data/app/controllers/concerns/decidim/devise_controllers.rb +2 -0
  23. data/app/controllers/concerns/decidim/direct_upload.rb +12 -6
  24. data/app/controllers/concerns/decidim/disable_redirection_to_external_host.rb +2 -0
  25. data/app/controllers/concerns/decidim/filter_resource.rb +2 -0
  26. data/app/controllers/concerns/decidim/impersonate_users.rb +4 -4
  27. data/app/controllers/concerns/decidim/locale_switcher.rb +12 -10
  28. data/app/controllers/concerns/decidim/needs_organization.rb +15 -0
  29. data/app/controllers/concerns/decidim/needs_permission.rb +22 -10
  30. data/app/controllers/concerns/decidim/onboarding_action_methods.rb +2 -0
  31. data/app/controllers/concerns/decidim/paginable.rb +7 -3
  32. data/app/controllers/concerns/decidim/payload_info.rb +2 -0
  33. data/app/controllers/concerns/decidim/resource_versions_concern.rb +14 -0
  34. data/app/controllers/decidim/amendments_controller.rb +34 -6
  35. data/app/controllers/decidim/application_controller.rb +2 -6
  36. data/app/controllers/decidim/authorization_modals_controller.rb +3 -1
  37. data/app/controllers/decidim/components/base_controller.rb +2 -0
  38. data/app/controllers/decidim/devise/passwords_controller.rb +8 -0
  39. data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +10 -4
  40. data/app/controllers/decidim/doorkeeper/credentials_controller.rb +6 -1
  41. data/app/controllers/decidim/favicon_controller.rb +9 -0
  42. data/app/controllers/decidim/free_resource_authorization_modals_controller.rb +2 -0
  43. data/app/controllers/decidim/gamification/badges_controller.rb +2 -0
  44. data/app/controllers/decidim/homepage_controller.rb +4 -1
  45. data/app/controllers/decidim/likes_controller.rb +1 -1
  46. data/app/controllers/decidim/links_controller.rb +2 -0
  47. data/app/controllers/decidim/manifests_controller.rb +2 -0
  48. data/app/controllers/decidim/messaging/conversations_controller.rb +11 -5
  49. data/app/controllers/decidim/newsletters_controller.rb +4 -0
  50. data/app/controllers/decidim/notifications_subscriptions_controller.rb +4 -0
  51. data/app/controllers/decidim/offline_controller.rb +5 -1
  52. data/app/controllers/decidim/open_data_controller.rb +5 -1
  53. data/app/controllers/decidim/pages_controller.rb +31 -3
  54. data/app/controllers/decidim/private_downloads_controller.rb +2 -0
  55. data/app/controllers/decidim/profiles_controller.rb +20 -2
  56. data/app/controllers/decidim/qr_controller.rb +3 -1
  57. data/app/controllers/decidim/resource_autocomplete_controller.rb +2 -0
  58. data/app/controllers/decidim/searches_controller.rb +2 -0
  59. data/app/controllers/decidim/short_links_controller.rb +4 -0
  60. data/app/controllers/decidim/static_map_controller.rb +2 -0
  61. data/app/controllers/decidim/timeouts_controller.rb +4 -0
  62. data/app/controllers/decidim/tos_controller.rb +2 -0
  63. data/app/controllers/decidim/upload_validations_controller.rb +4 -2
  64. data/app/controllers/decidim/user_activities_controller.rb +3 -0
  65. data/app/forms/decidim/upload_validation_form.rb +16 -10
  66. data/app/helpers/concerns/decidim/user_role_checker.rb +35 -10
  67. data/app/helpers/decidim/cells_paginate_helper.rb +0 -5
  68. data/app/helpers/decidim/decidim_form_helper.rb +1 -1
  69. data/app/helpers/decidim/layout_helper.rb +1 -0
  70. data/app/helpers/decidim/orders_helper.rb +8 -6
  71. data/app/helpers/decidim/paginate_helper.rb +15 -3
  72. data/app/helpers/decidim/sanitize_helper.rb +11 -1
  73. data/app/helpers/decidim/url_helper.rb +35 -0
  74. data/app/jobs/decidim/application_job.rb +4 -0
  75. data/app/jobs/decidim/open_data_job.rb +21 -5
  76. data/app/models/decidim/action_log.rb +7 -1
  77. data/app/models/decidim/authorization.rb +24 -0
  78. data/app/models/decidim/component.rb +10 -0
  79. data/app/models/decidim/like.rb +1 -1
  80. data/app/models/decidim/oauth_application.rb +1 -0
  81. data/app/models/decidim/user.rb +1 -0
  82. data/app/models/decidim/user_base_entity.rb +1 -1
  83. data/app/packs/src/decidim/callout.js +10 -0
  84. data/app/packs/src/decidim/callout.test.js +32 -0
  85. data/app/packs/src/decidim/controllers/accordion/accordion.test.js +64 -0
  86. data/app/packs/src/decidim/controllers/accordion/controller.js +43 -0
  87. data/app/packs/src/decidim/controllers/autofocus/controller.js +30 -0
  88. data/app/packs/src/decidim/controllers/language_change/controller.js +21 -8
  89. data/app/packs/src/decidim/controllers/language_change/language_change.test.js +0 -1
  90. data/app/packs/src/decidim/controllers/mention/controller.js +32 -3
  91. data/app/packs/src/decidim/controllers/mention/input_mentions.test.js +8 -5
  92. data/app/packs/src/decidim/controllers/multiple_mentions/input_multiple_mentions.test.js +1 -1
  93. data/app/packs/src/decidim/datepicker/datepicker_functions.js +61 -32
  94. data/app/packs/src/decidim/datepicker/form_datepicker.js +18 -2
  95. data/app/packs/src/decidim/datepicker/generate_datepicker.js +16 -8
  96. data/app/packs/src/decidim/datepicker/generate_timepicker.js +5 -3
  97. data/app/packs/src/decidim/datepicker/test/date.test.js +8 -0
  98. data/app/packs/src/decidim/datepicker/test/datepicker_functions_adjust_picker_position.test.js +64 -0
  99. data/app/packs/src/decidim/datepicker/test/time.test.js +39 -24
  100. data/app/packs/src/decidim/editor/common/suggestion.js +32 -22
  101. data/app/packs/src/decidim/editor/extensions/mention/index.js +14 -3
  102. data/app/packs/src/decidim/editor/index.js +4 -0
  103. data/app/packs/src/decidim/editor/test/extensions/mention.test.js +32 -9
  104. data/app/packs/src/decidim/refactor/implementation/autofocus.js +22 -0
  105. data/app/packs/src/decidim/refactor/implementation/autofocus.test.js +171 -0
  106. data/app/packs/src/decidim/utilities/dom.js +2 -2
  107. data/app/packs/stylesheets/decidim/_content_blocks.scss +4 -10
  108. data/app/packs/stylesheets/decidim/_conversations.scss +0 -8
  109. data/app/packs/stylesheets/decidim/_datepicker.scss +3 -3
  110. data/app/packs/stylesheets/decidim/_modal.scss +16 -8
  111. data/app/packs/stylesheets/decidim/_modal_share.scss +0 -22
  112. data/app/packs/stylesheets/decidim/_participatory_spaces.scss +11 -1
  113. data/app/packs/stylesheets/decidim/_rich_text.scss +12 -9
  114. data/app/packs/stylesheets/decidim/_spinner.scss +16 -0
  115. data/app/packs/stylesheets/decidim/_tom_select.scss +1 -1
  116. data/app/packs/stylesheets/decidim/_typography.scss +5 -2
  117. data/app/packs/stylesheets/decidim/application.scss +1 -0
  118. data/app/packs/stylesheets/decidim/legacy/email.scss +0 -5
  119. data/app/permissions/decidim/permissions.rb +20 -0
  120. data/app/presenters/decidim/admin_log/component_presenter.rb +1 -1
  121. data/app/presenters/decidim/log/base_presenter.rb +20 -2
  122. data/app/presenters/decidim/log/user_presenter.rb +2 -2
  123. data/app/presenters/decidim/menu_item_presenter.rb +1 -5
  124. data/app/presenters/decidim/resource_presenter.rb +11 -0
  125. data/app/resolvers/decidim/meta_image_url_resolver.rb +7 -1
  126. data/app/serializers/decidim/exporters/open_data_blocked_user_serializer.rb +11 -2
  127. data/app/serializers/decidim/exporters/open_data_moderation_serializer.rb +25 -1
  128. data/app/services/decidim/action_logger.rb +97 -29
  129. data/app/services/decidim/svg_content_validator.rb +889 -0
  130. data/app/uploaders/decidim/application_uploader.rb +2 -2
  131. data/app/validators/uploader_image_content_validator.rb +280 -0
  132. data/app/views/decidim/application/_radio_accordion.html.erb +1 -5
  133. data/app/views/decidim/manifests/show.json.erb +25 -22
  134. data/app/views/decidim/messaging/conversations/_add_conversation_users.html.erb +1 -1
  135. data/app/views/decidim/messaging/conversations/create.js.erb +1 -3
  136. data/app/views/decidim/shared/_login_modal.html.erb +12 -14
  137. data/app/views/decidim/shared/_results_per_page.html.erb +1 -1
  138. data/app/views/layouts/decidim/_mailer_logo.html.erb +1 -1
  139. data/app/views/layouts/decidim/header/_menu_breadcrumb_desktop.html.erb +3 -2
  140. data/config/initializers/rack_attack.rb +10 -0
  141. data/config/locales/bg.yml +1 -4
  142. data/config/locales/ca-IT.yml +10 -4
  143. data/config/locales/ca.yml +17 -11
  144. data/config/locales/cs.yml +24 -4
  145. data/config/locales/de.yml +100 -6
  146. data/config/locales/en.yml +10 -4
  147. data/config/locales/es-MX.yml +10 -4
  148. data/config/locales/es-PY.yml +10 -4
  149. data/config/locales/es.yml +16 -10
  150. data/config/locales/eu.yml +171 -168
  151. data/config/locales/fi-plain.yml +5 -3
  152. data/config/locales/fi.yml +5 -3
  153. data/config/locales/fr-CA.yml +10 -4
  154. data/config/locales/fr.yml +10 -4
  155. data/config/locales/gl.yml +1484 -33
  156. data/config/locales/hu.yml +0 -1
  157. data/config/locales/it.yml +0 -2
  158. data/config/locales/ja.yml +6 -4
  159. data/config/locales/pl.yml +1 -4
  160. data/config/locales/pt-BR.yml +1 -4
  161. data/config/locales/ro-RO.yml +0 -3
  162. data/config/locales/sk.yml +70 -4
  163. data/config/locales/sv.yml +71 -15
  164. data/config/locales/tr-TR.yml +1 -3
  165. data/config/routes.rb +11 -2
  166. data/db/migrate/20250523104311_move_cta_to_hero_content_block.rb +1 -1
  167. data/db/migrate/20250527122040_move_highlighted_content_banner_settings_to_content_block.rb +3 -0
  168. data/db/migrate/20260909000000_add_failed_attempts_and_locked_at_to_decidim_authorizations.rb +8 -0
  169. data/db/migrate/20261007090000_make_user_optional_in_action_logs.rb +12 -0
  170. data/decidim-core.gemspec +1 -1
  171. data/lib/decidim/api/functions/user_entity_list.rb +1 -0
  172. data/lib/decidim/api/types/user_moderation_type.rb +2 -2
  173. data/lib/decidim/content_parsers/user_parser.rb +1 -1
  174. data/lib/decidim/content_parsers.rb +0 -1
  175. data/lib/decidim/content_renderers/mention_resource_renderer.rb +19 -5
  176. data/lib/decidim/content_renderers/user_renderer.rb +15 -4
  177. data/lib/decidim/core/test/shared_examples/participatory_space_members_page_examples.rb +77 -0
  178. data/lib/decidim/core/test/shared_examples/participatory_space_members_shared_examples.rb +58 -0
  179. data/lib/decidim/core/test/shared_examples/versions_controller_examples.rb +23 -1
  180. data/lib/decidim/core/version.rb +1 -1
  181. data/lib/decidim/core.rb +10 -1
  182. data/lib/decidim/form_builder.rb +9 -1
  183. data/lib/decidim/has_upload_validations.rb +1 -0
  184. data/lib/decidim/legacy_form_builder.rb +4 -0
  185. data/lib/decidim/maintenance/import_models/scope.rb +2 -1
  186. data/lib/decidim/maintenance/taxonomy_importer.rb +4 -1
  187. data/lib/decidim/seeds.rb +1 -1
  188. data/lib/decidim/view_model.rb +1 -0
  189. data/lib/tasks/decidim_open_data_tasks.rake +7 -0
  190. metadata +14 -7
  191. data/lib/decidim/content_parsers/inline_images_parser.rb +0 -68
  192. data/lib/tasks/upgrade/decidim_active_storage_migration_tasks.rake +0 -79
@@ -40,7 +40,7 @@ module Decidim
40
40
 
41
41
  def url(options = {})
42
42
  representable = model.send(mounted_as)
43
- return super unless representable.is_a? ActiveStorage::Attached
43
+ return unless representable.is_a? ActiveStorage::Attached
44
44
 
45
45
  variant_url(options.delete(:variant), **options)
46
46
  end
@@ -54,7 +54,7 @@ module Decidim
54
54
 
55
55
  def path(options = {})
56
56
  representable = model.send(mounted_as)
57
- return super() unless representable.is_a? ActiveStorage::Attached
57
+ return unless representable.is_a? ActiveStorage::Attached
58
58
 
59
59
  variant_path(options.delete(:variant), **options)
60
60
  end
@@ -0,0 +1,280 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This validator ensures that files declared as images actually contain valid
4
+ # image data of the declared format. It does so by checking the leading bytes
5
+ # (magic bytes / file signature) of the file against the known signatures of
6
+ # the supported image formats, and by comparing the detected format with the
7
+ # content type declared by the file.
8
+ #
9
+ # This prevents non-image files (e.g. HTML, MATLAB, or arbitrary binary data)
10
+ # from being uploaded with an image extension and a spoofed image content type.
11
+ # Such files would later cause image processing to fail (e.g. in ImageMagick or
12
+ # in libvips when generating a variant) and could lead to a denial of service.
13
+ #
14
+ # Comparing the detected format with the declared content type also prevents
15
+ # files whose contents do not match their declaration (e.g. a JPEG file
16
+ # declared as image/png), so that the stored MIME type is consistent with the
17
+ # file contents.
18
+ #
19
+ # SVG documents are XML-based and can contain scripts and other active content,
20
+ # which is executed when the document is rendered by the browser. Because of
21
+ # that, the contents of files detected as SVG are additionally validated by
22
+ # Decidim::SvgContentValidator, so that documents which could execute scripts
23
+ # or read external resources are rejected instead of being stored as they are.
24
+ class UploaderImageContentValidator < ActiveModel::Validations::FileContentTypeValidator
25
+ # The number of leading bytes to read from the file to detect its signature.
26
+ SIGNATURE_LENGTH = 128
27
+
28
+ # The known signatures of the supported binary image formats. Each entry
29
+ # associates a format with a list of [offset, bytes] pairs that must all
30
+ # match at their respective offsets for the file to be considered of that
31
+ # format.
32
+ BINARY_IMAGE_SIGNATURES = [
33
+ [:png, [[0, "\x89PNG\r\n\x1A\n".b]]],
34
+ [:jpeg, [[0, "\xFF\xD8\xFF".b]]],
35
+ [:gif, [[0, "GIF87a".b]]],
36
+ [:gif, [[0, "GIF89a".b]]],
37
+ [:bmp, [[0, "BM".b]]],
38
+ [:tiff, [[0, "II*\x00".b]]],
39
+ [:tiff, [[0, "MM\x00*".b]]],
40
+ [:webp, [[0, "RIFF".b], [8, "WEBP".b]]]
41
+ ].freeze
42
+
43
+ # The major brands of the ISOBMFF "ftyp" box that identify HEIF and AVIF
44
+ # images. These formats share the same leading layout as other "ftyp" files
45
+ # (e.g. MP4 video), so the brand at offset 8 is used to tell images apart.
46
+ # The brands are grouped per format family, because HEIF files may use any
47
+ # of the HEIF brands regardless of their extension (e.g. a ".heic" file
48
+ # with the "mif1" major brand).
49
+ FTYPE_IMAGE_BRANDS = {
50
+ heif: %w(heic heix hevc hevx mif1 msf1).map(&:b).freeze,
51
+ avif: %w(avif avis).map(&:b).freeze
52
+ }.freeze
53
+
54
+ # The leading markup of an SVG document, which is XML-based and therefore has
55
+ # no fixed binary signature. The XML declaration is optional, and the document
56
+ # type declaration, comments and processing instructions are legal before the
57
+ # root element, so a document can start with any of them. Files detected as SVG
58
+ # are then checked by Decidim::SvgContentValidator, which requires an "svg"
59
+ # root element, so an XML document which is not an SVG is still rejected.
60
+ SVG_SIGNATURES = ["<svg".b, "<?".b, "<!--".b, "<!DOCTYPE".b].freeze
61
+
62
+ # The content types accepted for each image format detected from the file
63
+ # signature. The content type declared by the file must be one of these, so
64
+ # that the stored MIME type is consistent with the file contents. The lists
65
+ # include the aliases commonly used in the wild for the same format.
66
+ FORMAT_CONTENT_TYPES = {
67
+ png: %w(image/png),
68
+ jpeg: %w(image/jpeg image/jpg image/pjpeg),
69
+ gif: %w(image/gif),
70
+ bmp: %w(image/bmp image/x-ms-bmp image/windows-bmp),
71
+ tiff: %w(image/tiff image/x-tiff),
72
+ webp: %w(image/webp),
73
+ heif: %w(image/heic image/heif image/heic-sequence image/heif-sequence),
74
+ avif: %w(image/avif image/avis),
75
+ svg: %w(image/svg+xml)
76
+ }.freeze
77
+
78
+ def validate_each(record, attribute, value)
79
+ begin
80
+ values = parse_values(value)
81
+ rescue JSON::ParserError
82
+ record.errors.add attribute, :invalid
83
+ return
84
+ end
85
+
86
+ return if values.empty?
87
+
88
+ values.each do |val|
89
+ validate_image_content(record, attribute, val)
90
+ end
91
+ end
92
+
93
+ def check_validity!; end
94
+
95
+ private
96
+
97
+ def validate_image_content(record, attribute, file)
98
+ content_type = normalize_content_type(declared_content_type(file))
99
+ return unless content_type.start_with?("image/")
100
+
101
+ signature = file_signature(file)
102
+ return if signature.nil?
103
+
104
+ detected = image_format(signature)
105
+ return add_invalid_image(record, attribute) unless valid_image_format?(detected, content_type)
106
+
107
+ validate_svg_content(record, attribute, file) if detected == :svg
108
+ end
109
+
110
+ # The content type declared by the file, either through the blob of an
111
+ # attached file or through the upload itself.
112
+ def declared_content_type(file)
113
+ if file.is_a?(ActiveStorage::Attached)
114
+ file.blob&.content_type
115
+ else
116
+ file.try(:content_type)
117
+ end
118
+ end
119
+
120
+ # Strips the content type parameters (e.g. "image/png;charset=binary") and
121
+ # normalizes the casing, as content types are case insensitive.
122
+ def normalize_content_type(content_type)
123
+ content_type.to_s.split(";", 2).first.to_s.strip.downcase
124
+ end
125
+
126
+ # Whether the format detected from the file signature is one of the
127
+ # supported image formats and is consistent with the content type declared
128
+ # by the file.
129
+ def valid_image_format?(detected, content_type)
130
+ return false if detected.nil?
131
+
132
+ FORMAT_CONTENT_TYPES.fetch(detected).include?(content_type)
133
+ end
134
+
135
+ # Validates the contents of a file detected as SVG, which can contain active
136
+ # content. The validation is delegated to Decidim::SvgContentValidator, so
137
+ # that the SVG specific logic is kept out of this validator. Documents which
138
+ # are not well formed SVG documents are rejected as invalid images, and the
139
+ # ones which could execute scripts or read external resources when they are
140
+ # rendered are rejected as unsafe files.
141
+ def validate_svg_content(record, attribute, file)
142
+ case Decidim::SvgContentValidator.validate(file_content(file))
143
+ when :invalid
144
+ add_invalid_image(record, attribute)
145
+ when :unsafe
146
+ add_unsafe_svg(record, attribute)
147
+ end
148
+ end
149
+
150
+ def add_invalid_image(record, attribute)
151
+ record.errors.add attribute, I18n.t("decidim.errors.files.file_is_not_a_valid_image")
152
+ end
153
+
154
+ def add_unsafe_svg(record, attribute)
155
+ record.errors.add attribute, I18n.t("decidim.errors.files.file_contains_unsafe_content")
156
+ end
157
+
158
+ # Reads the leading bytes (signature) of the file. Returns nil when the file
159
+ # cannot be read, in which case the validation is skipped. Empty files yield
160
+ # an empty signature, which is rejected.
161
+ def file_signature(file)
162
+ read_file(file, SIGNATURE_LENGTH)
163
+ end
164
+
165
+ # Reads the whole contents of the file. Returns nil when the file cannot be
166
+ # read.
167
+ def file_content(file)
168
+ read_file(file)
169
+ end
170
+
171
+ # Reads the contents of the file, or only its leading bytes when a maximum
172
+ # length is given.
173
+ def read_file(file, max_length = nil)
174
+ if uploaded_file?(file)
175
+ File.open(file.path, "rb") { |io| read_io(io, max_length) }
176
+ elsif file.is_a?(ActiveStorage::Attached)
177
+ read_attached(file, max_length)
178
+ end
179
+ rescue ActiveStorage::Error, Errno::ENOENT, IOError
180
+ nil
181
+ end
182
+
183
+ # Reads the contents of an IO, or only its leading bytes when a maximum
184
+ # length is given. IO#read returns nil at the end of the file, so an empty
185
+ # file would otherwise be indistinguishable from an unreadable one and skip
186
+ # the validation. Normalizing it to an empty content keeps empty files
187
+ # rejected, while nil is kept for files which cannot be read at all.
188
+ def read_io(io, max_length = nil)
189
+ (max_length ? io.read(max_length) : io.read) || ""
190
+ end
191
+
192
+ # Reads the contents of an attached file. Blobs are only uploaded once the
193
+ # record is saved, so for still unpersisted blobs (e.g. an image assigned to
194
+ # a new record) the bytes are read from the pending attachable. Otherwise a
195
+ # spoofed image could be saved without being checked.
196
+ def read_attached(attached, max_length = nil)
197
+ blob = attached.blob
198
+ return read_blob(blob, max_length) if blob&.persisted?
199
+
200
+ read_pending_attachable(attached, max_length)
201
+ end
202
+
203
+ # ActiveStorage keeps the attachable of a pending attachment in the record's
204
+ # attachment changes until the blob is uploaded when the record is saved, so
205
+ # its contents can already be read during the validation.
206
+ def read_pending_attachable(attached, max_length = nil)
207
+ attachable = pending_attachable(attached)
208
+ if uploaded_file?(attachable) || attachable.is_a?(File)
209
+ File.open(attachable.path, "rb") { |io| read_io(io, max_length) }
210
+ elsif attachable.is_a?(Pathname)
211
+ File.open(attachable.to_path, "rb") { |io| read_io(io, max_length) }
212
+ elsif attachable.is_a?(Hash)
213
+ read_io_without_consuming(attachable[:io], max_length)
214
+ end
215
+ end
216
+
217
+ def pending_attachable(attached)
218
+ change = attached.record.try(:attachment_changes)&.[](attached.name.to_s)
219
+ change.try(:attachable)
220
+ end
221
+
222
+ # Reads the contents without consuming the IO, so ActiveStorage can still
223
+ # upload it after the validation.
224
+ def read_io_without_consuming(io, max_length = nil)
225
+ return unless io.respond_to?(:read) && io.respond_to?(:rewind)
226
+
227
+ io.rewind
228
+ content = read_io(io, max_length)
229
+ io.rewind
230
+ content
231
+ end
232
+
233
+ # Reads the whole contents of the blob, or only its leading bytes when a
234
+ # maximum length is given to keep the operation cheap for large files. The
235
+ # services return nil when the blob is empty, which is normalized to an
236
+ # empty content so that empty blobs are rejected. Falls back to opening the
237
+ # whole blob when the service does not support ranged downloads.
238
+ def read_blob(blob, max_length = nil)
239
+ return blob.download if max_length.nil?
240
+
241
+ blob.download_chunk(0...max_length) || ""
242
+ rescue NotImplementedError
243
+ blob.open { |io| read_io(io, max_length) }
244
+ end
245
+
246
+ # The image format detected from the file signature, or nil when the
247
+ # signature does not match any of the supported image formats.
248
+ def image_format(signature)
249
+ return nil if signature.blank?
250
+
251
+ binary_image_format(signature) || ftyp_image_format(signature) || svg_format(signature)
252
+ end
253
+
254
+ def binary_image_format(signature)
255
+ BINARY_IMAGE_SIGNATURES.find do |_format, pairs|
256
+ pairs.all? { |offset, bytes| signature[offset, bytes.bytesize] == bytes }
257
+ end&.first
258
+ end
259
+
260
+ # The format of an ISOBMFF-based image (HEIF or AVIF). These files start with
261
+ # a "ftyp" box at offset 4 followed by a major brand at offset 8.
262
+ def ftyp_image_format(signature)
263
+ return nil unless signature[4, 4] == "ftyp".b
264
+
265
+ FTYPE_IMAGE_BRANDS.find { |_format, brands| brands.include?(signature[8, 4]) }&.first
266
+ end
267
+
268
+ def svg_format(signature)
269
+ content = signature.sub(/\A\xEF\xBB\xBF/n, "").lstrip
270
+ return nil unless SVG_SIGNATURES.any? { |svg_signature| content.start_with?(svg_signature) }
271
+
272
+ :svg
273
+ end
274
+
275
+ def uploaded_file?(file)
276
+ return true if defined?(Rack::Test::UploadedFile) && file.is_a?(Rack::Test::UploadedFile)
277
+
278
+ file.is_a?(ActionDispatch::Http::UploadedFile)
279
+ end
280
+ end
@@ -12,7 +12,7 @@
12
12
  </label>
13
13
 
14
14
  <div data-controller="accordion" class="radio-accordion-section content-block__description editor-content">
15
- <div id="panel-title--<%= panel_id %>" aria-hidden="true">
15
+ <div id="panel-title--<%= panel_id %>" aria-hidden="true" inert>
16
16
  <%= yield %>
17
17
  </div>
18
18
 
@@ -21,10 +21,6 @@
21
21
  <%= show_more_text %>
22
22
  </span>
23
23
  <%= icon "arrow-down-s-line" %>
24
- <span>
25
- <%= show_less_text %>
26
- </span>
27
- <%= icon "arrow-up-s-line" %>
28
24
  </button>
29
25
  </div>
30
26
  </div>
@@ -1,32 +1,35 @@
1
- {
2
- "name": "<%= organization_params.html_name %>",
3
- "short_name": "<%= organization_params.html_short_name %>",
4
- "lang": "<%= organization_params.default_locale %>",
5
- "description": "<%= organization_params.translated_description %>",
6
- "display": "<%= organization_params.pwa_display %>",
7
- "start_url": "<%= organization_params.start_url %>",
8
- "theme_color": "<%= organization_params.colors["primary"] %>",
9
- "background_color": "#FFFFFF",
10
- "icons": [
1
+ <%
2
+ manifest = {
3
+ name: organization_params.html_name,
4
+ short_name: organization_params.html_short_name,
5
+ lang: organization_params.default_locale,
6
+ description: organization_params.translated_description,
7
+ display: organization_params.pwa_display,
8
+ start_url: organization_params.start_url,
9
+ theme_color: organization_params.colors["primary"],
10
+ background_color: "#FFFFFF",
11
+ icons: [
11
12
  {
12
- "src": "<%= current_organization.attached_uploader(:favicon).variant_url :small %>",
13
- "sizes": "32x32",
14
- "type": "image/png"
13
+ src: current_organization.attached_uploader(:favicon).variant_url(:small),
14
+ sizes: "32x32",
15
+ type: "image/png"
15
16
  },
16
17
  {
17
- "src": "<%= current_organization.attached_uploader(:favicon).variant_url :medium %>",
18
- "sizes": "180x180",
19
- "type": "image/png"
18
+ src: current_organization.attached_uploader(:favicon).variant_url(:medium),
19
+ sizes: "180x180",
20
+ type: "image/png"
20
21
  },
21
22
  {
22
- "src": "<%= current_organization.attached_uploader(:favicon).variant_url :big %>",
23
- "sizes": "192x192",
24
- "type": "image/png"
23
+ src: current_organization.attached_uploader(:favicon).variant_url(:big),
24
+ sizes: "192x192",
25
+ type: "image/png"
25
26
  },
26
27
  {
27
- "src": "<%= current_organization.attached_uploader(:favicon).variant_url :huge %>",
28
- "sizes": "512x512",
29
- "type": "image/png"
28
+ src: current_organization.attached_uploader(:favicon).variant_url(:huge),
29
+ sizes: "512x512",
30
+ type: "image/png"
30
31
  }
31
32
  ]
32
33
  }
34
+ %>
35
+ <%== manifest.to_json %>
@@ -11,7 +11,7 @@
11
11
  spellcheck="false"
12
12
  autocomplete="off"
13
13
  placeholder="<%= t("add_users_placeholder", scope: "decidim.messaging.conversations.add_conversation_users") %>"
14
- data-noresults="<%= t("no_results", scope: "decidim.messaging.conversations.add_conversation_users") %>"
14
+ data-no_results="<%= t("no_results", scope: "decidim.messaging.conversations.add_conversation_users") %>"
15
15
  data-selected="conversation__modal-results"
16
16
  contenteditable="true"
17
17
  data-direct-messages-disabled="<%= t("participant_with_disabled_message_reception", scope: "decidim.messaging.conversations.add_conversation_users") %>">
@@ -1,3 +1 @@
1
- $("#messages").append("<%= j(render "messages", sender: conversation.messages.first.sender, messages: [conversation.messages.first]).html_safe %>");
2
- $("div[data-add-message]").replaceWith("<%= j(render "reply", form:, conversation:).html_safe %>");
3
- window.initFoundation($("#new_message_"));
1
+ window.location.href = "<%= conversation_path(conversation) %>";
@@ -9,11 +9,9 @@
9
9
  %>
10
10
 
11
11
  <%= decidim_form_for(Decidim::User.new, namespace: "login", as: :user, url: path, html: { class: nil }) do |f| %>
12
- <div>
13
- <div class="flex flex-row">
14
- <%= icon "user-line", class: "w-6 h-6 text-gray fill-current" %>
15
- <h3 id="dialog-title-loginModal" class="h3 ml-1"><%= t(".please_log_in") %></h3>
16
- </div>
12
+ <div data-dialog-container>
13
+ <%= icon "user-line" %>
14
+ <h3 id="dialog-title-loginModal" tabindex="-1" data-dialog-title><%= t(".please_log_in") %></h3>
17
15
 
18
16
  <div>
19
17
  <% if current_organization.sign_in_enabled? %>
@@ -44,16 +42,16 @@
44
42
  <%= render partial: "decidim/devise/shared/omniauth_buttons", locals: { is_horizontal: true } %>
45
43
  <% end %>
46
44
  <% end %>
47
- <% if current_organization.sign_in_enabled? %>
48
- <div data-dialog-actions>
49
- <div class="form__wrapper-block w-full mb-4">
50
- <button type="submit" class="button button__lg button__secondary">
51
- <%= t("devise.sessions.new.log_in") %>
52
- </button>
53
- </div>
54
- </div>
55
- <% end %>
56
45
  </div>
57
46
  </div>
47
+ <% if current_organization.sign_in_enabled? %>
48
+ <div data-dialog-actions>
49
+ <div class="form__wrapper-block w-full mb-4">
50
+ <button type="submit" class="button button__lg button__secondary">
51
+ <%= t("devise.sessions.new.log_in") %>
52
+ </button>
53
+ </div>
54
+ </div>
55
+ <% end %>
58
56
  <% end %>
59
57
  <% end %>
@@ -13,7 +13,7 @@
13
13
  <% Decidim::Paginable::OPTIONS.each do |per_page_option| %>
14
14
  <li role="presentation">
15
15
  <%= link_to per_page_option,
16
- url_for(params.to_unsafe_h.except("locale", :locale).merge(page: nil, per_page: per_page_option)),
16
+ url_for(decidim_url_params(params, page: nil, per_page: per_page_option).except("locale", :locale)),
17
17
  data: { per_page_option: },
18
18
  class: "dropdown__item",
19
19
  title: t("decidim.shared.results_per_page.title"),
@@ -8,7 +8,7 @@
8
8
  <% if organization.logo.attached? %>
9
9
  <%= image_tag(
10
10
  organization.attached_uploader(:logo).variant_url(:medium, host: organization.host),
11
- style: "max-height: 50px",
11
+ style: "max-height: 50px; display: inline-block",
12
12
  alt: organization_name(organization)
13
13
  ) %>
14
14
  <% else %>
@@ -2,6 +2,7 @@
2
2
  <span><%= t("decidim.menu.home") %></span>
3
3
  <% end %>
4
4
  <% truncatable_items = breadcrumb_items.compact_blank.drop(1) %>
5
+ <% current_page_item = breadcrumb_items.compact_blank.select { |breadcrumb_item| breadcrumb_item[:active] }.last %>
5
6
  <% breadcrumb_items.each do |item| %>
6
7
  <% next if item.blank? %>
7
8
 
@@ -16,7 +17,7 @@
16
17
  <% end %>
17
18
  <span aria-hidden="true"><%= icon "arrow-right-s-line", class: "fill-white" %></span>
18
19
  <% if item[:url].present? && !is_active_link?(item[:url], :exclusive) %>
19
- <%= link_to item[:url], class: trigger_classes.join(" "), data: (truncatable ? { breadcrumb_truncate_target: "item" } : {}), "aria-current": (item[:active] ? "page" : nil) do %>
20
+ <%= link_to item[:url], class: trigger_classes.join(" "), data: (truncatable ? { breadcrumb_truncate_target: "item" } : {}), "aria-current": (item == current_page_item ? "page" : nil) do %>
20
21
  <% if truncatable %>
21
22
  <span class="menu-bar__breadcrumb-desktop__label--truncatable">
22
23
  <span class="menu-bar__breadcrumb-text" data-breadcrumb-truncate-target="text"><%= item_label %></span>
@@ -27,7 +28,7 @@
27
28
  <% end %>
28
29
  <% else %>
29
30
  <%# This block is executed if the condition is false %>
30
- <%= content_tag :span, class: [*trigger_classes, "no-interactive"].join(" "), data: (truncatable ? { breadcrumb_truncate_target: "item" } : {}), "aria-current": (item[:active] ? "page" : nil) do %>
31
+ <%= content_tag :span, class: [*trigger_classes, "no-interactive"].join(" "), data: (truncatable ? { breadcrumb_truncate_target: "item" } : {}), "aria-current": (item == current_page_item ? "page" : nil) do %>
31
32
  <% if truncatable %>
32
33
  <span class="menu-bar__breadcrumb-desktop__label--truncatable">
33
34
  <span class="menu-bar__breadcrumb-text" data-breadcrumb-truncate-target="text"><%= item_label %></span>
@@ -34,6 +34,16 @@ if Rails.env.production? || Rails.env.test?
34
34
  Rack::Attack.throttle("limit password recovery attempts per email", limit: 5, period: 60.seconds) do |request|
35
35
  request.params["user"]["email"] if request.path == "/users/password" && request.post?
36
36
  end
37
+
38
+ # Throttle SMS verification confirmation attempts per IP to 10 reqs/minute
39
+ Rack::Attack.throttle("limit sms verification attempts per ip", limit: 10, period: 60.seconds) do |request|
40
+ request.ip if request.path.match?(%r{^/[^/]+/sms/authorizations(?:\.[^/]+)?$}) && request.put?
41
+ end
42
+
43
+ # Throttle postal letter verification confirmation attempts per IP to 10 reqs/minute
44
+ Rack::Attack.throttle("limit postal letter verification attempts per ip", limit: 10, period: 60.seconds) do |request|
45
+ request.ip if request.path.match?(%r{^/[^/]+/postal_letter/authorizations(?:\.[^/]+)?$}) && request.put?
46
+ end
37
47
  end
38
48
  end
39
49
  end
@@ -82,8 +82,6 @@ bg:
82
82
  decidim_with_month_name_short: "%d %b"
83
83
  help:
84
84
  date_format: 'Формат: дд/мм/гггг'
85
- order: d-m-y
86
- separator: "/"
87
85
  datetime:
88
86
  distance_in_words:
89
87
  about_x_hours:
@@ -1502,7 +1500,6 @@ bg:
1502
1500
  layouts:
1503
1501
  decidim:
1504
1502
  announcements:
1505
- view_less: Покажи по-малко
1506
1503
  view_more: Още информация
1507
1504
  data_consent:
1508
1505
  details:
@@ -1678,7 +1675,7 @@ bg:
1678
1675
  long_with_particles: "%B %d, %Y от %H:%M"
1679
1676
  short: "%d/%m/%Y %H:%M"
1680
1677
  time_of_day: "%H:%M"
1681
- tooltip: "%d-%m-%Y %H:%M %p %Z (GMT %:z)"
1678
+ tooltip: "%d-%m-%Y %H:%M %Z (GMT %:z)"
1682
1679
  versions:
1683
1680
  directions:
1684
1681
  left: Изтривания
@@ -118,8 +118,6 @@ ca-IT:
118
118
  decidim_with_month_name_short: "%d %b"
119
119
  help:
120
120
  date_format: 'Format: dd/mm/aaaa'
121
- order: d-m-y
122
- separator: "/"
123
121
  datetime:
124
122
  distance_in_words:
125
123
  about_x_hours:
@@ -252,6 +250,7 @@ ca-IT:
252
250
  create: "%{user_name} ha afegit el component %{resource_name} a l'espai %{space_name}"
253
251
  delete: "%{user_name} ha eliminat el component %{resource_name} de l'espai %{space_name}"
254
252
  export_component: "%{user_name} ha exportat %{resource_name}%{component_name} de %{space_name} com %{format_name}"
253
+ menu_hidden: "%{user_name} ha amagat el component %{resource_name} del menú de l'espai de participació: %{space_name}"
255
254
  publish: "%{user_name} ha publicat el component %{resource_name} a l'espai %{space_name}"
256
255
  restore: "%{user_name} ha restaurat el component %{resource_name} a l'espai %{space_name}"
257
256
  soft_delete: "%{user_name} ha mogut el component %{resource_name} a l'espai %{space_name} a la paperera"
@@ -855,6 +854,8 @@ ca-IT:
855
854
  errors:
856
855
  files:
857
856
  file_cannot_be_processed: No s'ha pogut processar el fitxer
857
+ file_contains_unsafe_content: El fitxer conté contingut no segur
858
+ file_is_not_a_valid_image: El fitxer no és una imatge vàlida
858
859
  file_resolution_too_large: La resolució de l'arxiu és massa gran
859
860
  not_inside_organization: L'arxiu no està vinculat a cap organització.
860
861
  internal_server_error:
@@ -1710,6 +1711,8 @@ ca-IT:
1710
1711
  login_modal:
1711
1712
  please_log_in: Si us plau, inicia la sessió
1712
1713
  sign_up: Crea un compte
1714
+ mentions:
1715
+ search_prompt: Escriu aquí per cercar entre les participants
1713
1716
  mentions_modal:
1714
1717
  remove_recipient: Eliminar destinatària %{name}
1715
1718
  progress: Progrés
@@ -2092,7 +2095,6 @@ ca-IT:
2092
2095
  layouts:
2093
2096
  decidim:
2094
2097
  announcements:
2095
- view_less: Mostra menys
2096
2098
  view_more: Més informació
2097
2099
  data_consent:
2098
2100
  details:
@@ -2267,6 +2269,7 @@ ca-IT:
2267
2269
  close: Tancar
2268
2270
  reset: Reiniciar
2269
2271
  select: Seleccionar
2272
+ clock_format: 24
2270
2273
  formats:
2271
2274
  day_of_month: "%b %d"
2272
2275
  day_of_week: "%a"
@@ -2275,6 +2278,8 @@ ca-IT:
2275
2278
  ddmm: "%d.%m"
2276
2279
  ddmmyyyy: "%d.%m.%Y"
2277
2280
  decidim_day_of_year: "%d %B %Y"
2281
+ decidim_month: "%B"
2282
+ decidim_month_and_year: "%B %Y"
2278
2283
  decidim_short: "%d/%m/%Y %H:%M"
2279
2284
  default: "%a, %d %b %Y %H:%M:%S %z"
2280
2285
  devise:
@@ -2288,7 +2293,8 @@ ca-IT:
2288
2293
  long_with_particles: "%d %B, de %Y a les %H:%M"
2289
2294
  short: "%d/%m/%Y %H:%M"
2290
2295
  time_of_day: "%H:%M"
2291
- tooltip: "%d-%m-%Y %H:%M %p %Z (GMT %:z)"
2296
+ time_of_day_with_time_zone: "%Z de %H:%M"
2297
+ tooltip: "%d-%m-%Y %H:%M %Z (GMT %:z)"
2292
2298
  versions:
2293
2299
  directions:
2294
2300
  left: Esborrats