decidim-core 0.31.7 → 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.
- checksums.yaml +4 -4
- data/app/cells/decidim/address_cell.rb +7 -3
- data/app/cells/decidim/card_metadata_cell.rb +3 -1
- data/app/cells/decidim/content_blocks/participatory_space_main_data/title.erb +1 -14
- data/app/cells/decidim/date_range/show.erb +6 -6
- data/app/cells/decidim/date_range_cell.rb +7 -2
- data/app/cells/decidim/following_cell.rb +1 -1
- data/app/cells/decidim/nav_links/show.erb +3 -1
- data/app/cells/decidim/participatory_space_private_user/show.erb +1 -1
- data/app/cells/decidim/share_text_widget/modal.erb +1 -0
- data/app/cells/decidim/share_widget/modal.erb +1 -0
- data/app/cells/decidim/share_widget/qr_code_modal.erb +2 -4
- data/app/commands/decidim/create_follow.rb +3 -7
- data/app/commands/decidim/create_omniauth_registration.rb +19 -7
- data/app/commands/decidim/create_user_report.rb +1 -1
- data/app/commands/decidim/destroy_account.rb +6 -6
- data/app/commands/decidim/destroy_ephemeral_user.rb +2 -0
- data/app/commands/decidim/invite_user.rb +1 -1
- data/app/commands/decidim/multiple_attachments_methods.rb +17 -3
- data/app/commands/decidim/update_resources_taxonomies.rb +2 -1
- data/app/controllers/concerns/decidim/devise_authentication_methods.rb +4 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +4 -0
- data/app/controllers/concerns/decidim/direct_upload.rb +12 -6
- data/app/controllers/concerns/decidim/disable_redirection_to_external_host.rb +2 -0
- data/app/controllers/concerns/decidim/filter_resource.rb +2 -0
- data/app/controllers/concerns/decidim/impersonate_users.rb +4 -4
- data/app/controllers/concerns/decidim/locale_switcher.rb +62 -11
- data/app/controllers/concerns/decidim/needs_organization.rb +15 -0
- data/app/controllers/concerns/decidim/needs_permission.rb +22 -10
- data/app/controllers/concerns/decidim/onboarding_action_methods.rb +2 -0
- data/app/controllers/concerns/decidim/paginable.rb +7 -3
- data/app/controllers/concerns/decidim/payload_info.rb +2 -0
- data/app/controllers/concerns/decidim/resource_versions_concern.rb +14 -0
- data/app/controllers/decidim/amendments_controller.rb +34 -6
- data/app/controllers/decidim/application_controller.rb +2 -6
- data/app/controllers/decidim/authorization_modals_controller.rb +3 -1
- data/app/controllers/decidim/components/base_controller.rb +2 -0
- data/app/controllers/decidim/devise/passwords_controller.rb +8 -0
- data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +10 -4
- data/app/controllers/decidim/doorkeeper/credentials_controller.rb +6 -1
- data/app/controllers/decidim/favicon_controller.rb +9 -0
- data/app/controllers/decidim/free_resource_authorization_modals_controller.rb +2 -0
- data/app/controllers/decidim/gamification/badges_controller.rb +2 -0
- data/app/controllers/decidim/homepage_controller.rb +4 -1
- data/app/controllers/decidim/likes_controller.rb +1 -1
- data/app/controllers/decidim/links_controller.rb +2 -0
- data/app/controllers/decidim/manifests_controller.rb +2 -0
- data/app/controllers/decidim/messaging/conversations_controller.rb +11 -5
- data/app/controllers/decidim/newsletters_controller.rb +4 -0
- data/app/controllers/decidim/notifications_subscriptions_controller.rb +4 -0
- data/app/controllers/decidim/offline_controller.rb +5 -1
- data/app/controllers/decidim/open_data_controller.rb +5 -1
- data/app/controllers/decidim/pages_controller.rb +31 -3
- data/app/controllers/decidim/private_downloads_controller.rb +2 -0
- data/app/controllers/decidim/profiles_controller.rb +11 -1
- data/app/controllers/decidim/qr_controller.rb +3 -1
- data/app/controllers/decidim/resource_autocomplete_controller.rb +2 -0
- data/app/controllers/decidim/searches_controller.rb +2 -0
- data/app/controllers/decidim/short_links_controller.rb +4 -0
- data/app/controllers/decidim/static_map_controller.rb +2 -0
- data/app/controllers/decidim/timeouts_controller.rb +4 -0
- data/app/controllers/decidim/tos_controller.rb +2 -0
- data/app/controllers/decidim/upload_validations_controller.rb +4 -2
- data/app/controllers/decidim/user_activities_controller.rb +2 -0
- data/app/forms/decidim/upload_validation_form.rb +16 -10
- data/app/helpers/concerns/decidim/user_role_checker.rb +35 -10
- data/app/helpers/decidim/cells_paginate_helper.rb +0 -5
- data/app/helpers/decidim/layout_helper.rb +1 -0
- data/app/helpers/decidim/orders_helper.rb +8 -6
- data/app/helpers/decidim/paginate_helper.rb +27 -2
- data/app/helpers/decidim/sanitize_helper.rb +11 -1
- data/app/helpers/decidim/url_helper.rb +35 -0
- data/app/jobs/decidim/application_job.rb +4 -0
- data/app/jobs/decidim/open_data_job.rb +21 -5
- data/app/models/decidim/action_log.rb +7 -1
- data/app/models/decidim/authorization.rb +24 -0
- data/app/models/decidim/component.rb +10 -0
- data/app/models/decidim/like.rb +1 -1
- data/app/models/decidim/oauth_application.rb +1 -0
- data/app/models/decidim/user.rb +1 -0
- data/app/models/decidim/user_base_entity.rb +1 -1
- data/app/packs/src/decidim/callout.js +10 -0
- data/app/packs/src/decidim/callout.test.js +32 -0
- data/app/packs/src/decidim/controllers/accordion/accordion.test.js +64 -0
- data/app/packs/src/decidim/controllers/accordion/controller.js +43 -0
- data/app/packs/src/decidim/datepicker/datepicker_functions.js +54 -30
- data/app/packs/src/decidim/datepicker/form_datepicker.js +18 -2
- data/app/packs/src/decidim/datepicker/generate_datepicker.js +16 -8
- data/app/packs/src/decidim/datepicker/generate_timepicker.js +5 -3
- data/app/packs/src/decidim/datepicker/test/date.test.js +8 -0
- data/app/packs/src/decidim/datepicker/test/time.test.js +39 -24
- data/app/packs/src/decidim/utilities/dom.js +2 -2
- data/app/packs/stylesheets/decidim/_content_blocks.scss +4 -10
- data/app/packs/stylesheets/decidim/_conversations.scss +0 -8
- data/app/packs/stylesheets/decidim/_datepicker.scss +3 -3
- data/app/packs/stylesheets/decidim/_modal.scss +16 -8
- data/app/packs/stylesheets/decidim/_modal_share.scss +0 -22
- data/app/packs/stylesheets/decidim/_participatory_spaces.scss +11 -1
- data/app/packs/stylesheets/decidim/_rich_text.scss +12 -9
- data/app/packs/stylesheets/decidim/_spinner.scss +16 -0
- data/app/packs/stylesheets/decidim/_tom_select.scss +1 -1
- data/app/packs/stylesheets/decidim/_typography.scss +5 -2
- data/app/packs/stylesheets/decidim/legacy/email.scss +0 -5
- data/app/permissions/decidim/permissions.rb +20 -0
- data/app/presenters/decidim/admin_log/component_presenter.rb +1 -1
- data/app/presenters/decidim/log/base_presenter.rb +20 -2
- data/app/presenters/decidim/log/user_presenter.rb +2 -2
- data/app/serializers/decidim/exporters/open_data_blocked_user_serializer.rb +11 -2
- data/app/serializers/decidim/exporters/open_data_moderation_serializer.rb +25 -1
- data/app/services/decidim/action_logger.rb +97 -29
- data/app/services/decidim/svg_content_validator.rb +889 -0
- data/app/uploaders/decidim/application_uploader.rb +2 -2
- data/app/validators/uploader_image_content_validator.rb +282 -0
- data/app/views/decidim/application/_radio_accordion.html.erb +1 -5
- data/app/views/decidim/manifests/show.json.erb +25 -22
- data/app/views/decidim/messaging/conversations/create.js.erb +1 -3
- data/app/views/decidim/shared/_login_modal.html.erb +12 -14
- data/app/views/decidim/shared/_results_per_page.html.erb +1 -1
- data/app/views/layouts/decidim/_mailer_logo.html.erb +1 -1
- data/config/initializers/rack_attack.rb +10 -0
- data/config/locales/bg.yml +1 -4
- data/config/locales/ca-IT.yml +8 -4
- data/config/locales/ca.yml +10 -6
- data/config/locales/cs.yml +16 -4
- data/config/locales/de.yml +62 -6
- data/config/locales/en.yml +8 -4
- data/config/locales/es-MX.yml +8 -4
- data/config/locales/es-PY.yml +8 -4
- data/config/locales/es.yml +14 -10
- data/config/locales/eu.yml +165 -164
- data/config/locales/fi-plain.yml +3 -3
- data/config/locales/fi.yml +3 -3
- data/config/locales/fr-CA.yml +8 -4
- data/config/locales/fr.yml +8 -4
- data/config/locales/gl.yml +1440 -33
- data/config/locales/hu.yml +0 -1
- data/config/locales/it.yml +0 -2
- data/config/locales/ja.yml +4 -4
- data/config/locales/pl.yml +1 -4
- data/config/locales/pt-BR.yml +1 -4
- data/config/locales/ro-RO.yml +0 -3
- data/config/locales/sk.yml +51 -4
- data/config/locales/sv.yml +50 -13
- data/config/locales/tr-TR.yml +1 -3
- data/db/migrate/20250523104311_move_cta_to_hero_content_block.rb +1 -1
- data/db/migrate/20250527122040_move_highlighted_content_banner_settings_to_content_block.rb +3 -0
- data/db/migrate/20260909000000_add_failed_attempts_and_locked_at_to_decidim_authorizations.rb +8 -0
- data/db/migrate/20261007090000_make_user_optional_in_action_logs.rb +12 -0
- data/decidim-core.gemspec +1 -1
- data/lib/decidim/content_renderers/mention_resource_renderer.rb +6 -3
- data/lib/decidim/core/test/factories.rb +2 -2
- data/lib/decidim/core/test/shared_examples/participatory_space_members_page_examples.rb +77 -0
- data/lib/decidim/core/test/shared_examples/participatory_space_members_shared_examples.rb +85 -6
- data/lib/decidim/core/test/shared_examples/versions_controller_examples.rb +23 -1
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/core.rb +10 -1
- data/lib/decidim/has_upload_validations.rb +1 -0
- data/lib/decidim/legacy_form_builder.rb +4 -0
- data/lib/decidim/maintenance/import_models/scope.rb +2 -1
- data/lib/decidim/maintenance/taxonomy_importer.rb +4 -1
- data/lib/decidim/query_extensions.rb +2 -0
- data/lib/decidim/view_model.rb +1 -0
- data/lib/tasks/decidim_open_data_tasks.rake +7 -0
- metadata +22 -10
|
@@ -12,6 +12,8 @@ module Decidim
|
|
|
12
12
|
helper_method :term
|
|
13
13
|
|
|
14
14
|
def index
|
|
15
|
+
enforce_permission_to :read, :search
|
|
16
|
+
|
|
15
17
|
Search.call(term, current_organization, filters, page_params) do
|
|
16
18
|
on(:ok) do |results|
|
|
17
19
|
results_count = results.sum { |results_by_type| results_by_type.last[:count] }
|
|
@@ -8,6 +8,8 @@ module Decidim
|
|
|
8
8
|
# The index action redirects the user to the application root in case
|
|
9
9
|
# someone tries to request the short link URL without an identifier.
|
|
10
10
|
def index
|
|
11
|
+
enforce_permission_to :read, :short_link
|
|
12
|
+
|
|
11
13
|
redirect_to decidim.root_path, status: :moved_permanently
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -18,6 +20,8 @@ module Decidim
|
|
|
18
20
|
# @raise [ActionController::RoutingError] if a short link does not exist
|
|
19
21
|
# with the given identifier
|
|
20
22
|
def show
|
|
23
|
+
enforce_permission_to :read, :short_link
|
|
24
|
+
|
|
21
25
|
raise ActionController::RoutingError, "Not Found" unless link
|
|
22
26
|
|
|
23
27
|
redirect_to link.target_url, status: :moved_permanently
|
|
@@ -13,6 +13,8 @@ module Decidim
|
|
|
13
13
|
prepend_before_action :skip_timeout, only: :seconds_until_timeout
|
|
14
14
|
|
|
15
15
|
def seconds_until_timeout
|
|
16
|
+
enforce_permission_to :read, :timeout
|
|
17
|
+
|
|
16
18
|
time_remaining = current_user ? Decidim.config.expire_session_after - (Time.current - Time.zone.at(user_session["last_request_at"])) : 0
|
|
17
19
|
respond_to do |format|
|
|
18
20
|
format.json { render json: { seconds_remaining: time_remaining.to_i }, status: :ok }
|
|
@@ -21,6 +23,8 @@ module Decidim
|
|
|
21
23
|
|
|
22
24
|
# If user wants to continue session after inactivity warning.
|
|
23
25
|
def heartbeat
|
|
26
|
+
enforce_permission_to :read, :timeout
|
|
27
|
+
|
|
24
28
|
respond_to do |format|
|
|
25
29
|
format.js
|
|
26
30
|
end
|
|
@@ -7,6 +7,8 @@ module Decidim
|
|
|
7
7
|
skip_before_action :store_current_location
|
|
8
8
|
|
|
9
9
|
def accept_tos
|
|
10
|
+
enforce_permission_to(:update, :user, current_user:)
|
|
11
|
+
|
|
10
12
|
current_user.accepted_tos_version = Time.current
|
|
11
13
|
if current_user.save!
|
|
12
14
|
flash[:notice] = t("accept.success", scope: "decidim.pages.terms_of_service")
|
|
@@ -10,6 +10,8 @@ module Decidim
|
|
|
10
10
|
before_action :underscore_params!
|
|
11
11
|
|
|
12
12
|
def create
|
|
13
|
+
enforce_permission_to :create, :upload_validation
|
|
14
|
+
|
|
13
15
|
@form = form(Decidim::UploadValidationForm).from_params(params)
|
|
14
16
|
|
|
15
17
|
ValidateUpload.call(@form) do
|
|
@@ -23,14 +25,14 @@ module Decidim
|
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
private
|
|
29
|
+
|
|
26
30
|
def organization_time_zone
|
|
27
31
|
return Rails.application.config.time_zone unless current_organization
|
|
28
32
|
|
|
29
33
|
super
|
|
30
34
|
end
|
|
31
35
|
|
|
32
|
-
private
|
|
33
|
-
|
|
34
36
|
def ensure_authenticated!
|
|
35
37
|
return true unless current_organization
|
|
36
38
|
|
|
@@ -12,6 +12,8 @@ module Decidim
|
|
|
12
12
|
helper_method :activities, :resource_types, :user
|
|
13
13
|
|
|
14
14
|
def index
|
|
15
|
+
enforce_permission_to :read, :profile
|
|
16
|
+
|
|
15
17
|
raise ActionController::RoutingError, "Missing user: #{params[:nickname]}" unless user
|
|
16
18
|
raise ActionController::RoutingError, "Blocked User" if user.blocked? && !current_user&.admin?
|
|
17
19
|
end
|
|
@@ -32,16 +32,22 @@ module Decidim
|
|
|
32
32
|
private
|
|
33
33
|
|
|
34
34
|
def file_validators
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
if resource_class.constantize == Decidim::ContentBlockAttachment && resource_class.constantize.validators_on(property.to_sym).none?
|
|
36
|
+
extension = blob.filename.to_s.split(".").last&.downcase
|
|
37
|
+
allowed = Decidim::RecordImageUploader.new(nil, :file).extension_allowlist
|
|
38
|
+
errors.add(property.to_sym, I18n.t("errors.messages.allowed_file_content_types", types: allowed.join(", "))) if extension.present? && allowed.exclude?(extension)
|
|
39
|
+
else
|
|
40
|
+
org = organization
|
|
41
|
+
PassthruValidator.new(
|
|
42
|
+
attributes: [property],
|
|
43
|
+
to: resource_class.constantize,
|
|
44
|
+
with: lambda { |record|
|
|
45
|
+
validate_with.tap do |hash|
|
|
46
|
+
hash.merge!(organization: record.try(:organization) || org) if !hash[:organization] && record.respond_to?(:organization=)
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
).validate_each(self, property.to_sym, blob)
|
|
50
|
+
end
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
def validate_with
|
|
@@ -10,35 +10,60 @@ module Decidim
|
|
|
10
10
|
def user_has_any_role?(user, participatory_space = nil, broad_check: false)
|
|
11
11
|
return false unless user
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
@user_has_any_role_cache ||= {}
|
|
14
|
+
cache_key = [user.id, participatory_space&.class&.name, participatory_space&.id, broad_check]
|
|
15
|
+
return @user_has_any_role_cache[cache_key] if @user_has_any_role_cache.has_key?(cache_key)
|
|
16
|
+
|
|
17
|
+
@user_has_any_role_cache[cache_key] = global_user_role?(user) || space_user_role?(user, participatory_space, broad_check:)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def global_user_role?(user)
|
|
21
|
+
user.admin || user.roles.any?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def space_user_role?(user, participatory_space, broad_check: false)
|
|
25
|
+
return participatory_process_user_role?(user, participatory_space, broad_check:) if participatory_process_space?(participatory_space)
|
|
26
|
+
return assembly_user_role?(user, participatory_space, broad_check:) if assembly_space?(participatory_space)
|
|
27
|
+
return conference_user_role?(user, participatory_space, broad_check:) if conference_space?(participatory_space)
|
|
28
|
+
return false unless broad_check
|
|
29
|
+
|
|
30
|
+
participatory_process_user_role?(user, nil, broad_check: true) ||
|
|
31
|
+
assembly_user_role?(user, nil, broad_check: true) ||
|
|
32
|
+
conference_user_role?(user, nil, broad_check: true)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def participatory_process_space?(participatory_space)
|
|
36
|
+
Decidim.module_installed?(:participatory_processes) && participatory_space.is_a?(Decidim::ParticipatoryProcess)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def assembly_space?(participatory_space)
|
|
40
|
+
Decidim.module_installed?(:assemblies) && participatory_space.is_a?(Decidim::Assembly)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def conference_space?(participatory_space)
|
|
44
|
+
Decidim.module_installed?(:conferences) && participatory_space.is_a?(Decidim::Conference)
|
|
20
45
|
end
|
|
21
46
|
|
|
22
47
|
def participatory_process_user_role?(user, participatory_process = nil, broad_check: false)
|
|
23
48
|
return false unless Decidim.module_installed?(:participatory_processes)
|
|
49
|
+
return false unless participatory_process.nil? || participatory_process.is_a?(Decidim::ParticipatoryProcess)
|
|
24
50
|
return Decidim::ParticipatoryProcessUserRole.exists?(user:) if broad_check
|
|
25
|
-
return false unless participatory_process.is_a?(Decidim::ParticipatoryProcess)
|
|
26
51
|
|
|
27
52
|
Decidim::ParticipatoryProcessUserRole.exists?(user:, participatory_process:)
|
|
28
53
|
end
|
|
29
54
|
|
|
30
55
|
def assembly_user_role?(user, assembly = nil, broad_check: false)
|
|
31
56
|
return false unless Decidim.module_installed?(:assemblies)
|
|
57
|
+
return false unless assembly.nil? || assembly.is_a?(Decidim::Assembly)
|
|
32
58
|
return Decidim::AssemblyUserRole.exists?(user:) if broad_check
|
|
33
|
-
return false unless assembly.is_a?(Decidim::Assembly)
|
|
34
59
|
|
|
35
60
|
Decidim::AssemblyUserRole.exists?(user:, assembly:)
|
|
36
61
|
end
|
|
37
62
|
|
|
38
63
|
def conference_user_role?(user, conference = nil, broad_check: false)
|
|
39
64
|
return false unless Decidim.module_installed?(:conferences)
|
|
65
|
+
return false unless conference.nil? || conference.is_a?(Decidim::Conference)
|
|
40
66
|
return Decidim::ConferenceUserRole.exists?(user:) if broad_check
|
|
41
|
-
return false unless conference.is_a?(Decidim::Conference)
|
|
42
67
|
|
|
43
68
|
Decidim::ConferenceUserRole.exists?(user:, conference:)
|
|
44
69
|
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(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 +=
|
|
19
|
-
|
|
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
|
|
@@ -55,8 +55,18 @@ module Decidim
|
|
|
55
55
|
)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# Public: Escapes the HTML special characters of a user-inputted string.
|
|
59
|
+
#
|
|
60
|
+
# The result is marked as HTML-safe, so that when the views output it with
|
|
61
|
+
# `<%= %>` (or pass it to a tag helper) Rails does not escape it a second
|
|
62
|
+
# time. Otherwise, a text such as `O'Neil` would end up as `O&#39;Neil` in
|
|
63
|
+
# the HTML and the browser would display the `'` entity literally.
|
|
64
|
+
#
|
|
65
|
+
# text - A String (or an object responding to `to_str`).
|
|
66
|
+
#
|
|
67
|
+
# Returns an HTML-safe String.
|
|
58
68
|
def decidim_html_escape(text)
|
|
59
|
-
ERB::Util.
|
|
69
|
+
ERB::Util.html_escape(text.to_str)
|
|
60
70
|
end
|
|
61
71
|
|
|
62
72
|
def decidim_url_escape(text)
|
|
@@ -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
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
module Decidim
|
|
4
4
|
class ApplicationJob < ActiveJob::Base
|
|
5
|
+
# Wait until the commits on the transaction are actually on the database
|
|
6
|
+
# before running the jobs, preventing possible race conditions.
|
|
7
|
+
self.enqueue_after_transaction_commit = true
|
|
8
|
+
|
|
5
9
|
# Automatically retry jobs that encountered a deadlock
|
|
6
10
|
retry_on ActiveRecord::Deadlocked
|
|
7
11
|
|
|
@@ -5,14 +5,30 @@ module Decidim
|
|
|
5
5
|
queue_as :exports
|
|
6
6
|
|
|
7
7
|
def perform(organization, resource = nil)
|
|
8
|
-
path =
|
|
8
|
+
path = nil
|
|
9
|
+
organization = Organization.with_attached_open_data_files.find(organization&.id)
|
|
10
|
+
|
|
11
|
+
filename = organization.open_data_file_path(resource)
|
|
12
|
+
tmp_filename = "#{SecureRandom.uuid}-#{filename}"
|
|
13
|
+
path = Rails.root.join("tmp", tmp_filename)
|
|
14
|
+
|
|
15
|
+
Rails.logger.info "[OpenDataJob] Starting export for organization=#{organization.id} resource=#{resource.inspect}"
|
|
9
16
|
|
|
10
17
|
exporter = OpenDataExporter.new(organization, path, resource)
|
|
11
|
-
|
|
18
|
+
exported_bytes = exporter.export
|
|
19
|
+
|
|
20
|
+
raise "Export produced no data (0 bytes) for resource=#{resource.inspect}" unless exported_bytes.is_a?(Integer) && exported_bytes.positive?
|
|
21
|
+
|
|
22
|
+
File.open(path, "rb") do |file|
|
|
23
|
+
organization.open_data_files.attach(io: file, filename:)
|
|
24
|
+
end
|
|
12
25
|
|
|
13
|
-
organization.open_data_files.
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
organization.open_data_files.select { |f| f.blob.filename.to_s == filename }.sort_by(&:created_at)[0...-1].each(&:purge)
|
|
27
|
+
rescue StandardError => e
|
|
28
|
+
Rails.logger.error "[OpenDataJob] Export failed for organization=#{organization&.id} resource=#{resource.inspect}: #{e.message}"
|
|
29
|
+
raise
|
|
30
|
+
ensure
|
|
31
|
+
FileUtils.rm_f(path) if path.present?
|
|
16
32
|
end
|
|
17
33
|
end
|
|
18
34
|
end
|
|
@@ -12,7 +12,11 @@ module Decidim
|
|
|
12
12
|
foreign_key: :decidim_organization_id,
|
|
13
13
|
class_name: "Decidim::Organization"
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
# As we need to generate logs that do not have a certain user (see #17282),
|
|
16
|
+
# we need to allow user to be optional.
|
|
17
|
+
belongs_to :user,
|
|
18
|
+
class_name: "Decidim::UserBaseEntity",
|
|
19
|
+
optional: true
|
|
16
20
|
|
|
17
21
|
belongs_to :component,
|
|
18
22
|
foreign_key: :decidim_component_id,
|
|
@@ -198,6 +202,8 @@ module Decidim
|
|
|
198
202
|
# Lazy loads the `user` association through BatchLoader, can be used
|
|
199
203
|
# as a regular object.
|
|
200
204
|
def user_lazy(cache: true)
|
|
205
|
+
return if user_id.blank? || user_type.blank?
|
|
206
|
+
|
|
201
207
|
self.class.lazy_relation(user_id, user_type, cache)
|
|
202
208
|
end
|
|
203
209
|
|
|
@@ -98,6 +98,30 @@ module Decidim
|
|
|
98
98
|
user == self.user
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
def record_failed_attempt!
|
|
102
|
+
with_lock do
|
|
103
|
+
increment!(:failed_attempts) # rubocop:disable Rails/SkipsModelValidations
|
|
104
|
+
return unless failed_attempts >= Decidim.verification_max_failed_attempts
|
|
105
|
+
|
|
106
|
+
update!(locked_at: Time.current)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def reset_failed_attempts!
|
|
111
|
+
update!(failed_attempts: 0, locked_at: nil)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def locked_for_confirmation?
|
|
115
|
+
locked_at.present? && locked_at + Decidim.verification_unlock_in > Time.current
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def clear_expired_lock!
|
|
119
|
+
return if locked_at.blank?
|
|
120
|
+
return if locked_for_confirmation?
|
|
121
|
+
|
|
122
|
+
update!(locked_at: nil, failed_attempts: 0)
|
|
123
|
+
end
|
|
124
|
+
|
|
101
125
|
private
|
|
102
126
|
|
|
103
127
|
def active_handler?
|
|
@@ -19,6 +19,16 @@ module Decidim
|
|
|
19
19
|
|
|
20
20
|
scope :registered_component_manifests, -> { where(manifest_name: Decidim.component_registry.manifests.collect(&:name)) }
|
|
21
21
|
scope :registered_space_manifests, -> { where(participatory_space_type: Decidim.participatory_space_registry.manifests.collect(&:model_class_name)) }
|
|
22
|
+
scope :for_organization, lambda { |organization:|
|
|
23
|
+
conditions = Decidim.participatory_space_registry.manifests.map do |manifest|
|
|
24
|
+
where(
|
|
25
|
+
participatory_space_type: manifest.model_class_name,
|
|
26
|
+
participatory_space_id: manifest.participatory_spaces.call(organization).reselect(:id)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
conditions.reduce(:or) || none
|
|
31
|
+
}
|
|
22
32
|
|
|
23
33
|
default_scope { registered_component_manifests.registered_space_manifests.order(arel_table[:weight].asc, arel_table[:manifest_name].asc) }
|
|
24
34
|
|
data/app/models/decidim/like.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Decidim
|
|
|
12
12
|
validates :resource_id, uniqueness: { scope: [:resource_type, :author] }
|
|
13
13
|
validate :author_and_resource_same_organization
|
|
14
14
|
|
|
15
|
-
scope :for_listing, -> { order(:
|
|
15
|
+
scope :for_listing, -> { order(:created_at, :id) }
|
|
16
16
|
|
|
17
17
|
private
|
|
18
18
|
|
|
@@ -18,6 +18,7 @@ module Decidim
|
|
|
18
18
|
:organization_logo,
|
|
19
19
|
file_size: { less_than_or_equal_to: ->(record) { record.maximum_upload_size } },
|
|
20
20
|
uploader_content_type: true,
|
|
21
|
+
uploader_image_content: true,
|
|
21
22
|
uploader_image_dimensions: true
|
|
22
23
|
)
|
|
23
24
|
attached_config[:organization_logo] = OpenStruct.new(uploader: OAuthApplicationLogoUploader)
|
data/app/models/decidim/user.rb
CHANGED
|
@@ -32,6 +32,7 @@ module Decidim
|
|
|
32
32
|
has_many :access_tokens, class_name: "Doorkeeper::AccessToken", foreign_key: :resource_owner_id, dependent: :destroy
|
|
33
33
|
has_many :reminders, foreign_key: "decidim_user_id", class_name: "Decidim::Reminder", dependent: :destroy
|
|
34
34
|
has_many :private_exports, class_name: "Decidim::PrivateExport", dependent: :destroy, inverse_of: :attached_to, as: :attached_to
|
|
35
|
+
has_many :impersonation_logs, foreign_key: "decidim_user_id", class_name: "Decidim::ImpersonationLog", dependent: :destroy
|
|
35
36
|
|
|
36
37
|
validates :name, presence: true, unless: -> { deleted? }
|
|
37
38
|
validates :nickname,
|
|
@@ -62,7 +62,7 @@ module Decidim
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def users_followings
|
|
65
|
-
@users_followings ||= Decidim::UserBaseEntity.joins(:follows).where(decidim_follows: { user: self })
|
|
65
|
+
@users_followings ||= Decidim::UserBaseEntity.joins(:follows).where(decidim_follows: { user: self }).order(decidim_follows: { created_at: :asc, id: :asc })
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def followings_blocked?
|
|
@@ -19,3 +19,13 @@ document.addEventListener("turbo:load", () => {
|
|
|
19
19
|
callout.innerHTML += " ";
|
|
20
20
|
}, 500);
|
|
21
21
|
});
|
|
22
|
+
|
|
23
|
+
document.addEventListener("click", (event) => {
|
|
24
|
+
const closeButton = event.target.closest("[data-alert-box] [data-close]");
|
|
25
|
+
|
|
26
|
+
if (!closeButton) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
closeButton.closest("[data-alert-box]").remove();
|
|
31
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "src/decidim/callout"
|
|
2
|
+
|
|
3
|
+
describe("callout close button", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
document.body.innerHTML = `
|
|
6
|
+
<div id="flash-messages-container">
|
|
7
|
+
<div class="flash success" data-alert-box role="alert" aria-atomic="true">
|
|
8
|
+
<div class="flash__message">Signed in successfully.</div>
|
|
9
|
+
<button type="button" class="close-button" data-close aria-label="Dismiss">×</button>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
`;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("removes the alert box when the close button is clicked", () => {
|
|
16
|
+
const closeButton = document.querySelector("[data-close]");
|
|
17
|
+
|
|
18
|
+
expect(document.querySelector("[data-alert-box]")).not.toBeNull();
|
|
19
|
+
|
|
20
|
+
closeButton.click();
|
|
21
|
+
|
|
22
|
+
expect(document.querySelector("[data-alert-box]")).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("does nothing when clicking outside of the close button", () => {
|
|
26
|
+
const message = document.querySelector(".flash__message");
|
|
27
|
+
|
|
28
|
+
message.click();
|
|
29
|
+
|
|
30
|
+
expect(document.querySelector("[data-alert-box]")).not.toBeNull();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint max-lines: ["error", 350] */
|
|
1
2
|
/* global jest */
|
|
2
3
|
|
|
3
4
|
import AccordionController from "src/decidim/controllers/accordion/controller";
|
|
@@ -99,6 +100,69 @@ describe("AccordionController", () => {
|
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
102
|
|
|
103
|
+
describe("_setupInertPanels", () => {
|
|
104
|
+
const nextTick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
105
|
+
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
panel1.setAttribute("inert", "");
|
|
108
|
+
panel1.setAttribute("aria-hidden", "true");
|
|
109
|
+
panel1.setAttribute("tabindex", "-1");
|
|
110
|
+
panel2.setAttribute("aria-hidden", "true");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("only manages panels with the inert attribute", async () => {
|
|
114
|
+
controller._setupInertPanels();
|
|
115
|
+
expect(controller._panelObservers.length).toBe(1);
|
|
116
|
+
|
|
117
|
+
panel2.setAttribute("aria-hidden", "false");
|
|
118
|
+
await nextTick();
|
|
119
|
+
expect(panel2.hasAttribute("inert")).toBe(false);
|
|
120
|
+
expect("inertManaged" in panel2.dataset).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("removes inert and moves focus to the panel when it gets expanded", async () => {
|
|
124
|
+
controller._setupInertPanels();
|
|
125
|
+
|
|
126
|
+
panel1.setAttribute("aria-hidden", "false");
|
|
127
|
+
await nextTick();
|
|
128
|
+
expect(panel1.hasAttribute("inert")).toBe(false);
|
|
129
|
+
expect(document.activeElement).toBe(panel1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("restores inert when the panel gets collapsed again", async () => {
|
|
133
|
+
controller._setupInertPanels();
|
|
134
|
+
|
|
135
|
+
panel1.setAttribute("aria-hidden", "false");
|
|
136
|
+
await nextTick();
|
|
137
|
+
panel1.setAttribute("aria-hidden", "true");
|
|
138
|
+
await nextTick();
|
|
139
|
+
expect(panel1.hasAttribute("inert")).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("keeps managing an expanded panel across teardown and setup", async () => {
|
|
143
|
+
controller._setupInertPanels();
|
|
144
|
+
|
|
145
|
+
panel1.setAttribute("aria-hidden", "false");
|
|
146
|
+
await nextTick();
|
|
147
|
+
controller._teardownInertPanels();
|
|
148
|
+
|
|
149
|
+
panel1.setAttribute("aria-hidden", "true");
|
|
150
|
+
controller._setupInertPanels();
|
|
151
|
+
expect(controller._panelObservers.length).toBe(1);
|
|
152
|
+
expect(panel1.hasAttribute("inert")).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("stops syncing after teardown", async () => {
|
|
156
|
+
controller._setupInertPanels();
|
|
157
|
+
controller._teardownInertPanels();
|
|
158
|
+
expect(controller._panelObservers.length).toBe(0);
|
|
159
|
+
|
|
160
|
+
panel1.setAttribute("aria-hidden", "false");
|
|
161
|
+
await nextTick();
|
|
162
|
+
expect(panel1.hasAttribute("inert")).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
102
166
|
describe("_applyBreakpointOpenAttributes", () => {
|
|
103
167
|
beforeEach(() => {
|
|
104
168
|
controller.initialize();
|