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
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Map
|
5
|
+
# A module to contain map functionality specific to the OpenStreetMap (OSM)
|
6
|
+
# based map providers.
|
7
|
+
module Provider
|
8
|
+
module Autocomplete
|
9
|
+
autoload :Osm, "decidim/map/provider/autocomplete/osm"
|
10
|
+
end
|
11
|
+
module Geocoding
|
12
|
+
autoload :Osm, "decidim/map/provider/geocoding/osm"
|
13
|
+
end
|
14
|
+
module DynamicMap
|
15
|
+
autoload :Osm, "decidim/map/provider/dynamic_map/osm"
|
16
|
+
end
|
17
|
+
module StaticMap
|
18
|
+
autoload :Osm, "decidim/map/provider/static_map/osm"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Map
|
5
|
+
module Provider
|
6
|
+
module StaticMap
|
7
|
+
# The static map utility class for the HERE maps service
|
8
|
+
class Here < ::Decidim::Map::StaticMap
|
9
|
+
# @See Decidim::Map::StaticMap#url_params
|
10
|
+
def url_params(latitude:, longitude:, options: {})
|
11
|
+
params = {
|
12
|
+
c: "#{latitude}, #{longitude}",
|
13
|
+
z: options[:zoom] || 15,
|
14
|
+
w: options[:width] || 120,
|
15
|
+
h: options[:height] || 120,
|
16
|
+
f: 1
|
17
|
+
}
|
18
|
+
|
19
|
+
api_key = configuration[:api_key]
|
20
|
+
if api_key.is_a?(Array)
|
21
|
+
# Legacy way of configuring the API credentials
|
22
|
+
params[:app_id] = api_key[0]
|
23
|
+
params[:app_code] = api_key[1]
|
24
|
+
else
|
25
|
+
# The new way of configuring the API key
|
26
|
+
params[:apiKey] = api_key
|
27
|
+
end
|
28
|
+
|
29
|
+
params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Map
|
5
|
+
module Provider
|
6
|
+
module StaticMap
|
7
|
+
# The static map utility class for the OpenStreetMap based map services
|
8
|
+
class Osm < ::Decidim::Map::StaticMap
|
9
|
+
# @See Decidim::Map::StaticMap#url_params
|
10
|
+
def url_params(latitude:, longitude:, options: {})
|
11
|
+
# This is the format used by osm-static-maps which is not an
|
12
|
+
# official OSM product but it should be rather easy to setup. For
|
13
|
+
# further information, see:
|
14
|
+
# https://github.com/jperelli/osm-static-maps
|
15
|
+
{
|
16
|
+
geojson: {
|
17
|
+
type: "Point",
|
18
|
+
coordinates: [longitude, latitude]
|
19
|
+
}.to_json,
|
20
|
+
zoom: options[:zoom] || 15,
|
21
|
+
width: options[:width] || 120,
|
22
|
+
height: options[:height] || 120
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Map
|
5
|
+
# A base class for static mapping functionality, common to all static map
|
6
|
+
# services.
|
7
|
+
class StaticMap < Map::Utility
|
8
|
+
# Creates a link for the static maps. This will point to an external map
|
9
|
+
# service where the user can further explore the given location.
|
10
|
+
#
|
11
|
+
# @param params [Hash] The parameters for the static map URL
|
12
|
+
# @option params [Float, String] :latitude The latitude of the map
|
13
|
+
# position to be linked to
|
14
|
+
# @option params [Float, String] :longitude The longitude of the map
|
15
|
+
# position to be linked to
|
16
|
+
# @option params [Hash] :options Extra options that can be provided to the
|
17
|
+
# map URL containing the following keys:
|
18
|
+
# * zoom: A number to represent the zoom value of the map (default 17)
|
19
|
+
#
|
20
|
+
# @return [String] The link where the static map images link to.
|
21
|
+
def link(latitude:, longitude:, options: {})
|
22
|
+
zoom = options.fetch(:zoom, 17)
|
23
|
+
base_url = configuration.fetch(
|
24
|
+
:link,
|
25
|
+
"https://www.openstreetmap.org/"
|
26
|
+
)
|
27
|
+
|
28
|
+
params = { mlat: latitude, mlon: longitude }
|
29
|
+
fragment = "map=#{zoom}/#{latitude}/#{longitude}"
|
30
|
+
|
31
|
+
URI.parse(base_url).tap do |uri|
|
32
|
+
uri.query = URI.encode_www_form(params)
|
33
|
+
uri.fragment = fragment
|
34
|
+
end.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creates a URL that generates a static map image for the given map
|
38
|
+
# location with the given options.
|
39
|
+
#
|
40
|
+
# @param params [Hash] The parameters for the static map URL
|
41
|
+
# @option params [Float, String] :latitude The latitude of the map
|
42
|
+
# position
|
43
|
+
# @option params [Float, String] :longitude The longitude of the map
|
44
|
+
# position
|
45
|
+
# @option params [Hash] :options Extra options that can be provided to
|
46
|
+
# the underlying map service to generate the image with containing the
|
47
|
+
# following keys:
|
48
|
+
# * zoom: A number to represent the zoom value of the map image (default
|
49
|
+
# 15)
|
50
|
+
# * width: A number to represent the pixel width of the map image
|
51
|
+
# (default 120)
|
52
|
+
# * height: A number to represent the pixel height of the map image
|
53
|
+
# (default 120)
|
54
|
+
#
|
55
|
+
# @return [String] The URL to request for the static map image.
|
56
|
+
def url(latitude:, longitude:, options: {})
|
57
|
+
map_url = configuration.fetch(:url, nil)
|
58
|
+
return unless map_url
|
59
|
+
|
60
|
+
# If a lambda or proc is passed as the :static_map_url configuration.
|
61
|
+
if map_url.respond_to?(:call)
|
62
|
+
return map_url.call(
|
63
|
+
latitude: latitude,
|
64
|
+
longitude: longitude,
|
65
|
+
options: options
|
66
|
+
).to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
# Fetch the "extra" parameters from the configured map URL
|
70
|
+
configured_uri = URI.parse(map_url)
|
71
|
+
configured_params = Rack::Utils.parse_nested_query(
|
72
|
+
configured_uri.query
|
73
|
+
).symbolize_keys
|
74
|
+
|
75
|
+
# Generate a base URL without the URL parameters
|
76
|
+
configured_uri.query = nil
|
77
|
+
configured_uri.fragment = nil
|
78
|
+
base_url = configured_uri.to_s
|
79
|
+
|
80
|
+
# Generate the actual parameters by combining the configured parameters
|
81
|
+
# with the provider specific parameters, giving priority to the
|
82
|
+
# dynamically set parameters.
|
83
|
+
params = configured_params.merge(
|
84
|
+
url_params(
|
85
|
+
latitude: latitude,
|
86
|
+
longitude: longitude,
|
87
|
+
options: options
|
88
|
+
)
|
89
|
+
)
|
90
|
+
|
91
|
+
# Generate the actual URL to call with all the prepared parameters.
|
92
|
+
URI.parse(base_url).tap do |uri|
|
93
|
+
uri.query = URI.encode_www_form(params)
|
94
|
+
end.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
# Prepares the URL params for the static map URL.
|
98
|
+
#
|
99
|
+
# @param (see #url)
|
100
|
+
#
|
101
|
+
# @return [Hash] The parameters to pass to the static map image URL.
|
102
|
+
def url_params(latitude:, longitude:, options: {})
|
103
|
+
{
|
104
|
+
latitude: latitude,
|
105
|
+
longitude: longitude,
|
106
|
+
zoom: options.fetch(:zoom, 15),
|
107
|
+
width: options.fetch(:width, 120),
|
108
|
+
height: options.fetch(:height, 120)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
# Creates a static map image data for the given map location with the
|
113
|
+
# given options.
|
114
|
+
#
|
115
|
+
# @param (see #url)
|
116
|
+
#
|
117
|
+
# @return [String] The raw data for the image.
|
118
|
+
def image_data(latitude:, longitude:, options: {})
|
119
|
+
request_url = url(
|
120
|
+
latitude: latitude,
|
121
|
+
longitude: longitude,
|
122
|
+
options: options
|
123
|
+
)
|
124
|
+
return "" unless request_url
|
125
|
+
|
126
|
+
response = Faraday.get(request_url) do |req|
|
127
|
+
req.headers["Referer"] = organization.host
|
128
|
+
end
|
129
|
+
response.body
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Map
|
5
|
+
# Generic map utility that will be used for providing different map
|
6
|
+
# functionality to the application.
|
7
|
+
#
|
8
|
+
# @abstract
|
9
|
+
class Utility
|
10
|
+
attr_reader :organization, :configuration, :locale
|
11
|
+
|
12
|
+
# Initializes the map utility.
|
13
|
+
#
|
14
|
+
# @param options [Hash] The options for the map utility
|
15
|
+
# @option options [Decidim::Organization] :organization The organization
|
16
|
+
# where the map functionality is used
|
17
|
+
# @option options [String] :config The configuration hash specific to the
|
18
|
+
# utility
|
19
|
+
# @option options [String] :locale The locale to use for the queries
|
20
|
+
def initialize(organization:, config:, locale: I18n.locale.to_s)
|
21
|
+
@organization = organization
|
22
|
+
@locale = locale
|
23
|
+
configure!(config)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
# Sets the local configurations for the utility.
|
29
|
+
#
|
30
|
+
# @param config [Hash] The whole configuration hash.
|
31
|
+
#
|
32
|
+
# @return [Hash] The configuration hash.
|
33
|
+
def configure!(config)
|
34
|
+
@configuration = config
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
#
|
5
|
+
# Takes care of holding and accessing organization settings for each
|
6
|
+
# organization or the default organization.
|
7
|
+
#
|
8
|
+
class OrganizationSettings < OpenStruct
|
9
|
+
class << self
|
10
|
+
# Fetches or creates a settings object for the given organization.
|
11
|
+
#
|
12
|
+
# @param organization [Decidim::Organization] The organization in
|
13
|
+
# question.
|
14
|
+
# @return [Decidim::OrganizationSettings] The settings object.
|
15
|
+
def for(organization)
|
16
|
+
# Before the organization has an ID attached to it, it cannot be stored
|
17
|
+
# to the registry.
|
18
|
+
return new(organization) if organization.new_record?
|
19
|
+
|
20
|
+
@registry ||= {}
|
21
|
+
@registry[organization.id] ||= new(organization)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Reloads the settings object for a given organization. Should be called
|
25
|
+
# when the configurations have changed and need to be reloaded.
|
26
|
+
#
|
27
|
+
# @param organization [Decidim::Organization] The organization in question.
|
28
|
+
# @return [Decidim::OrganizationSettings] The settings object.
|
29
|
+
def reload(organization)
|
30
|
+
@registry.delete(organization.id) if @registry
|
31
|
+
self.for(organization)
|
32
|
+
end
|
33
|
+
|
34
|
+
# The settings should be reset during the tests in order for the new tests
|
35
|
+
# to always load the latest settings. The results of the previous tests
|
36
|
+
# should not affect the settings of the following test.
|
37
|
+
def reset!
|
38
|
+
@registry = {}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the default configuration value for the given setting key chain.
|
42
|
+
#
|
43
|
+
# For example:
|
44
|
+
#
|
45
|
+
# Decidim::OrganizationSettings.default(:upload, :maximum_file_size, :default)
|
46
|
+
# #=> 10
|
47
|
+
#
|
48
|
+
# Note: this cannot fetch the default settings from the class instance
|
49
|
+
# variable "defaults" because that would cause an infinite loop.
|
50
|
+
#
|
51
|
+
# @param *chain [Symbol, String] The configuration key(s) to dig into
|
52
|
+
# inside the default configurations hash.
|
53
|
+
# @return The value found from the default configurations hash.
|
54
|
+
def default(*chain)
|
55
|
+
return if chain.blank?
|
56
|
+
|
57
|
+
configs = defaults_hash
|
58
|
+
while (lookup = chain.shift)
|
59
|
+
configs = configs[lookup.to_s]
|
60
|
+
return configs if chain.empty?
|
61
|
+
return unless configs.is_a?(Hash)
|
62
|
+
end
|
63
|
+
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# This is a class level helper to get a "dummy" default settings object
|
68
|
+
# that responds to the same methods as the normal organization specific
|
69
|
+
# settings objects. This allows for the following kind of syntactic sugar:
|
70
|
+
#
|
71
|
+
# settings = Decidim::OrganizationSettings.for(actual_org)
|
72
|
+
# settings.target_config_accessor #=> returns the organization setting
|
73
|
+
#
|
74
|
+
# settings = Decidim::OrganizationSettings.defaults
|
75
|
+
# settings.target_config_accessor #=> returns the default setting
|
76
|
+
#
|
77
|
+
# This can be used through the Decidim module as follows:
|
78
|
+
#
|
79
|
+
# Decidim.organization_settings(org).target_config_accessor
|
80
|
+
# #=> returns the organization specific setting
|
81
|
+
#
|
82
|
+
# Decidim.organization_settings(model_beloging_to_org).target_config_accessor
|
83
|
+
# #=> returns the organization specific setting for model's organization
|
84
|
+
#
|
85
|
+
# Decidim.organization_settings(nil).target_config_accessor
|
86
|
+
# #=> returns the default setting
|
87
|
+
#
|
88
|
+
# @return [Decidim::OrganizationSettings] The default settings object.
|
89
|
+
def defaults
|
90
|
+
@defaults ||= new(OpenStruct.new)
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
# Stores the default settings hash which is used to create the settings
|
96
|
+
# objects. This will provide all the missing configuration values for the
|
97
|
+
# final object if it does not define some of the values.
|
98
|
+
#
|
99
|
+
# Note: This cannot be stored in a class variable because it would change
|
100
|
+
# the arrays into comma separated strings.
|
101
|
+
#
|
102
|
+
# @return [Hash] The default settings hash.
|
103
|
+
def defaults_hash
|
104
|
+
{
|
105
|
+
"upload" => {
|
106
|
+
"allowed_file_extensions" => {
|
107
|
+
"default" => %w(jpg jpeg gif png bmp pdf rtf txt),
|
108
|
+
"admin" => %w(jpg jpeg gif png bmp pdf doc docx xls xlsx ppt ppx rtf txt odt ott odf otg ods ots),
|
109
|
+
"image" => %w(jpg jpeg gif png bmp ico)
|
110
|
+
},
|
111
|
+
"allowed_content_types" => {
|
112
|
+
"default" => %w(
|
113
|
+
image/*
|
114
|
+
application/pdf
|
115
|
+
application/rtf
|
116
|
+
text/plain
|
117
|
+
),
|
118
|
+
"admin" => %w(
|
119
|
+
image/*
|
120
|
+
application/vnd.oasis.opendocument
|
121
|
+
application/vnd.ms-*
|
122
|
+
application/msword
|
123
|
+
application/vnd.ms-word
|
124
|
+
application/vnd.openxmlformats-officedocument
|
125
|
+
application/vnd.oasis.opendocument
|
126
|
+
application/pdf
|
127
|
+
application/rtf
|
128
|
+
text/plain
|
129
|
+
)
|
130
|
+
},
|
131
|
+
"maximum_file_size" => {
|
132
|
+
"default" => 10,
|
133
|
+
"avatar" => 5
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def initialize(organization)
|
141
|
+
# This maps the local configuration top level keys to the methods/column
|
142
|
+
# names in the organization model that provide the values for these
|
143
|
+
# settings.
|
144
|
+
keys_map = { upload: :file_upload_settings }
|
145
|
+
|
146
|
+
# Pass a configuration hash to the parent constructor that combines the
|
147
|
+
# default settings with the organization level settings. This ensures that
|
148
|
+
# all configurations have values even when the organization settings do
|
149
|
+
# not define them.
|
150
|
+
super(
|
151
|
+
keys_map.map do |config, method|
|
152
|
+
[
|
153
|
+
config.to_s,
|
154
|
+
generate_config(
|
155
|
+
organization.public_send(method) || {},
|
156
|
+
self.class.default(config)
|
157
|
+
)
|
158
|
+
]
|
159
|
+
end.to_h
|
160
|
+
)
|
161
|
+
|
162
|
+
keys_map.keys.each do |config|
|
163
|
+
define_config_accessors(public_send(config), [config])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def wrap_upload_maximum_file_size(value)
|
168
|
+
value.megabytes
|
169
|
+
end
|
170
|
+
|
171
|
+
def wrap_upload_maximum_file_size_avatar(value)
|
172
|
+
value.megabytes
|
173
|
+
end
|
174
|
+
|
175
|
+
def wrap_upload_allowed_content_types(value)
|
176
|
+
content_type_array(value)
|
177
|
+
end
|
178
|
+
|
179
|
+
def wrap_upload_allowed_content_types_admin(value)
|
180
|
+
content_type_array(value)
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
# Generates a final settigns configuration struct from the given settings
|
186
|
+
# hash. Combines the given defaults with the settings hash.
|
187
|
+
#
|
188
|
+
# @param hash [Hash] The configurations hash.
|
189
|
+
# @param default [Hash] The default configurations.
|
190
|
+
# @return [OpenStruct] The configuration struct.
|
191
|
+
def generate_config(hash, default = {})
|
192
|
+
OpenStruct.new(
|
193
|
+
default.deep_merge(hash).map do |key, value|
|
194
|
+
value = generate_config(value) if value.is_a?(Hash)
|
195
|
+
[key, value]
|
196
|
+
end.to_h
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Turns the stars into wildcard regular expression matches in the matching
|
201
|
+
# strings.
|
202
|
+
#
|
203
|
+
# @param [Array<String>] An array of glob strings to match against.
|
204
|
+
# @return [Array<Regexp>] An array of regular expressions to match against.
|
205
|
+
def content_type_array(types)
|
206
|
+
types.map do |match_string|
|
207
|
+
Regexp.new(Regexp.escape(match_string).gsub("\\*", ".*?"))
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# This defines all the config accessors for the configuration parameters
|
212
|
+
# that can be directly called for the settings instance without having to
|
213
|
+
# "drill down" to the child structs. For example, if the whole settings
|
214
|
+
# object was initialized with the following hash:
|
215
|
+
#
|
216
|
+
# {
|
217
|
+
# "upload" => {
|
218
|
+
# "allowed_file_extensions" => {
|
219
|
+
# "default" => %w(jpg jpeg),
|
220
|
+
# "admin" => %w(jpg jpeg gif png)
|
221
|
+
# }
|
222
|
+
# },
|
223
|
+
# "another_thing" => {
|
224
|
+
# "bleep" => "bloop",
|
225
|
+
# "foo" => {
|
226
|
+
# "bar" => 1
|
227
|
+
# "baz" => 2
|
228
|
+
# }
|
229
|
+
# }
|
230
|
+
# }
|
231
|
+
#
|
232
|
+
# This would automatically generate the following methods in the settings
|
233
|
+
# instance:
|
234
|
+
#
|
235
|
+
# - upload_allowed_file_extensions #=> ["jpg", "jpeg"]
|
236
|
+
# - upload_allowed_file_extensions_admin #=> ["jpg", "jpeg", "gif", "png"]
|
237
|
+
# - another_thing_bleep #=> "bloop"
|
238
|
+
# - another_thing_foo_bar #=> 1
|
239
|
+
# - another_thing_foo_baz #=> 2
|
240
|
+
#
|
241
|
+
# Note that when the deepest configuration hash has the key "default", it
|
242
|
+
# will not be appended to the method name.
|
243
|
+
#
|
244
|
+
# @param obj [Decidim::OrganizationSettings, OpenStruct] The settings object
|
245
|
+
# for which to define the accessors.
|
246
|
+
# @param chain [Array<Symbol>] The current lookup chain for the settings
|
247
|
+
# object. Needed when called recursively.
|
248
|
+
def define_config_accessors(obj, chain)
|
249
|
+
obj.each_pair do |key, val|
|
250
|
+
if val.is_a?(OpenStruct)
|
251
|
+
define_config_accessors(val, [*chain, key])
|
252
|
+
else
|
253
|
+
prefix = chain.join("_")
|
254
|
+
method = prefix
|
255
|
+
method = "#{method}_#{key}" unless key.to_sym == :default
|
256
|
+
|
257
|
+
define_singleton_method(method) do
|
258
|
+
value = dig(*chain, key)
|
259
|
+
return value unless respond_to?("wrap_#{method}")
|
260
|
+
|
261
|
+
public_send("wrap_#{method}", value)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|