decidim-core 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/config/decidim_core_manifest.js +5 -0
- data/app/assets/javascripts/decidim.js.es6 +2 -0
- data/app/assets/javascripts/decidim/ajax_modals.js.es6 +3 -3
- data/app/assets/javascripts/decidim/confirm.js.es6 +3 -2
- data/app/assets/javascripts/decidim/core/bundle.js +1 -1
- data/app/assets/javascripts/decidim/core/bundle.js.map +1 -1
- data/app/assets/javascripts/decidim/diff_mode_dropdown.js.es6 +18 -4
- data/app/assets/javascripts/decidim/editor.js.es6 +3 -3
- data/app/assets/javascripts/decidim/geocoding.js.es6 +60 -0
- data/app/assets/javascripts/decidim/geocoding/attach_input.js.es6 +106 -0
- data/app/assets/javascripts/decidim/geocoding/format_address.js.es6 +29 -0
- data/app/assets/javascripts/decidim/geocoding/provider/here.js.es6 +107 -0
- data/app/assets/javascripts/decidim/geocoding/provider/photon.js.es6 +77 -0
- data/app/assets/javascripts/decidim/map.js.es6 +34 -124
- data/app/assets/javascripts/decidim/map/controller.js.es6 +92 -0
- data/app/assets/javascripts/decidim/map/controller/markers.js.es6 +65 -0
- data/app/assets/javascripts/decidim/map/controller/static.es6 +48 -0
- data/app/assets/javascripts/decidim/map/factory.js.es6 +51 -0
- data/app/assets/javascripts/decidim/map/icon.js.es6 +31 -0
- data/app/assets/javascripts/decidim/map/legacy.js.es6 +87 -0
- data/app/assets/javascripts/decidim/map/provider/default.js.es6 +22 -0
- data/app/assets/javascripts/decidim/map/provider/here.js.es6 +22 -0
- data/app/assets/javascripts/decidim/security/selfxss_warning.js.es6 +19 -0
- data/app/assets/stylesheets/decidim/_decidim.scss +2 -0
- data/app/assets/stylesheets/decidim/modules/_cards.scss +15 -0
- data/app/assets/stylesheets/decidim/modules/_forms.scss +14 -0
- data/app/assets/stylesheets/decidim/modules/_layout.scss +11 -3
- data/app/assets/stylesheets/decidim/modules/_map.scss +35 -0
- data/app/assets/stylesheets/decidim/modules/_progress-bar.scss +4 -0
- data/app/assets/stylesheets/decidim/modules/_reveal.scss +5 -0
- data/app/assets/stylesheets/decidim/modules/_status-labels.scss +2 -1
- data/app/cells/decidim/author/flag.erb +1 -1
- data/app/cells/decidim/author/profile_inline.erb +2 -2
- data/app/cells/decidim/author_cell.rb +5 -2
- data/app/cells/decidim/card_cell.rb +21 -7
- data/app/cells/decidim/card_m/show.erb +1 -1
- data/app/cells/decidim/card_m_cell.rb +6 -4
- data/app/cells/decidim/collapsible_authors_cell.rb +1 -1
- data/app/cells/decidim/diff/diff_mode_html.erb +5 -5
- data/app/cells/decidim/follow_button/show.erb +6 -6
- data/app/cells/decidim/follow_button_cell.rb +8 -0
- data/app/cells/decidim/progress_bar/show.erb +11 -4
- data/app/cells/decidim/progress_bar_cell.rb +20 -1
- data/app/cells/decidim/translation_bar/show.erb +6 -0
- data/app/cells/decidim/translation_bar_cell.rb +52 -0
- data/app/cells/decidim/version_cell.rb +1 -1
- data/app/cells/decidim/versions_list_cell.rb +1 -1
- data/app/commands/decidim/amendable/accept.rb +9 -3
- data/app/commands/decidim/amendable/create_draft.rb +2 -0
- data/app/commands/decidim/amendable/update_draft.rb +2 -0
- data/app/commands/decidim/attachment_methods.rb +12 -5
- data/app/commands/decidim/destroy_account.rb +1 -0
- data/app/commands/decidim/gallery_methods.rb +16 -9
- data/app/commands/decidim/messaging/reply_to_conversation.rb +1 -1
- data/app/commands/decidim/multiple_attachments_methods.rb +56 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +1 -0
- data/app/controllers/concerns/decidim/filter_resource.rb +24 -6
- data/app/controllers/concerns/decidim/flaggable.rb +20 -0
- data/app/controllers/concerns/decidim/force_authentication.rb +1 -0
- data/app/controllers/concerns/decidim/impersonate_users.rb +1 -1
- data/app/controllers/concerns/decidim/needs_snippets.rb +20 -0
- data/app/controllers/concerns/decidim/paginable.rb +5 -1
- data/app/controllers/concerns/decidim/withdrawable.rb +20 -0
- data/app/controllers/decidim/application_controller.rb +16 -0
- data/app/controllers/decidim/components/base_controller.rb +6 -1
- data/app/controllers/decidim/cookie_policy_controller.rb +6 -3
- data/app/controllers/decidim/messaging/conversations_controller.rb +5 -2
- data/app/forms/decidim/account_form.rb +5 -1
- data/app/forms/decidim/amendable/create_form.rb +1 -1
- data/app/forms/decidim/amendable/form.rb +44 -3
- data/app/forms/decidim/attachment_form.rb +5 -1
- data/app/forms/decidim/user_group_form.rb +5 -1
- data/app/helpers/decidim/cells_helper.rb +3 -15
- data/app/helpers/decidim/check_boxes_tree_helper.rb +21 -12
- data/app/helpers/decidim/cookies_helper.rb +1 -1
- data/app/helpers/decidim/decidim_form_helper.rb +1 -1
- data/app/helpers/decidim/filter_params_helper.rb +30 -0
- data/app/helpers/decidim/map_helper.rb +86 -23
- data/app/helpers/decidim/orders_helper.rb +6 -1
- data/app/helpers/decidim/paginate_helper.rb +3 -1
- data/app/helpers/decidim/scopes_helper.rb +4 -4
- data/app/helpers/decidim/translations_helper.rb +7 -1
- data/app/jobs/decidim/machine_translation_fields_job.rb +30 -0
- data/app/jobs/decidim/machine_translation_resource_job.rb +113 -0
- data/app/jobs/decidim/machine_translation_save_job.rb +33 -0
- data/app/mailers/decidim/reported_mailer.rb +8 -1
- data/app/models/decidim/action_log.rb +1 -1
- data/app/models/decidim/area.rb +3 -0
- data/app/models/decidim/area_type.rb +4 -0
- data/app/models/decidim/attachment.rb +30 -2
- data/app/models/decidim/attachment_collection.rb +3 -0
- data/app/models/decidim/authorization.rb +3 -0
- data/app/models/decidim/category.rb +4 -0
- data/app/models/decidim/component.rb +7 -0
- data/app/models/decidim/content_block.rb +11 -1
- data/app/models/decidim/contextual_help_section.rb +4 -0
- data/app/models/decidim/follow.rb +3 -1
- data/app/models/decidim/messaging/message.rb +1 -1
- data/app/models/decidim/moderation.rb +1 -1
- data/app/models/decidim/newsletter.rb +3 -0
- data/app/models/decidim/oauth_application.rb +2 -0
- data/app/models/decidim/organization.rb +53 -9
- data/app/models/decidim/scope.rb +4 -1
- data/app/models/decidim/scope_type.rb +3 -0
- data/app/models/decidim/share_token.rb +49 -0
- data/app/models/decidim/static_page.rb +4 -1
- data/app/models/decidim/static_page_topic.rb +3 -0
- data/app/models/decidim/user_base_entity.rb +6 -2
- data/app/permissions/decidim/permissions.rb +9 -0
- data/app/presenters/decidim/log/base_presenter.rb +1 -1
- data/app/presenters/decidim/log/value_types/default_presenter.rb +1 -1
- data/app/presenters/decidim/official_author_presenter.rb +36 -0
- data/app/presenters/decidim/resource_locator_presenter.rb +63 -12
- data/app/queries/decidim/similar_emendations.rb +4 -4
- data/app/scrubbers/decidim/user_input_scrubber.rb +1 -1
- data/app/serializers/decidim/importers/participatory_space_components_importer.rb +1 -1
- data/app/services/decidim/base_diff_renderer.rb +17 -0
- data/app/services/decidim/open_data_exporter.rb +2 -0
- data/app/services/decidim/resource_search.rb +95 -6
- data/app/services/decidim/static_map_generator.rb +10 -26
- data/app/uploaders/decidim/application_uploader.rb +15 -1
- data/app/uploaders/decidim/attachment_uploader.rb +23 -17
- data/app/uploaders/decidim/banner_image_uploader.rb +1 -1
- data/app/uploaders/decidim/hero_image_uploader.rb +1 -1
- data/app/uploaders/decidim/homepage_image_uploader.rb +1 -1
- data/app/uploaders/decidim/image_uploader.rb +6 -2
- data/app/uploaders/decidim/oauth_application_logo_uploader.rb +1 -1
- data/app/uploaders/decidim/official_image_footer_uploader.rb +1 -1
- data/app/uploaders/decidim/official_image_header_uploader.rb +1 -1
- data/app/uploaders/decidim/organization_logo_uploader.rb +1 -1
- data/app/uploaders/decidim/record_image_uploader.rb +15 -0
- data/app/validators/etiquette_validator.rb +0 -7
- data/app/validators/geocoding_validator.rb +9 -4
- data/app/validators/passthru_validator.rb +111 -0
- data/app/validators/scope_belongs_to_component_validator.rb +16 -0
- data/app/validators/uploader_content_type_validator.rb +44 -0
- data/app/views/decidim/authorization_modals/_content.html.erb +2 -2
- data/app/views/decidim/devise/registrations/new.html.erb +3 -1
- data/app/views/decidim/devise/sessions/new.html.erb +3 -1
- data/app/views/decidim/messaging/conversations/_error_modal.html.erb +21 -0
- data/app/views/decidim/messaging/conversations/error.js.erb +10 -0
- data/app/views/decidim/notification_mailer/event_received.html.erb +2 -2
- data/app/views/decidim/reported_mailer/report.html.erb +49 -3
- data/app/views/decidim/scopes/_scopes_picker_input.html.erb +15 -14
- data/app/views/decidim/searches/_filters.html.erb +1 -0
- data/app/views/decidim/shared/_login_modal.html.erb +14 -3
- data/app/views/decidim/shared/_static_map.html.erb +1 -1
- data/app/views/layouts/decidim/_head.html.erb +2 -0
- data/app/views/layouts/decidim/_js_configuration.html.erb +7 -1
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +3 -4
- data/config/locales/bg.yml +1508 -0
- data/config/locales/ca.yml +35 -8
- data/config/locales/cs.yml +34 -7
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +23 -4
- data/config/locales/el.yml +0 -4
- data/config/locales/en.yml +30 -3
- data/config/locales/eo.yml +92 -0
- data/config/locales/es-MX.yml +28 -1
- data/config/locales/es-PY.yml +28 -1
- data/config/locales/es.yml +44 -17
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +3 -4
- data/config/locales/fi-plain.yml +28 -1
- data/config/locales/fi.yml +29 -2
- data/config/locales/fr-CA.yml +32 -4
- data/config/locales/fr.yml +61 -33
- data/config/locales/ga-IE.yml +0 -8
- data/config/locales/gl.yml +3 -4
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +7 -4
- data/config/locales/id-ID.yml +3 -4
- data/config/locales/is-IS.yml +3 -9
- data/config/locales/is.yml +463 -0
- data/config/locales/it.yml +36 -8
- data/config/locales/ja-JP.yml +25 -16
- data/config/locales/ja.yml +1605 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/{lv-LV.yml → lv.yml} +0 -4
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +25 -3
- data/config/locales/no.yml +133 -6
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +88 -71
- data/config/locales/pt-BR.yml +3 -4
- data/config/locales/pt.yml +10 -4
- data/config/locales/ro-RO.yml +10 -4
- data/config/locales/ru.yml +3 -10
- data/config/locales/sk.yml +3 -4
- data/config/locales/sl.yml +8 -7
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +0 -7
- data/config/locales/sv.yml +17 -6
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +3 -4
- data/config/locales/uk.yml +3 -11
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +1584 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20200525184143_add_enable_machine_translation_to_decidim_organizations.rb +7 -0
- data/db/migrate/20200702073419_create_decidim_share_tokens.rb +16 -0
- data/db/migrate/20200707132401_add_comments_max_length_to_decidim_organization.rb +7 -0
- data/db/migrate/20200730142511_add_file_upload_settings_to_decidim_organizations.rb +36 -0
- data/db/migrate/20200806092109_add_machine_translation_display_priority_to_organizations.rb +17 -0
- data/db/migrate/20201004160335_remove_notifications_with_continuity_badge.rb +9 -0
- data/db/seeds.rb +5 -4
- data/lib/decidim/authorable.rb +22 -1
- data/lib/decidim/authorization_form_builder.rb +7 -0
- data/lib/decidim/coauthorable.rb +22 -0
- data/lib/decidim/component_manifest.rb +1 -1
- data/lib/decidim/content_processor.rb +52 -29
- data/lib/decidim/content_renderers/base_renderer.rb +1 -1
- data/lib/decidim/content_renderers/hashtag_renderer.rb +2 -0
- data/lib/decidim/content_renderers/link_renderer.rb +4 -1
- data/lib/decidim/content_renderers/user_group_renderer.rb +3 -1
- data/lib/decidim/content_renderers/user_renderer.rb +3 -1
- data/lib/decidim/core.rb +67 -12
- data/lib/decidim/core/engine.rb +60 -21
- data/lib/decidim/core/test.rb +6 -0
- data/lib/decidim/core/test/factories.rb +34 -8
- data/lib/decidim/core/test/shared_examples/amendable/accept_amendment_examples.rb +4 -4
- data/lib/decidim/core/test/shared_examples/amendable_proposals_interface_examples.rb +8 -8
- data/lib/decidim/core/test/shared_examples/comments_examples.rb +52 -1
- data/lib/decidim/core/test/shared_examples/embed_resource_examples.rb +49 -0
- data/lib/decidim/core/test/shared_examples/follows_examples.rb +3 -3
- data/lib/decidim/core/test/shared_examples/manage_component_share_tokens.rb +83 -0
- data/lib/decidim/core/test/shared_examples/map_examples.rb +186 -0
- data/lib/decidim/core/test/shared_examples/preview_component_with_share_token_examples.rb +55 -0
- data/lib/decidim/core/test/shared_examples/resource_search_examples.rb +200 -0
- data/lib/decidim/core/test/shared_examples/scopable_resource_examples.rb +43 -0
- data/lib/decidim/core/test/shared_examples/scope_helper_examples.rb +12 -1
- data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +15 -2
- data/lib/decidim/core/test/shared_examples/simple_event.rb +7 -0
- data/lib/decidim/core/test/shared_examples/system_endorse_resource_examples.rb +1 -0
- data/lib/decidim/core/test/shared_examples/traceable_interface_examples.rb +1 -1
- data/lib/decidim/core/test/shared_examples/uncommentable_component_examples.rb +1 -1
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/diffy_extension.rb +21 -0
- data/lib/decidim/events/base_event.rb +11 -9
- data/lib/decidim/exporters.rb +7 -0
- data/lib/decidim/exporters/csv.rb +15 -1
- data/lib/decidim/exporters/excel.rb +1 -1
- data/lib/decidim/exporters/export_manifest.rb +29 -0
- data/lib/decidim/exporters/pdf.rb +56 -0
- data/lib/decidim/file_validator_humanizer.rb +98 -0
- data/lib/decidim/form_builder.rb +65 -54
- data/lib/decidim/geocodable.rb +79 -0
- data/lib/decidim/has_attachments.rb +10 -0
- data/lib/decidim/has_upload_validations.rb +36 -0
- data/lib/decidim/map.rb +214 -0
- data/lib/decidim/map/autocomplete.rb +67 -0
- data/lib/decidim/map/dynamic_map.rb +89 -0
- data/lib/decidim/map/frontend.rb +97 -0
- data/lib/decidim/map/geocoding.rb +115 -0
- data/lib/decidim/map/provider.rb +12 -0
- data/lib/decidim/map/provider/autocomplete/here.rb +20 -0
- data/lib/decidim/map/provider/autocomplete/osm.rb +20 -0
- data/lib/decidim/map/provider/dynamic_map/here.rb +51 -0
- data/lib/decidim/map/provider/dynamic_map/osm.rb +13 -0
- data/lib/decidim/map/provider/geocoding/here.rb +58 -0
- data/lib/decidim/map/provider/geocoding/osm.rb +30 -0
- data/lib/decidim/map/provider/here.rb +21 -0
- data/lib/decidim/map/provider/osm.rb +22 -0
- data/lib/decidim/map/provider/static_map/here.rb +35 -0
- data/lib/decidim/map/provider/static_map/osm.rb +29 -0
- data/lib/decidim/map/static_map.rb +133 -0
- data/lib/decidim/map/utility.rb +38 -0
- data/lib/decidim/organization_settings.rb +267 -0
- data/lib/decidim/resource_manifest.rb +1 -1
- data/lib/decidim/scopable.rb +9 -6
- data/lib/decidim/scopable_component.rb +29 -1
- data/lib/decidim/scopable_participatory_space.rb +19 -0
- data/lib/decidim/scopable_resource.rb +21 -0
- data/lib/decidim/search_resource_fields_mapper.rb +15 -2
- data/lib/decidim/searchable.rb +4 -0
- data/lib/decidim/settings_manifest.rb +2 -1
- data/lib/decidim/shareable_with_token.rb +27 -0
- data/lib/decidim/snippets.rb +30 -0
- data/lib/decidim/translatable_attributes.rb +42 -4
- data/lib/decidim/translatable_resource.rb +78 -0
- data/lib/decidim/view_model.rb +1 -0
- data/lib/tasks/decidim_locales_tasks.rake +35 -0
- data/lib/tasks/decidim_tasks.rake +1 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.bg.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.da.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.eo.js +17 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.et.js +18 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr-CA.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ga.js +15 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.hr.js +13 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.is.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ja.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lt.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lv.js +17 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.mt.js +15 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sl.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sr.js +16 -0
- metadata +138 -26
- data/app/helpers/decidim/multi_translation_helper.rb +0 -0
- data/lib/decidim/hashtaggable.rb +0 -24
@@ -10,6 +10,9 @@ module Decidim
|
|
10
10
|
class StaticPage < ApplicationRecord
|
11
11
|
include Decidim::Traceable
|
12
12
|
include Decidim::Loggable
|
13
|
+
include Decidim::TranslatableResource
|
14
|
+
|
15
|
+
translatable_fields :title, :content
|
13
16
|
|
14
17
|
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization", inverse_of: :static_pages
|
15
18
|
belongs_to :topic, foreign_key: "topic_id", class_name: "Decidim::StaticPageTopic", optional: true
|
@@ -19,7 +22,7 @@ module Decidim
|
|
19
22
|
|
20
23
|
# These pages will be created by default when registering an organization
|
21
24
|
# and cannot be deleted.
|
22
|
-
DEFAULT_PAGES = %w(
|
25
|
+
DEFAULT_PAGES = %w(terms-and-conditions).freeze
|
23
26
|
|
24
27
|
after_create :update_organization_tos_version
|
25
28
|
before_destroy :can_be_destroyed?
|
@@ -11,15 +11,19 @@ module Decidim
|
|
11
11
|
include Resourceable
|
12
12
|
include Decidim::Followable
|
13
13
|
include Decidim::Loggable
|
14
|
+
include Decidim::HasUploadValidations
|
14
15
|
|
15
16
|
belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
|
16
17
|
has_many :notifications, foreign_key: "decidim_user_id", class_name: "Decidim::Notification", dependent: :destroy
|
17
18
|
has_many :following_follows, foreign_key: "decidim_user_id", class_name: "Decidim::Follow", dependent: :destroy
|
18
19
|
|
19
|
-
|
20
|
+
# Regex for name & nickname format validations
|
21
|
+
REGEXP_NAME = /\A(?!.*[<>?%&\^*#@\(\)\[\]\=\+\:\;\"\{\}\\\|])/.freeze
|
22
|
+
|
23
|
+
validates_avatar
|
20
24
|
mount_uploader :avatar, Decidim::AvatarUploader
|
21
25
|
|
22
|
-
validates :name, :nickname, format: { with:
|
26
|
+
validates :name, :nickname, format: { with: REGEXP_NAME }
|
23
27
|
|
24
28
|
# Public: Returns a collection with all the entities this user is following.
|
25
29
|
#
|
@@ -46,6 +46,7 @@ module Decidim
|
|
46
46
|
permission_action.action == :read
|
47
47
|
|
48
48
|
return allow! if component.published?
|
49
|
+
return allow! if user_can_preview_component?
|
49
50
|
return allow! if user_can_admin_component?
|
50
51
|
return allow! if user_can_admin_component_via_space?
|
51
52
|
|
@@ -152,6 +153,14 @@ module Decidim
|
|
152
153
|
allow! if permission_action.subject == :user_group_invitations
|
153
154
|
end
|
154
155
|
|
156
|
+
def user_can_preview_component?
|
157
|
+
return allow! if context[:share_token].present? && Decidim::ShareToken.use!(token_for: component, token: context[:share_token])
|
158
|
+
rescue ActiveRecord::RecordNotFound
|
159
|
+
nil
|
160
|
+
rescue StandardError
|
161
|
+
nil
|
162
|
+
end
|
163
|
+
|
155
164
|
def user_can_admin_component?
|
156
165
|
new_permission_action = Decidim::PermissionAction.new(
|
157
166
|
action: permission_action.action,
|
@@ -16,7 +16,7 @@ module Decidim
|
|
16
16
|
#
|
17
17
|
# Check the other presenters in this folder for more examples.
|
18
18
|
class DefaultPresenter
|
19
|
-
# value - the
|
19
|
+
# value - the value to render, can be of any type.
|
20
20
|
# view_helpers - an object encapsulating all the view helpers,
|
21
21
|
# it will most likely come from the top of the chain.
|
22
22
|
def initialize(value, view_helpers)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
#
|
5
|
+
# A dummy presenter to abstract out the author of an official resource.
|
6
|
+
#
|
7
|
+
class OfficialAuthorPresenter
|
8
|
+
def nickname
|
9
|
+
""
|
10
|
+
end
|
11
|
+
|
12
|
+
def badge
|
13
|
+
""
|
14
|
+
end
|
15
|
+
|
16
|
+
def profile_path
|
17
|
+
""
|
18
|
+
end
|
19
|
+
|
20
|
+
def avatar_url
|
21
|
+
ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
|
22
|
+
end
|
23
|
+
|
24
|
+
def deleted?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def can_be_contacted?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_tooltip?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
# A presenter to get the url or path from a resource.
|
5
|
+
# resource - a record or array of nested records.
|
5
6
|
class ResourceLocatorPresenter
|
6
7
|
def initialize(resource)
|
7
8
|
@resource = resource
|
@@ -26,7 +27,7 @@ module Decidim
|
|
26
27
|
#
|
27
28
|
# Returns a String.
|
28
29
|
def url(options = {})
|
29
|
-
member_route("url", options.merge(host:
|
30
|
+
member_route("url", options.merge(host: root_resource.organization.host))
|
30
31
|
end
|
31
32
|
|
32
33
|
# Builds the index path to the associated collection of resources.
|
@@ -53,7 +54,9 @@ module Decidim
|
|
53
54
|
#
|
54
55
|
# Returns a String.
|
55
56
|
def show(options = {})
|
56
|
-
|
57
|
+
options.merge!(options_for_polymorphic)
|
58
|
+
|
59
|
+
admin_route_proxy.send("#{member_route_name}_path", target, options)
|
57
60
|
end
|
58
61
|
|
59
62
|
# Builds the admin edit path to the resource.
|
@@ -62,53 +65,101 @@ module Decidim
|
|
62
65
|
#
|
63
66
|
# Returns a String.
|
64
67
|
def edit(options = {})
|
65
|
-
|
68
|
+
options.merge!(options_for_polymorphic)
|
69
|
+
|
70
|
+
admin_route_proxy.send("edit_#{member_route_name}_path", target, options)
|
66
71
|
end
|
67
72
|
|
68
73
|
private
|
69
74
|
|
75
|
+
def polymorphic?
|
76
|
+
resource.is_a? Array
|
77
|
+
end
|
78
|
+
|
79
|
+
def target
|
80
|
+
if polymorphic?
|
81
|
+
resource.last
|
82
|
+
else
|
83
|
+
resource
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def root_resource
|
88
|
+
if polymorphic?
|
89
|
+
resource.first
|
90
|
+
else
|
91
|
+
resource
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
70
95
|
# Private: Build the route to the resource.
|
71
96
|
#
|
72
97
|
# Returns a String.
|
73
98
|
def member_route(route_type, options)
|
74
|
-
|
99
|
+
options.merge!(options_for_polymorphic)
|
100
|
+
|
101
|
+
route_proxy.send("#{member_route_name}_#{route_type}", target, options)
|
75
102
|
end
|
76
103
|
|
77
104
|
# Private: Build the route to the associated collection of resources.
|
78
105
|
#
|
79
106
|
# Returns a String.
|
80
107
|
def collection_route(route_type, options)
|
108
|
+
options.merge!(options_for_polymorphic)
|
109
|
+
|
81
110
|
route_proxy.send("#{collection_route_name}_#{route_type}", options)
|
82
111
|
end
|
83
112
|
|
84
113
|
def admin_collection_route(route_type, options)
|
114
|
+
options.merge!(options_for_polymorphic)
|
115
|
+
|
85
116
|
admin_route_proxy.send("#{collection_route_name}_#{route_type}", options)
|
86
117
|
end
|
87
118
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
119
|
+
def manifest_for(record)
|
120
|
+
record.try(:resource_manifest) ||
|
121
|
+
record.class.try(:resource_manifest) ||
|
122
|
+
record.class.try(:participatory_space_manifest)
|
92
123
|
end
|
93
124
|
|
94
125
|
def component
|
95
|
-
|
126
|
+
root_resource.try(:component)
|
96
127
|
end
|
97
128
|
|
98
129
|
def member_route_name
|
99
|
-
|
130
|
+
if polymorphic?
|
131
|
+
polymorphic_member_route_name
|
132
|
+
else
|
133
|
+
manifest_for(target).route_name
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def polymorphic_member_route_name
|
138
|
+
return unless polymorphic?
|
139
|
+
|
140
|
+
resource.map { |record| manifest_for(record).route_name }.join("_")
|
100
141
|
end
|
101
142
|
|
102
143
|
def collection_route_name
|
103
144
|
member_route_name.pluralize
|
104
145
|
end
|
105
146
|
|
147
|
+
def options_for_polymorphic
|
148
|
+
return {} unless polymorphic?
|
149
|
+
|
150
|
+
parent_resources = {}
|
151
|
+
(resource - [target]).each do |parent|
|
152
|
+
parent_resources["#{manifest_for(parent).route_name}_id"] = parent.id
|
153
|
+
end
|
154
|
+
parent_resources
|
155
|
+
end
|
156
|
+
|
106
157
|
def route_proxy
|
107
|
-
@route_proxy ||= EngineRouter.main_proxy(component ||
|
158
|
+
@route_proxy ||= EngineRouter.main_proxy(component || target)
|
108
159
|
end
|
109
160
|
|
110
161
|
def admin_route_proxy
|
111
|
-
@admin_route_proxy ||= EngineRouter.admin_proxy(component ||
|
162
|
+
@admin_route_proxy ||= EngineRouter.admin_proxy(component || target)
|
112
163
|
end
|
113
164
|
end
|
114
165
|
end
|
@@ -30,8 +30,8 @@ module Decidim
|
|
30
30
|
.not_hidden
|
31
31
|
.where(
|
32
32
|
"GREATEST(#{title_similarity}, #{body_similarity}) >= ?",
|
33
|
-
emendation.title,
|
34
|
-
emendation.body,
|
33
|
+
translated_attribute(emendation.title),
|
34
|
+
translated_attribute(emendation.body),
|
35
35
|
amendable_module.similarity_threshold
|
36
36
|
)
|
37
37
|
.limit(amendable_module.similarity_limit)
|
@@ -46,11 +46,11 @@ module Decidim
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def title_similarity
|
49
|
-
"similarity(title, ?)"
|
49
|
+
"similarity(title::text, ?)"
|
50
50
|
end
|
51
51
|
|
52
52
|
def body_similarity
|
53
|
-
"similarity(body, ?)"
|
53
|
+
"similarity(body::text, ?)"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -21,7 +21,7 @@ module Decidim
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def custom_allowed_attributes
|
24
|
-
Loofah::HTML5::SafeList::ALLOWED_ATTRIBUTES + %w(frameborder allowfullscreen)
|
24
|
+
Loofah::HTML5::SafeList::ALLOWED_ATTRIBUTES + %w(frameborder allowfullscreen) - %w(onerror)
|
25
25
|
end
|
26
26
|
|
27
27
|
def custom_allowed_tags
|
@@ -64,7 +64,7 @@ module Decidim
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def override_step_settings_ids(attributes, step_settings)
|
67
|
-
return
|
67
|
+
return unless @participatory_space.has_steps? && step_settings.present?
|
68
68
|
|
69
69
|
@participatory_space.steps.each do |step|
|
70
70
|
old_id = attributes["settings"]["steps"].keys.first
|
@@ -59,6 +59,22 @@ module Decidim
|
|
59
59
|
diff
|
60
60
|
end
|
61
61
|
|
62
|
+
def parse_user_group_changeset(attribute, values, type, diff)
|
63
|
+
return unless diff
|
64
|
+
|
65
|
+
old_user_group = Decidim::UserGroup.find_by(id: values[0])
|
66
|
+
new_user_group = Decidim::UserGroup.find_by(id: values[1])
|
67
|
+
|
68
|
+
diff.update(
|
69
|
+
attribute => {
|
70
|
+
type: type,
|
71
|
+
label: I18n.t(attribute, scope: i18n_scope),
|
72
|
+
old_value: old_user_group ? translated_attribute(old_user_group.name) : "",
|
73
|
+
new_value: new_user_group ? translated_attribute(new_user_group.name) : ""
|
74
|
+
}
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
62
78
|
def parse_scope_changeset(attribute, values, type, diff)
|
63
79
|
return unless diff
|
64
80
|
|
@@ -79,6 +95,7 @@ module Decidim
|
|
79
95
|
return parse_i18n_changeset(attribute, values, type, diff) if [:i18n, :i18n_html].include?(type)
|
80
96
|
|
81
97
|
return parse_scope_changeset(attribute, values, type, diff) if type == :scope
|
98
|
+
return parse_user_group_changeset(attribute, values, type, diff) if type == :user_group
|
82
99
|
|
83
100
|
diff.update(
|
84
101
|
attribute => {
|
@@ -4,6 +4,8 @@ module Decidim
|
|
4
4
|
# This is the base class to be used by other search services.
|
5
5
|
# Searchlight documentation: https://github.com/nathanl/searchlight
|
6
6
|
class ResourceSearch < Searchlight::Search
|
7
|
+
attr_reader :user, :organization, :component
|
8
|
+
|
7
9
|
# Initialize the Searchlight::Search base class with the options provided.
|
8
10
|
#
|
9
11
|
# scope - The scope used to create the base query
|
@@ -13,6 +15,31 @@ module Decidim
|
|
13
15
|
def initialize(scope, options = {})
|
14
16
|
super(options)
|
15
17
|
@scope = scope
|
18
|
+
@user = options[:current_user] || options[:user]
|
19
|
+
@component = options[:component]
|
20
|
+
@organization = options[:organization] || component&.organization
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Companion method to `search_search_text` which defines the
|
24
|
+
# attributes where we should search for text values in a model.
|
25
|
+
def self.text_search_fields(*fields)
|
26
|
+
@text_search_fields = fields if fields.any?
|
27
|
+
@text_search_fields
|
28
|
+
end
|
29
|
+
|
30
|
+
# Handle the search_text filter. We have to cast the JSONB columns
|
31
|
+
# into a `text` type so that we can search.
|
32
|
+
def search_search_text
|
33
|
+
return query unless self.class.text_search_fields.any?
|
34
|
+
|
35
|
+
fields = self.class.text_search_fields.dup
|
36
|
+
|
37
|
+
text_query = query.where(localized_search_text_in("#{query.model_name.plural}.#{fields.shift}"), text: "%#{search_text}%")
|
38
|
+
|
39
|
+
fields.each do |field|
|
40
|
+
text_query = text_query.or(query.where(localized_search_text_in("#{query.model_name.plural}.#{field}"), text: "%#{search_text}%"))
|
41
|
+
end
|
42
|
+
text_query
|
16
43
|
end
|
17
44
|
|
18
45
|
# Creates the SearchLight base query.
|
@@ -51,8 +78,65 @@ module Decidim
|
|
51
78
|
query.includes(:scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
|
52
79
|
end
|
53
80
|
|
81
|
+
# Handle the origin filter.
|
82
|
+
def search_origin
|
83
|
+
renamed_origin = Array(origin).map do |search_value|
|
84
|
+
"#{search_value}_origin"
|
85
|
+
end
|
86
|
+
apply_scopes(%w(official_origin citizens_origin user_group_origin meeting_origin), renamed_origin)
|
87
|
+
end
|
88
|
+
|
89
|
+
# We overwrite the `results` method to ensure we only return unique
|
90
|
+
# results. We can't use `#uniq` because it returns an Array and we're
|
91
|
+
# adding scopes in the controller, and `#distinct` doesn't work here
|
92
|
+
# because in the later scopes we're ordering by `RANDOM()` in a DB level,
|
93
|
+
# and `SELECT DISTINCT` doesn't work with `RANDOM()` sorting, so we need
|
94
|
+
# to perform two queries.
|
95
|
+
#
|
96
|
+
# The correct behaviour is backed by tests.
|
97
|
+
def results
|
98
|
+
base_query.model.where(id: super.pluck(:id))
|
99
|
+
end
|
100
|
+
|
54
101
|
private
|
55
102
|
|
103
|
+
# Private: To be used by classes that inherit from ResourceSearch.
|
104
|
+
#
|
105
|
+
# This method is useful when the values of the filters match the names of
|
106
|
+
# defined scopes in a model, it applies those scopes that are included in
|
107
|
+
# the search values.
|
108
|
+
#
|
109
|
+
# Example:
|
110
|
+
# Consider you want to filter by state, and your model has an `open` and
|
111
|
+
# a `closed` ActiveRecord scope.
|
112
|
+
#
|
113
|
+
# def search_state
|
114
|
+
# apply_scopes(%w(open closed), state)
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# In this scenario, the `state` variable has the input by the use, who
|
118
|
+
# has selected which states they want to see. `states` here is an array
|
119
|
+
# of strings.
|
120
|
+
#
|
121
|
+
# Returns an ActiveRecord::Relation.
|
122
|
+
def apply_scopes(scopes, search_values)
|
123
|
+
search_values = Array(search_values)
|
124
|
+
|
125
|
+
conditions = scopes.map do |scope|
|
126
|
+
search_values.member?(scope.to_s) ? query.try(scope) : nil
|
127
|
+
end.compact
|
128
|
+
|
129
|
+
return query unless conditions.any?
|
130
|
+
|
131
|
+
scoped_query = query.where(id: conditions.shift)
|
132
|
+
|
133
|
+
conditions.each do |condition|
|
134
|
+
scoped_query = scoped_query.or(query.where(id: condition))
|
135
|
+
end
|
136
|
+
|
137
|
+
scoped_query
|
138
|
+
end
|
139
|
+
|
56
140
|
# Private: Creates an array of category ids.
|
57
141
|
# It contains categories' subcategories ids as well.
|
58
142
|
def all_category_ids
|
@@ -67,7 +151,7 @@ module Decidim
|
|
67
151
|
|
68
152
|
# Private: Returns an array with checked category ids.
|
69
153
|
def category_ids
|
70
|
-
|
154
|
+
Array(category_id)
|
71
155
|
end
|
72
156
|
|
73
157
|
# Private: Returns an array with checked scope ids.
|
@@ -75,14 +159,19 @@ module Decidim
|
|
75
159
|
if scope_id.is_a?(Hash)
|
76
160
|
scope_id.values
|
77
161
|
else
|
78
|
-
|
162
|
+
Array(scope_id)
|
79
163
|
end
|
80
164
|
end
|
81
165
|
|
82
|
-
#
|
83
|
-
# to
|
84
|
-
|
85
|
-
|
166
|
+
# Internal: builds the needed query to search for a text in the organization's
|
167
|
+
# available locales. Note that it is intended to be used as follows:
|
168
|
+
#
|
169
|
+
# Example:
|
170
|
+
# Resource.where(localized_search_text_for(:title, text: "my_query"))
|
171
|
+
#
|
172
|
+
# The Hash with the `:text` key is required or it won't work.
|
173
|
+
def localized_search_text_in(field)
|
174
|
+
organization.available_locales.map { |l| "#{field} ->> '#{l}' ILIKE :text" }.join(" OR ")
|
86
175
|
end
|
87
176
|
end
|
88
177
|
end
|