decidim-core 0.31.8 → 0.31.9

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 (83) 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 +3 -7
  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/devise_controllers.rb +2 -0
  15. data/app/controllers/concerns/decidim/direct_upload.rb +12 -6
  16. data/app/controllers/concerns/decidim/impersonate_users.rb +2 -2
  17. data/app/controllers/concerns/decidim/needs_organization.rb +15 -0
  18. data/app/controllers/decidim/amendments_controller.rb +34 -6
  19. data/app/controllers/decidim/application_controller.rb +2 -0
  20. data/app/controllers/decidim/authorization_modals_controller.rb +1 -1
  21. data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +10 -4
  22. data/app/controllers/decidim/doorkeeper/credentials_controller.rb +6 -1
  23. data/app/controllers/decidim/messaging/conversations_controller.rb +1 -1
  24. data/app/controllers/decidim/profiles_controller.rb +1 -1
  25. data/app/helpers/decidim/cells_paginate_helper.rb +0 -5
  26. data/app/helpers/decidim/layout_helper.rb +1 -0
  27. data/app/helpers/decidim/orders_helper.rb +8 -6
  28. data/app/helpers/decidim/paginate_helper.rb +27 -2
  29. data/app/helpers/decidim/url_helper.rb +35 -0
  30. data/app/jobs/decidim/open_data_job.rb +21 -5
  31. data/app/models/decidim/action_log.rb +7 -1
  32. data/app/models/decidim/component.rb +10 -0
  33. data/app/models/decidim/like.rb +1 -1
  34. data/app/packs/src/decidim/datepicker/datepicker_functions.js +20 -7
  35. data/app/packs/src/decidim/datepicker/form_datepicker.js +18 -2
  36. data/app/packs/src/decidim/datepicker/generate_datepicker.js +12 -4
  37. data/app/packs/src/decidim/datepicker/generate_timepicker.js +5 -3
  38. data/app/packs/src/decidim/datepicker/test/date.test.js +8 -0
  39. data/app/packs/stylesheets/decidim/_datepicker.scss +3 -3
  40. data/app/packs/stylesheets/decidim/_spinner.scss +16 -0
  41. data/app/packs/stylesheets/decidim/_tom_select.scss +1 -1
  42. data/app/presenters/decidim/log/base_presenter.rb +10 -1
  43. data/app/services/decidim/action_logger.rb +97 -29
  44. data/app/services/decidim/svg_content_validator.rb +419 -84
  45. data/app/validators/uploader_image_content_validator.rb +6 -2
  46. data/app/views/decidim/manifests/show.json.erb +25 -22
  47. data/app/views/decidim/shared/_results_per_page.html.erb +1 -1
  48. data/config/locales/bg.yml +1 -3
  49. data/config/locales/ca-IT.yml +5 -3
  50. data/config/locales/ca.yml +7 -5
  51. data/config/locales/cs.yml +9 -3
  52. data/config/locales/de.yml +1 -3
  53. data/config/locales/en.yml +5 -3
  54. data/config/locales/es-MX.yml +5 -3
  55. data/config/locales/es-PY.yml +5 -3
  56. data/config/locales/es.yml +7 -5
  57. data/config/locales/eu.yml +10 -8
  58. data/config/locales/fi-plain.yml +2 -2
  59. data/config/locales/fi.yml +2 -2
  60. data/config/locales/fr-CA.yml +5 -3
  61. data/config/locales/fr.yml +5 -3
  62. data/config/locales/gl.yml +0 -1
  63. data/config/locales/it.yml +0 -2
  64. data/config/locales/ja.yml +3 -3
  65. data/config/locales/pl.yml +1 -3
  66. data/config/locales/pt-BR.yml +1 -3
  67. data/config/locales/ro-RO.yml +0 -2
  68. data/config/locales/sk.yml +49 -3
  69. data/config/locales/sv.yml +3 -3
  70. data/config/locales/tr-TR.yml +1 -1
  71. data/db/migrate/20250523104311_move_cta_to_hero_content_block.rb +1 -1
  72. data/db/migrate/20250527122040_move_highlighted_content_banner_settings_to_content_block.rb +3 -0
  73. data/db/migrate/20261007090000_make_user_optional_in_action_logs.rb +12 -0
  74. data/decidim-core.gemspec +1 -1
  75. data/lib/decidim/content_renderers/mention_resource_renderer.rb +6 -3
  76. data/lib/decidim/core/test/factories.rb +2 -2
  77. data/lib/decidim/core/version.rb +1 -1
  78. data/lib/decidim/core.rb +1 -1
  79. data/lib/decidim/maintenance/import_models/scope.rb +2 -1
  80. data/lib/decidim/maintenance/taxonomy_importer.rb +4 -1
  81. data/lib/decidim/view_model.rb +1 -0
  82. data/lib/tasks/decidim_open_data_tasks.rake +7 -0
  83. metadata +18 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da2944b3eea9b97a316575553e82c7e4a14c3b2e98da84253af02ef05d4a01cc
4
- data.tar.gz: 3e68f90d8259e679f17a9e13811dce598970c90592d9b40fbf281ea89419783c
3
+ metadata.gz: 6e1c01c70cdf678ab170f7d0fd3f2303449ade6aade8aa287145426016920eeb
4
+ data.tar.gz: cb24549047f3c1b3656eaae7cf754fc7c081585a6797e2494d0e7d020f2bf929
5
5
  SHA512:
6
- metadata.gz: bcf39a24518f3d8e7ee79b5fa148bd884e58a7b209b87cafdc0ca447a7d9b22a207a33d535e42507fdac7cf0a8b18dc9d171a042272cf6c273939f292f4723f8
7
- data.tar.gz: 68c57967364106483e793c7e89030bc661124ac5ce42437e47b5084c12713f26b237556559e1c71fd65c53871a282ed2c72383ffad4d2db7501249506031b8c8
6
+ metadata.gz: 423fb639e760d39405d86075fef43cafbf70f45b612395dd17ab27df20f308b6b837d349629a0d9c71f9d356b69a107e76ca0f07dcbd95dfd822b21fad1d0c0a
7
+ data.tar.gz: 0a532ea81a89dc19bd22481b9d47f52735c079e926aa4bdeef0e907bb26d85d324c143cfd764bdb6186080139da92bad33f519258a3921ba8c3830fb39bb4f82
@@ -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?
@@ -32,13 +32,9 @@ module Decidim
32
32
  attr_reader :follow, :form
33
33
 
34
34
  def create_follow!
35
- @follow = Follow.find_by(
36
- followable: form.followable,
37
- user: current_user
38
- ) || Follow.create!(
39
- followable: form.followable,
40
- user: current_user
41
- )
35
+ @follow = current_user.following_follows.where(
36
+ followable: form.followable
37
+ ).first_or_create!
42
38
  end
43
39
 
44
40
  def increment_score
@@ -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_participatory_space_private_user
105
- Decidim::ParticipatorySpacePrivateUser.where(user: current_user).find_each(&:destroy)
105
+ Decidim::ParticipatorySpacePrivateUser.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
@@ -23,6 +23,7 @@ module Decidim
23
23
  include UserBlockedChecker
24
24
  include ActiveStorage::SetCurrent
25
25
  include Decidim::OnboardingActionMethods
26
+ include Decidim::UrlHelper
26
27
 
27
28
  helper Decidim::TranslationsHelper
28
29
  helper Decidim::MetaTagsHelper
@@ -38,6 +39,7 @@ module Decidim
38
39
  helper Decidim::SanitizeHelper
39
40
  helper Decidim::ApplicationHelper
40
41
  helper Decidim::OnboardingActionHelper
42
+ helper Decidim::UrlHelper
41
43
 
42
44
  layout "layouts/decidim/application"
43
45
 
@@ -29,7 +29,7 @@ module Decidim
29
29
  end
30
30
 
31
31
  def extension
32
- File.extname(blob_args[:filename]).delete(".")
32
+ File.extname(blob_args[:filename]).delete(".").try(:downcase)
33
33
  end
34
34
 
35
35
  def maximum_allowed_size
@@ -41,11 +41,17 @@ module Decidim
41
41
  end
42
42
 
43
43
  def allowed_extensions
44
- if user_has_elevated_role?
45
- current_organization.settings.upload_allowed_file_extensions_admin
46
- else
47
- current_organization.settings.upload_allowed_file_extensions
48
- end
44
+ extensions = if user_has_elevated_role?
45
+ current_organization.settings.upload_allowed_file_extensions_admin
46
+ else
47
+ current_organization.settings.upload_allowed_file_extensions
48
+ end
49
+
50
+ # The configured extensions are matched case-insensitively, as the
51
+ # filename extension is normalized before the comparison. An allowlist
52
+ # entry such as "JPG" must therefore accept both "photo.jpg" and
53
+ # "photo.JPG".
54
+ extensions.map { |pattern| pattern.to_s.downcase }
49
55
  end
50
56
 
51
57
  def content_types
@@ -83,14 +83,14 @@ module Decidim
83
83
  end
84
84
 
85
85
  def expired_log
86
- @expired_log ||= Decidim::ImpersonationLog
86
+ @expired_log ||= Decidim::ImpersonationLog # rubocop:disable Decidim/OrganizationScopedFinder -- real_user is the impersonated user of the current session
87
87
  .where(admin: real_user)
88
88
  .expired
89
89
  .first
90
90
  end
91
91
 
92
92
  def impersonation_log
93
- @impersonation_log ||= Decidim::ImpersonationLog
93
+ @impersonation_log ||= Decidim::ImpersonationLog # rubocop:disable Decidim/OrganizationScopedFinder -- real_user is the impersonated user of the current session
94
94
  .where(admin: real_user)
95
95
  .active
96
96
  .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
@@ -21,14 +21,14 @@ module Decidim
21
21
  if amendment_draft
22
22
  redirect_to edit_draft_amend_path(amendment_draft)
23
23
  else
24
- @form = form(Decidim::Amendable::CreateForm).from_params(params)
24
+ @form = form(Decidim::Amendable::CreateForm).from_params(create_params)
25
25
  end
26
26
  end
27
27
 
28
28
  def create
29
29
  enforce_permission_to :create, :amendment, current_component: amendable.component
30
30
 
31
- @form = form(Decidim::Amendable::CreateForm).from_params(params)
31
+ @form = form(Decidim::Amendable::CreateForm).from_params(create_params)
32
32
 
33
33
  Decidim::Amendable::CreateDraft.call(@form) do
34
34
  on(:ok) do |amendment|
@@ -144,13 +144,13 @@ module Decidim
144
144
  def review
145
145
  enforce_permission_to :accept, :amendment, amendable:, current_component: amendable.component
146
146
 
147
- @form = form(Decidim::Amendable::ReviewForm).from_params(params)
147
+ @form = form(Decidim::Amendable::ReviewForm).from_params(review_params)
148
148
  end
149
149
 
150
150
  def accept
151
151
  enforce_permission_to :accept, :amendment, amendable:, current_component: amendable.component
152
152
 
153
- @form = form(Decidim::Amendable::ReviewForm).from_params(params)
153
+ @form = form(Decidim::Amendable::ReviewForm).from_params(review_params)
154
154
 
155
155
  Decidim::Amendable::Accept.call(@form) do
156
156
  on(:ok) do |emendation|
@@ -189,12 +189,40 @@ module Decidim
189
189
  params[:amendable_gid] || params.dig(:amendment, :amendable_gid)
190
190
  end
191
191
 
192
+ # Binds the create form to the already-checked amendable, so a conflicting
193
+ # nested `amendment[amendable_gid]` cannot select another resource.
194
+ def create_params
195
+ params.deep_merge(amendment: { amendable_gid: amendable&.to_sgid&.to_s })
196
+ end
197
+
198
+ # Binds the review form to the amendment from the route, so a nested
199
+ # `amendment[id]` cannot select a different amendment.
200
+ def review_params
201
+ params.deep_merge(amendment: { id: amendment&.id })
202
+ end
203
+
192
204
  def amendment
193
- @amendment ||= Decidim::Amendment.find_by(id: params[:id])
205
+ @amendment ||= Decidim::Amendment.find_by(id: params[:id]) # rubocop:disable Decidim/OrganizationScopedFinder -- Amendment has no organization column; #amendable validates the owning resource
194
206
  end
195
207
 
196
208
  def amendable
197
- @amendable ||= GlobalID::Locator.locate_signed(amendable_gid) || amendment&.amendable
209
+ @amendable ||= begin
210
+ # Existing amendments must always resolve their own amendable, so a
211
+ # foreign amendment cannot be authorized through a local
212
+ # `amendable_gid` supplied alongside its id. The signed resource is
213
+ # only used when creating an amendment.
214
+ resource = if creating_amendment?
215
+ GlobalID::Locator.locate_signed(amendable_gid)
216
+ else
217
+ amendment&.amendable
218
+ end
219
+ ensure_in_organization!(resource)
220
+ resource
221
+ end
222
+ end
223
+
224
+ def creating_amendment?
225
+ %w(new create).include?(action_name)
198
226
  end
199
227
 
200
228
  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[: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)
@@ -71,7 +71,7 @@ module Decidim
71
71
  def profile_holder
72
72
  return if params[:nickname].blank?
73
73
 
74
- @profile_holder ||= Decidim::UserBaseEntity.find_by("nickname = ? AND decidim_organization_id = ?", params[:nickname].downcase, current_organization.id)
74
+ @profile_holder ||= current_organization.user_entities.find_by(nickname: params[:nickname].downcase)
75
75
  end
76
76
  end
77
77
  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,14 +11,39 @@ 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 += paginate collection, window: 2, outer_window: 1, theme: "decidim", params: paginate_params
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
26
+ template += paginate collection, window: 2, outer_window: 1, theme: "decidim", params: pagination_params(paginate_params)
20
27
  template.html_safe
21
28
  end
22
29
  end
30
+
31
+ private
32
+
33
+ def pagination_params(paginate_params)
34
+ request_params = decidim_url_params(params).except("locale", :locale)
35
+ request_params["q"] = request_params["q"].except("locale", :locale) if request_params["q"].is_a?(Hash)
36
+ request_params[:locale] = nil if admin_controller_with_locale_prefix?
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)
43
+ end
44
+
45
+ def admin_controller_with_locale_prefix?
46
+ request.path_parameters[:locale].present? && controller_path.to_s.include?("/admin/")
47
+ end
23
48
  end
24
49
  end