decidim-core 0.32.2 → 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 (82) 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/date_range/show.erb +6 -6
  5. data/app/cells/decidim/date_range_cell.rb +7 -2
  6. data/app/commands/decidim/create_follow.rb +2 -3
  7. data/app/commands/decidim/create_omniauth_registration.rb +2 -5
  8. data/app/commands/decidim/create_user_report.rb +1 -1
  9. data/app/commands/decidim/destroy_account.rb +6 -6
  10. data/app/commands/decidim/destroy_ephemeral_user.rb +2 -0
  11. data/app/commands/decidim/invite_user.rb +1 -1
  12. data/app/commands/decidim/multiple_attachments_methods.rb +17 -3
  13. data/app/commands/decidim/update_resources_taxonomies.rb +2 -1
  14. data/app/controllers/concerns/decidim/direct_upload.rb +12 -6
  15. data/app/controllers/concerns/decidim/impersonate_users.rb +2 -2
  16. data/app/controllers/concerns/decidim/needs_organization.rb +15 -0
  17. data/app/controllers/decidim/amendments_controller.rb +34 -6
  18. data/app/controllers/decidim/application_controller.rb +2 -0
  19. data/app/controllers/decidim/authorization_modals_controller.rb +1 -1
  20. data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +10 -4
  21. data/app/controllers/decidim/doorkeeper/credentials_controller.rb +6 -1
  22. data/app/controllers/decidim/messaging/conversations_controller.rb +1 -1
  23. data/app/controllers/decidim/profiles_controller.rb +1 -1
  24. data/app/helpers/decidim/cells_paginate_helper.rb +0 -5
  25. data/app/helpers/decidim/layout_helper.rb +1 -0
  26. data/app/helpers/decidim/orders_helper.rb +8 -6
  27. data/app/helpers/decidim/paginate_helper.rb +15 -3
  28. data/app/helpers/decidim/url_helper.rb +35 -0
  29. data/app/jobs/decidim/open_data_job.rb +21 -5
  30. data/app/models/decidim/action_log.rb +7 -1
  31. data/app/models/decidim/component.rb +10 -0
  32. data/app/models/decidim/like.rb +1 -1
  33. data/app/packs/src/decidim/datepicker/datepicker_functions.js +20 -7
  34. data/app/packs/src/decidim/datepicker/form_datepicker.js +18 -2
  35. data/app/packs/src/decidim/datepicker/generate_datepicker.js +12 -4
  36. data/app/packs/src/decidim/datepicker/generate_timepicker.js +5 -3
  37. data/app/packs/src/decidim/datepicker/test/date.test.js +8 -0
  38. data/app/packs/stylesheets/decidim/_datepicker.scss +3 -3
  39. data/app/packs/stylesheets/decidim/_spinner.scss +16 -0
  40. data/app/packs/stylesheets/decidim/_tom_select.scss +1 -1
  41. data/app/presenters/decidim/log/base_presenter.rb +10 -1
  42. data/app/services/decidim/action_logger.rb +97 -29
  43. data/app/services/decidim/svg_content_validator.rb +419 -84
  44. data/app/validators/uploader_image_content_validator.rb +6 -2
  45. data/app/views/decidim/manifests/show.json.erb +25 -22
  46. data/app/views/decidim/shared/_results_per_page.html.erb +1 -1
  47. data/config/locales/bg.yml +1 -3
  48. data/config/locales/ca-IT.yml +7 -3
  49. data/config/locales/ca.yml +7 -5
  50. data/config/locales/cs.yml +9 -3
  51. data/config/locales/de.yml +1 -3
  52. data/config/locales/en.yml +5 -3
  53. data/config/locales/es-MX.yml +5 -3
  54. data/config/locales/es-PY.yml +5 -3
  55. data/config/locales/es.yml +7 -5
  56. data/config/locales/eu.yml +10 -8
  57. data/config/locales/fi-plain.yml +2 -2
  58. data/config/locales/fi.yml +2 -2
  59. data/config/locales/fr-CA.yml +5 -3
  60. data/config/locales/fr.yml +5 -3
  61. data/config/locales/gl.yml +0 -1
  62. data/config/locales/it.yml +0 -2
  63. data/config/locales/ja.yml +3 -3
  64. data/config/locales/pl.yml +1 -3
  65. data/config/locales/pt-BR.yml +1 -3
  66. data/config/locales/ro-RO.yml +0 -2
  67. data/config/locales/sk.yml +68 -3
  68. data/config/locales/sv.yml +3 -3
  69. data/config/locales/tr-TR.yml +1 -1
  70. data/db/migrate/20250523104311_move_cta_to_hero_content_block.rb +1 -1
  71. data/db/migrate/20250527122040_move_highlighted_content_banner_settings_to_content_block.rb +3 -0
  72. data/db/migrate/20261007090000_make_user_optional_in_action_logs.rb +12 -0
  73. data/decidim-core.gemspec +1 -1
  74. data/lib/decidim/content_renderers/mention_resource_renderer.rb +1 -1
  75. data/lib/decidim/core/version.rb +1 -1
  76. data/lib/decidim/core.rb +1 -1
  77. data/lib/decidim/maintenance/import_models/scope.rb +2 -1
  78. data/lib/decidim/maintenance/taxonomy_importer.rb +4 -1
  79. data/lib/decidim/seeds.rb +1 -1
  80. data/lib/decidim/view_model.rb +1 -0
  81. data/lib/tasks/decidim_open_data_tasks.rake +7 -0
  82. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8290aaa3b5f8596b066ea39214624b798bc2fa4cbc2555ec74be6f0332b9356f
4
- data.tar.gz: 1a76634eca16d14db59d3f6d61fe7e17ae5d9ca9f44497ca92ae37e09ba2b7f2
3
+ metadata.gz: b36d5939e11ea9f6641061565d89c529db8c1bcbb9c2d1eb42a3e38467962bfa
4
+ data.tar.gz: 9e114b4cb16118a1e9ea8d668c74fb7d5cd22a3b073bd26bf726280d479c3a00
5
5
  SHA512:
6
- metadata.gz: 20697b2436b43b7c2b8d239ee8d865bdc25c2b6916f741ad36398134d995dfb8139d1391cef863931a8a0be9b08a53408511f513367c5c3dec5295a428a00cbf
7
- data.tar.gz: c1b155c89712ddfa2274c99f0965ee2cabc68385e93faf62ed069a39d2d10a87c3911d5b90872b99d44f03aeb0a2a0ddab202be2a330b43af317615d761d52d4
6
+ metadata.gz: d231f0aaa0f6b3470ad0f9e5f651c96291211c1d2bfd729a8e2828ea19e9f286e245524b44a5282977addaf958241ba2696e3c3b8cbbd1dec04da57a6cd70239
7
+ data.tar.gz: 188fc272e8072d119a29d91fefa8808c19ad793e9699512979af8f5786c6c9945a5709b9da28f5ce5e35a05e8054ccd614a5126c5d965bd28a09a6a8d9e9759c
@@ -37,8 +37,12 @@ module Decidim
37
37
  t("show.pending_address", scope: "decidim.meetings.meetings")
38
38
  end
39
39
 
40
+ # Returns true when the model has both start and end times present, so the
41
+ # start-and-end-time section can be rendered.
40
42
  def display_start_and_end_time?
41
- model.respond_to?(:start_time) && model.respond_to?(:end_time)
43
+ return false unless model.respond_to?(:start_time) && model.respond_to?(:end_time)
44
+
45
+ model.start_time.present? && model.end_time.present?
42
46
  end
43
47
 
44
48
  def start_and_end_time
@@ -63,11 +67,11 @@ module Decidim
63
67
  private
64
68
 
65
69
  def start_time
66
- l model.start_time, format: "%H:%M %p"
70
+ l model.start_time, format: :time_of_day
67
71
  end
68
72
 
69
73
  def end_time
70
- l model.end_time, format: "%H:%M %p %Z"
74
+ l model.end_time, format: :time_of_day_with_time_zone
71
75
  end
72
76
  end
73
77
  end
@@ -101,11 +101,13 @@ module Decidim
101
101
  }
102
102
  end
103
103
 
104
+ # Returns the metadata item with the formatted start date time, or nil when
105
+ # the dates are blank.
104
106
  def start_date_item
105
107
  return if dates_blank?
106
108
 
107
109
  {
108
- text: I18n.l(start_date, format: "%H:%M %p %Z"),
110
+ text: I18n.l(start_date.in_time_zone, format: :time_of_day_with_time_zone),
109
111
  icon: "time-line"
110
112
  }
111
113
  end
@@ -2,29 +2,29 @@
2
2
  <% if same_day? %>
3
3
  <div data-date>
4
4
  <%= l start_time, format: "%d" %>
5
- <span data-month><%= l start_time, format: "%B#{" %Y" if show_year?}" %></span>
5
+ <span data-month><%= l start_time, format: show_year? ? :decidim_month_and_year : :decidim_month %></span>
6
6
  </div>
7
7
  <div data-time>
8
- <%= l start_time, format: "%H:%M" %> - <%= l end_time, format: "%H:%M" %>
8
+ <%= l start_time, format: :time_of_day %> - <%= l end_time, format: :time_of_day %>
9
9
  </div>
10
10
  <% else %>
11
11
  <div>
12
12
  <div data-date>
13
13
  <%= l start_time, format: "%d" %>
14
- <span data-month><%= l start_time, format: "%B#{" %Y" if show_year?}" %></span>
14
+ <span data-month><%= l start_time, format: show_year? ? :decidim_month_and_year : :decidim_month %></span>
15
15
  </div>
16
16
  <div data-time>
17
- <%= l start_time, format: "%H:%M" %>
17
+ <%= l start_time, format: :time_of_day %>
18
18
  </div>
19
19
  </div>
20
20
  <%= icon "arrow-right-line" %>
21
21
  <div>
22
22
  <div data-date>
23
23
  <%= l end_time, format: "%d" %>
24
- <span data-month><%= l end_time, format: "%B#{" %Y" if show_year?}" %></span>
24
+ <span data-month><%= l end_time, format: show_year? ? :decidim_month_and_year : :decidim_month %></span>
25
25
  </div>
26
26
  <div data-time>
27
- <%= l end_time, format: "%H:%M" %>
27
+ <%= l end_time, format: :time_of_day %>
28
28
  </div>
29
29
  </div>
30
30
  <% end %>
@@ -21,12 +21,17 @@ module Decidim
21
21
 
22
22
  private
23
23
 
24
+ # Values are normalized to the rendering time zone so the date checks below
25
+ # and the rendered values agree. Plain `Time` and `Date` values (e.g. from
26
+ # `Time.parse` or a database read outside the organization time zone) can
27
+ # fall on a different day once converted, and the checks must use the same
28
+ # zone as the display.
24
29
  def start_time
25
- model[:start]
30
+ model[:start]&.in_time_zone
26
31
  end
27
32
 
28
33
  def end_time
29
- model[:end]
34
+ model[:end]&.in_time_zone
30
35
  end
31
36
 
32
37
  def same_day?
@@ -33,9 +33,8 @@ module Decidim
33
33
  attr_reader :follow, :form
34
34
 
35
35
  def create_follow!
36
- @follow = Follow.where(
37
- followable: form.followable,
38
- user: current_user
36
+ @follow = current_user.following_follows.where(
37
+ followable: form.followable
39
38
  ).first_or_create!
40
39
  end
41
40
 
@@ -66,10 +66,7 @@ module Decidim
66
66
  end
67
67
 
68
68
  def create_or_find_user
69
- @user = User.find_or_initialize_by(
70
- email: verified_email,
71
- organization:
72
- )
69
+ @user = organization.users.find_or_initialize_by(email: verified_email)
73
70
 
74
71
  if @user.persisted?
75
72
  # If user has left the account unconfirmed and later on decides to sign
@@ -120,7 +117,7 @@ module Decidim
120
117
  end
121
118
 
122
119
  def existing_identity
123
- @existing_identity ||= Identity.find_by(
120
+ @existing_identity ||= Identity.find_by( # rubocop:disable Decidim/OrganizationScopedFinder -- user: organization.users scopes the lookup to the current organization
124
121
  user: organization.users,
125
122
  provider: form.provider,
126
123
  uid: form.uid
@@ -38,7 +38,7 @@ module Decidim
38
38
  attr_reader :form, :report
39
39
 
40
40
  def find_or_create_moderation!
41
- @moderation = UserModeration.find_or_create_by!(user: @reportable)
41
+ @moderation = @reportable.user_moderation || @reportable.create_user_moderation!
42
42
  end
43
43
 
44
44
  def create_report!
@@ -57,15 +57,15 @@ module Decidim
57
57
  end
58
58
 
59
59
  def destroy_user_badges
60
- Decidim::Gamification::BadgeScore.where(user: current_user).find_each(&:destroy)
60
+ Decidim::Gamification::BadgeScore.where(user: current_user).find_each(&:destroy) # rubocop:disable Decidim/OrganizationScopedFinder -- records belong to the current user
61
61
  end
62
62
 
63
63
  def destroy_user_reports
64
- Decidim::UserModeration.where(user: current_user).find_each(&:destroy)
64
+ Decidim::UserModeration.where(user: current_user).find_each(&:destroy) # rubocop:disable Decidim/OrganizationScopedFinder -- records belong to the current user
65
65
  end
66
66
 
67
67
  def destroy_user_likes
68
- Decidim::Like.where(author: current_user).find_each(&:destroy)
68
+ Decidim::Like.where(author: current_user).find_each(&:destroy) # rubocop:disable Decidim/OrganizationScopedFinder -- records belong to the current user
69
69
  end
70
70
 
71
71
  def destroy_user_identities
@@ -97,12 +97,12 @@ module Decidim
97
97
  end
98
98
 
99
99
  def destroy_follows
100
- Decidim::Follow.where(followable: current_user).find_each(&:destroy)
101
- Decidim::Follow.where(user: current_user).find_each(&:destroy)
100
+ current_user.follows.find_each(&:destroy)
101
+ current_user.following_follows.find_each(&:destroy)
102
102
  end
103
103
 
104
104
  def destroy_member
105
- Decidim::ParticipatorySpace::Member.where(user: current_user).find_each(&:destroy)
105
+ Decidim::ParticipatorySpace::Member.where(user: current_user).find_each(&:destroy) # rubocop:disable Decidim/OrganizationScopedFinder -- records belong to the current user
106
106
  end
107
107
 
108
108
  def delegate_destroy_to_participatory_spaces
@@ -32,7 +32,9 @@ module Decidim
32
32
  attr_reader :user
33
33
 
34
34
  def destroy_pending_authorizations!
35
+ # rubocop:disable Decidim/OrganizationScopedFinder -- authorizations belong to the ephemeral user passed to the command
35
36
  Decidim::Authorization.where(user:, granted_at: nil).destroy_all
37
+ # rubocop:enable Decidim/OrganizationScopedFinder
36
38
  end
37
39
 
38
40
  def destroy_account!
@@ -27,7 +27,7 @@ module Decidim
27
27
  attr_reader :form
28
28
 
29
29
  def user
30
- @user ||= Decidim::User.where(organization: form.organization).where(email: form.email.downcase).first
30
+ @user ||= form.organization.users.find_by(email: form.email.downcase)
31
31
  end
32
32
 
33
33
  def update_user
@@ -22,7 +22,7 @@ module Decidim
22
22
  end
23
23
 
24
24
  def update_attachment_title_for(attachment)
25
- Decidim::Attachment.find(attachment[:id]).update(title: title_for(attachment))
25
+ attachments_for(attachment_parent).find_by(id: attachment[:id])&.update(title: title_for(attachment))
26
26
  end
27
27
 
28
28
  def attachments_invalid?
@@ -43,7 +43,7 @@ module Decidim
43
43
  weight = first_weight
44
44
  # Add the weights first to the old attachments
45
45
  attachment_ids = keep_ids
46
- Decidim::Attachment.where(id: attachment_ids).each do |attachment|
46
+ attachments_for(attachment_parent).where(id: attachment_ids).each do |attachment|
47
47
  attachment.update!(weight:)
48
48
  weight += 1
49
49
  end
@@ -57,7 +57,8 @@ module Decidim
57
57
  end
58
58
 
59
59
  def attachment_cleanup!(include_all_attachments: false)
60
- attachments = include_all_attachments ? attachments_attached_to.attachments.with_attached_file : attachments_attached_to.attachments
60
+ attachments = attachments_for(attachments_attached_to)
61
+ attachments = attachments.with_attached_file if include_all_attachments
61
62
 
62
63
  attachments.each do |attachment|
63
64
  attachment.destroy! unless keep_ids.include?(attachment.id)
@@ -79,6 +80,19 @@ module Decidim
79
80
  form.current_component.organization if form.respond_to?(:current_component)
80
81
  end
81
82
 
83
+ def attachment_parent
84
+ @attached_to || @resource || attachments_attached_to
85
+ end
86
+
87
+ # Only attachments owned by the record being changed can be modified. Some
88
+ # parents, such as organizations, do not include the attachments concern,
89
+ # so fall back to filtering by the polymorphic association.
90
+ def attachments_for(parent)
91
+ return parent.attachments if parent.respond_to?(:attachments)
92
+
93
+ Decidim::Attachment.where(attached_to: parent) # rubocop:disable Decidim/OrganizationScopedFinder -- parent is the current organization or an already scoped record
94
+ end
95
+
82
96
  def signed_id_for(attachment)
83
97
  return attachment[:file] if attachment.is_a?(Hash)
84
98
 
@@ -7,9 +7,10 @@ module Decidim
7
7
  #
8
8
  # taxonomy_ids - the taxonomy ids to update
9
9
  # resources - an ApplicationRecord collection of resources to update.
10
+ # organization - the organization that owns the taxonomies.
10
11
  def initialize(taxonomy_ids, resources, organization)
11
12
  @organization = organization
12
- @taxonomies = Decidim::Taxonomy.non_roots.where(organization:, id: taxonomy_ids)
13
+ @taxonomies = organization.taxonomies.non_roots.where(id: taxonomy_ids)
13
14
  @resources = resources
14
15
  @response = { taxonomies: [], successful: [], errored: [] }
15
16
  end
@@ -30,7 +30,7 @@ module Decidim
30
30
  end
31
31
 
32
32
  def extension
33
- File.extname(blob_args[:filename]).delete(".")
33
+ File.extname(blob_args[:filename]).delete(".").try(:downcase)
34
34
  end
35
35
 
36
36
  def maximum_allowed_size
@@ -42,11 +42,17 @@ module Decidim
42
42
  end
43
43
 
44
44
  def allowed_extensions
45
- if user_has_elevated_role?
46
- current_organization.settings.upload_allowed_file_extensions_admin
47
- else
48
- current_organization.settings.upload_allowed_file_extensions
49
- end
45
+ extensions = if user_has_elevated_role?
46
+ current_organization.settings.upload_allowed_file_extensions_admin
47
+ else
48
+ current_organization.settings.upload_allowed_file_extensions
49
+ end
50
+
51
+ # The configured extensions are matched case-insensitively, as the
52
+ # filename extension is normalized before the comparison. An allowlist
53
+ # entry such as "JPG" must therefore accept both "photo.jpg" and
54
+ # "photo.JPG".
55
+ extensions.map { |pattern| pattern.to_s.downcase }
50
56
  end
51
57
 
52
58
  def content_types
@@ -87,14 +87,14 @@ module Decidim
87
87
  end
88
88
 
89
89
  def expired_log
90
- @expired_log ||= Decidim::ImpersonationLog
90
+ @expired_log ||= Decidim::ImpersonationLog # rubocop:disable Decidim/OrganizationScopedFinder -- real_user is the impersonated user of the current session
91
91
  .where(admin: real_user)
92
92
  .expired
93
93
  .first
94
94
  end
95
95
 
96
96
  def impersonation_log
97
- @impersonation_log ||= Decidim::ImpersonationLog
97
+ @impersonation_log ||= Decidim::ImpersonationLog # rubocop:disable Decidim/OrganizationScopedFinder -- real_user is the impersonated user of the current session
98
98
  .where(admin: real_user)
99
99
  .active
100
100
  .first
@@ -37,6 +37,21 @@ module Decidim
37
37
  def verify_organization
38
38
  redirect_to decidim_system.root_path unless current_organization
39
39
  end
40
+
41
+ # Checks whether the given resource belongs to the current organization.
42
+ def in_organization?(resource)
43
+ return false if resource.blank?
44
+
45
+ resource.organization == current_organization
46
+ end
47
+
48
+ # Raises ActiveRecord::RecordNotFound when the given resource belongs to
49
+ # another organization. Blank resources are handled by the callers.
50
+ def ensure_in_organization!(resource)
51
+ return if resource.blank? || in_organization?(resource)
52
+
53
+ raise ActiveRecord::RecordNotFound
54
+ end
40
55
  end
41
56
  end
42
57
  end
@@ -22,14 +22,14 @@ module Decidim
22
22
  if amendment_draft
23
23
  redirect_to edit_draft_amend_path(amendment_draft)
24
24
  else
25
- @form = form(Decidim::Amendable::CreateForm).from_params(params)
25
+ @form = form(Decidim::Amendable::CreateForm).from_params(create_params)
26
26
  end
27
27
  end
28
28
 
29
29
  def create
30
30
  enforce_permission_to :create, :amendment, current_component: amendable.component
31
31
 
32
- @form = form(Decidim::Amendable::CreateForm).from_params(params)
32
+ @form = form(Decidim::Amendable::CreateForm).from_params(create_params)
33
33
 
34
34
  Decidim::Amendable::CreateDraft.call(@form) do
35
35
  on(:ok) do |amendment|
@@ -145,13 +145,13 @@ module Decidim
145
145
  def review
146
146
  enforce_permission_to :accept, :amendment, amendable:, current_component: amendable.component
147
147
 
148
- @form = form(Decidim::Amendable::ReviewForm).from_params(params)
148
+ @form = form(Decidim::Amendable::ReviewForm).from_params(review_params)
149
149
  end
150
150
 
151
151
  def accept
152
152
  enforce_permission_to :accept, :amendment, amendable:, current_component: amendable.component
153
153
 
154
- @form = form(Decidim::Amendable::ReviewForm).from_params(params)
154
+ @form = form(Decidim::Amendable::ReviewForm).from_params(review_params)
155
155
 
156
156
  Decidim::Amendable::Accept.call(@form) do
157
157
  on(:ok) do |emendation|
@@ -190,12 +190,40 @@ module Decidim
190
190
  params[:amendable_gid] || params.dig(:amendment, :amendable_gid)
191
191
  end
192
192
 
193
+ # Binds the create form to the already-checked amendable, so a conflicting
194
+ # nested `amendment[amendable_gid]` cannot select another resource.
195
+ def create_params
196
+ params.deep_merge(amendment: { amendable_gid: amendable&.to_sgid&.to_s })
197
+ end
198
+
199
+ # Binds the review form to the amendment from the route, so a nested
200
+ # `amendment[id]` cannot select a different amendment.
201
+ def review_params
202
+ params.deep_merge(amendment: { id: amendment&.id })
203
+ end
204
+
193
205
  def amendment
194
- @amendment ||= Decidim::Amendment.find_by(id: params[:id])
206
+ @amendment ||= Decidim::Amendment.find_by(id: params[:id]) # rubocop:disable Decidim/OrganizationScopedFinder -- Amendment has no organization column; #amendable validates the owning resource
195
207
  end
196
208
 
197
209
  def amendable
198
- @amendable ||= GlobalID::Locator.locate_signed(amendable_gid) || amendment&.amendable
210
+ @amendable ||= begin
211
+ # Existing amendments must always resolve their own amendable, so a
212
+ # foreign amendment cannot be authorized through a local
213
+ # `amendable_gid` supplied alongside its id. The signed resource is
214
+ # only used when creating an amendment.
215
+ resource = if creating_amendment?
216
+ GlobalID::Locator.locate_signed(amendable_gid)
217
+ else
218
+ amendment&.amendable
219
+ end
220
+ ensure_in_organization!(resource)
221
+ resource
222
+ end
223
+ end
224
+
225
+ def creating_amendment?
226
+ %w(new create).include?(action_name)
199
227
  end
200
228
 
201
229
  def emendation
@@ -28,6 +28,7 @@ module Decidim
28
28
  include ActiveStorage::SetCurrent
29
29
  include OnboardingActionMethods
30
30
  include EphemeralSessionChecker
31
+ include Decidim::UrlHelper
31
32
 
32
33
  helper Decidim::MetaTagsHelper
33
34
  helper Decidim::DecidimFormHelper
@@ -44,6 +45,7 @@ module Decidim
44
45
  helper Decidim::SocialShareButtonHelper
45
46
  helper Decidim::FiltersHelper
46
47
  helper Decidim::OnboardingActionHelper
48
+ helper Decidim::UrlHelper
47
49
 
48
50
  register_permissions(::Decidim::ApplicationController,
49
51
  ::Decidim::Admin::Permissions,
@@ -25,7 +25,7 @@ module Decidim
25
25
  end
26
26
 
27
27
  def current_component
28
- @current_component ||= Decidim::Component.where(participatory_space: current_organization.participatory_spaces).find(params[:component_id])
28
+ @current_component ||= Decidim::Component.where(participatory_space: current_organization.participatory_spaces).find(params[:component_id]) # rubocop:disable Decidim/OrganizationScopedFinder -- participatory_spaces is scoped to current_organization
29
29
  end
30
30
 
31
31
  def authorization_action
@@ -6,8 +6,12 @@ module Decidim
6
6
  class AuthorizationsController < ::Doorkeeper::AuthorizationsController
7
7
  include HasSpecificBreadcrumb
8
8
 
9
+ before_action :set_oauth_application
10
+
9
11
  helper_method :oauth_application, :all_abilities?
10
12
 
13
+ attr_reader :oauth_application
14
+
11
15
  def new
12
16
  @scopes =
13
17
  if pre_auth.authorizable?
@@ -19,10 +23,6 @@ module Decidim
19
23
  super
20
24
  end
21
25
 
22
- def oauth_application
23
- @oauth_application ||= Decidim::OAuthApplication.find_by(uid: params[:client_id])
24
- end
25
-
26
26
  def breadcrumb_item
27
27
  {
28
28
  label: t("decidim.doorkeeper.authorizations.new.authorize"),
@@ -32,6 +32,12 @@ module Decidim
32
32
 
33
33
  private
34
34
 
35
+ def set_oauth_application
36
+ return if params[:client_id].blank?
37
+
38
+ @oauth_application = current_organization.oauth_applications.find_by!(uid: params.expect(:client_id))
39
+ end
40
+
35
41
  def all_abilities?
36
42
  %w(api:read api:write).all? { |scope| @scopes.include?(scope) } &&
37
43
  %w(profile user).any? { |scope| @scopes.include?(scope) }
@@ -5,6 +5,7 @@ module Decidim
5
5
  # A controller to expose a simple JSON API so OAuth clients can get the user's information.
6
6
  class CredentialsController < ApplicationController
7
7
  before_action :doorkeeper_authorize!
8
+ before_action :validate_token_organization!
8
9
  respond_to :json
9
10
 
10
11
  def me
@@ -23,8 +24,12 @@ module Decidim
23
24
  }
24
25
  end
25
26
 
27
+ def validate_token_organization!
28
+ ensure_in_organization!(doorkeeper_token&.application)
29
+ end
30
+
26
31
  def current_resource_owner
27
- @current_resource_owner ||= Decidim::User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
32
+ @current_resource_owner ||= current_organization.users.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
28
33
  end
29
34
 
30
35
  def avatar_url
@@ -113,7 +113,7 @@ module Decidim
113
113
  end
114
114
 
115
115
  def conversation
116
- @conversation ||= Conversation.find(params[:id])
116
+ @conversation ||= Conversation.find(params[:id]) # rubocop:disable Decidim/OrganizationScopedFinder -- conversation permissions require the current user to be a participant
117
117
  end
118
118
 
119
119
  def new_conversation(recipient)
@@ -79,7 +79,7 @@ module Decidim
79
79
  def profile_holder
80
80
  return if params[:nickname].blank?
81
81
 
82
- @profile_holder ||= Decidim::UserBaseEntity.find_by("nickname = ? AND decidim_organization_id = ?", params[:nickname].downcase, current_organization.id)
82
+ @profile_holder ||= current_organization.user_entities.find_by(nickname: params[:nickname].downcase)
83
83
  end
84
84
  end
85
85
  end
@@ -8,11 +8,6 @@ module Decidim
8
8
  include Cell::ViewModel::Partial
9
9
  include Decidim::PaginateHelper
10
10
 
11
- def paginate(scope, **options, &)
12
- options = options.reverse_merge(views_prefix: "../views/")
13
- super
14
- end
15
-
16
11
  def per_page
17
12
  params[:per_page].to_i || Decidim::Paginable::OPTIONS.first
18
13
  end
@@ -133,6 +133,7 @@ module Decidim
133
133
  end
134
134
 
135
135
  def current_url(params = request.parameters)
136
+ params = decidim_url_params(params)
136
137
  return url_for(params) if respond_to?(:current_participatory_space) || respond_to?(:current_component)
137
138
 
138
139
  each_decidim_engine do |helpers|
@@ -28,12 +28,14 @@ module Decidim
28
28
 
29
29
  link_to(
30
30
  t("#{i18n_scope}.#{order}"),
31
- url_for(params.to_unsafe_h.except(
32
- "component_id",
33
- "participatory_process_slug",
34
- "assembly_slug",
35
- "initiative_slug"
36
- ).merge(page: nil, order:)),
31
+ url_for(
32
+ decidim_url_params(params, page: nil, order:).except(
33
+ "component_id",
34
+ "participatory_process_slug",
35
+ "assembly_slug",
36
+ "initiative_slug"
37
+ )
38
+ ),
37
39
  {
38
40
  data: { order: },
39
41
  remote: true
@@ -11,11 +11,18 @@ module Decidim
11
11
  def decidim_paginate(collection, paginate_params = {})
12
12
  return if collection.total_pages <= 1
13
13
 
14
+ show_per_page_selector = collection.total_pages.positive? && Decidim::Paginable::OPTIONS.include?(collection.limit_value)
14
15
  per_page = (params[:per_page] || paginate_params[:per_page] || Decidim::Paginable::OPTIONS.first).to_i
15
16
 
16
17
  content_tag :div, class: "flex flex-col-reverse md:flex-row items-center justify-between gap-1 py-8 md:py-16 md:flex-wrap", data: { pagination: "" } do
17
18
  template = ""
18
- template += render(partial: "decidim/shared/results_per_page", locals: { per_page: }, formats: [:html]) if collection.total_pages.positive?
19
+ template +=
20
+ if show_per_page_selector
21
+ render(partial: "decidim/shared/results_per_page", locals: { per_page: }, formats: [:html])
22
+ else
23
+ # Add an empty div to position the pagination pages consistently.
24
+ content_tag :div
25
+ end
19
26
  template += paginate collection, window: 2, outer_window: 1, theme: "decidim", params: pagination_params(paginate_params)
20
27
  template.html_safe
21
28
  end
@@ -24,10 +31,15 @@ module Decidim
24
31
  private
25
32
 
26
33
  def pagination_params(paginate_params)
27
- request_params = params.to_unsafe_h.except("locale", :locale)
34
+ request_params = decidim_url_params(params).except("locale", :locale)
28
35
  request_params["q"] = request_params["q"].except("locale", :locale) if request_params["q"].is_a?(Hash)
29
36
  request_params[:locale] = nil if admin_controller_with_locale_prefix?
30
- request_params.merge(paginate_params)
37
+
38
+ # Sanitize again after merging because Kaminari also merges these
39
+ # parameters with the raw request parameters.
40
+ sanitized_params = decidim_url_params(request_params.merge(paginate_params))
41
+
42
+ sanitized_params.merge(_recall: {}, use_route: nil)
31
43
  end
32
44
 
33
45
  def admin_controller_with_locale_prefix?
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Helper that sanitizes the parameters used to generate URLs.
5
+ module UrlHelper
6
+ # Rails uses these options to build URLs. Allowing user-controlled values
7
+ # for them can change the generated URL's scheme, host, or path. The
8
+ # `_recall` and `use_route` options are handled before the route set
9
+ # resolves the URL, so they are not part of RESERVED_OPTIONS.
10
+ RESERVED_URL_OPTIONS = (
11
+ ActionDispatch::Routing::RouteSet::RESERVED_OPTIONS + [:path_params, :_recall, :use_route]
12
+ ).freeze
13
+
14
+ # Removes the Rails URL generation options from the given parameters and
15
+ # merges the extra parameters.
16
+ #
17
+ # The extra parameters are trusted values defined by the application, so
18
+ # they take precedence over the request parameters. This allows forcing
19
+ # routing options (such as the controller, the action or the format)
20
+ # without letting a request parameter override them.
21
+ #
22
+ # params - An ActionController::Parameters or a Hash.
23
+ # extra_params - A Hash with extra URL generation options.
24
+ #
25
+ # Returns a HashWithIndifferentAccess without the reserved URL options.
26
+ def decidim_url_params(params, **extra_params)
27
+ Decidim::UrlHelper.sanitize_params(params).merge(extra_params)
28
+ end
29
+
30
+ def self.sanitize_params(params)
31
+ params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
32
+ params.with_indifferent_access.except(*RESERVED_URL_OPTIONS)
33
+ end
34
+ end
35
+ end