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.

Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_core_manifest.js +5 -0
  3. data/app/assets/javascripts/decidim.js.es6 +2 -0
  4. data/app/assets/javascripts/decidim/ajax_modals.js.es6 +3 -3
  5. data/app/assets/javascripts/decidim/confirm.js.es6 +3 -2
  6. data/app/assets/javascripts/decidim/core/bundle.js +1 -1
  7. data/app/assets/javascripts/decidim/core/bundle.js.map +1 -1
  8. data/app/assets/javascripts/decidim/diff_mode_dropdown.js.es6 +18 -4
  9. data/app/assets/javascripts/decidim/editor.js.es6 +3 -3
  10. data/app/assets/javascripts/decidim/geocoding.js.es6 +60 -0
  11. data/app/assets/javascripts/decidim/geocoding/attach_input.js.es6 +106 -0
  12. data/app/assets/javascripts/decidim/geocoding/format_address.js.es6 +29 -0
  13. data/app/assets/javascripts/decidim/geocoding/provider/here.js.es6 +107 -0
  14. data/app/assets/javascripts/decidim/geocoding/provider/photon.js.es6 +77 -0
  15. data/app/assets/javascripts/decidim/map.js.es6 +34 -124
  16. data/app/assets/javascripts/decidim/map/controller.js.es6 +92 -0
  17. data/app/assets/javascripts/decidim/map/controller/markers.js.es6 +65 -0
  18. data/app/assets/javascripts/decidim/map/controller/static.es6 +48 -0
  19. data/app/assets/javascripts/decidim/map/factory.js.es6 +51 -0
  20. data/app/assets/javascripts/decidim/map/icon.js.es6 +31 -0
  21. data/app/assets/javascripts/decidim/map/legacy.js.es6 +87 -0
  22. data/app/assets/javascripts/decidim/map/provider/default.js.es6 +22 -0
  23. data/app/assets/javascripts/decidim/map/provider/here.js.es6 +22 -0
  24. data/app/assets/javascripts/decidim/security/selfxss_warning.js.es6 +19 -0
  25. data/app/assets/stylesheets/decidim/_decidim.scss +2 -0
  26. data/app/assets/stylesheets/decidim/modules/_cards.scss +15 -0
  27. data/app/assets/stylesheets/decidim/modules/_forms.scss +14 -0
  28. data/app/assets/stylesheets/decidim/modules/_layout.scss +11 -3
  29. data/app/assets/stylesheets/decidim/modules/_map.scss +35 -0
  30. data/app/assets/stylesheets/decidim/modules/_progress-bar.scss +4 -0
  31. data/app/assets/stylesheets/decidim/modules/_reveal.scss +5 -0
  32. data/app/assets/stylesheets/decidim/modules/_status-labels.scss +2 -1
  33. data/app/cells/decidim/author/flag.erb +1 -1
  34. data/app/cells/decidim/author/profile_inline.erb +2 -2
  35. data/app/cells/decidim/author_cell.rb +5 -2
  36. data/app/cells/decidim/card_cell.rb +21 -7
  37. data/app/cells/decidim/card_m/show.erb +1 -1
  38. data/app/cells/decidim/card_m_cell.rb +6 -4
  39. data/app/cells/decidim/collapsible_authors_cell.rb +1 -1
  40. data/app/cells/decidim/diff/diff_mode_html.erb +5 -5
  41. data/app/cells/decidim/follow_button/show.erb +6 -6
  42. data/app/cells/decidim/follow_button_cell.rb +8 -0
  43. data/app/cells/decidim/progress_bar/show.erb +11 -4
  44. data/app/cells/decidim/progress_bar_cell.rb +20 -1
  45. data/app/cells/decidim/translation_bar/show.erb +6 -0
  46. data/app/cells/decidim/translation_bar_cell.rb +52 -0
  47. data/app/cells/decidim/version_cell.rb +1 -1
  48. data/app/cells/decidim/versions_list_cell.rb +1 -1
  49. data/app/commands/decidim/amendable/accept.rb +9 -3
  50. data/app/commands/decidim/amendable/create_draft.rb +2 -0
  51. data/app/commands/decidim/amendable/update_draft.rb +2 -0
  52. data/app/commands/decidim/attachment_methods.rb +12 -5
  53. data/app/commands/decidim/destroy_account.rb +1 -0
  54. data/app/commands/decidim/gallery_methods.rb +16 -9
  55. data/app/commands/decidim/messaging/reply_to_conversation.rb +1 -1
  56. data/app/commands/decidim/multiple_attachments_methods.rb +56 -0
  57. data/app/controllers/concerns/decidim/devise_controllers.rb +1 -0
  58. data/app/controllers/concerns/decidim/filter_resource.rb +24 -6
  59. data/app/controllers/concerns/decidim/flaggable.rb +20 -0
  60. data/app/controllers/concerns/decidim/force_authentication.rb +1 -0
  61. data/app/controllers/concerns/decidim/impersonate_users.rb +1 -1
  62. data/app/controllers/concerns/decidim/needs_snippets.rb +20 -0
  63. data/app/controllers/concerns/decidim/paginable.rb +5 -1
  64. data/app/controllers/concerns/decidim/withdrawable.rb +20 -0
  65. data/app/controllers/decidim/application_controller.rb +16 -0
  66. data/app/controllers/decidim/components/base_controller.rb +6 -1
  67. data/app/controllers/decidim/cookie_policy_controller.rb +6 -3
  68. data/app/controllers/decidim/messaging/conversations_controller.rb +5 -2
  69. data/app/forms/decidim/account_form.rb +5 -1
  70. data/app/forms/decidim/amendable/create_form.rb +1 -1
  71. data/app/forms/decidim/amendable/form.rb +44 -3
  72. data/app/forms/decidim/attachment_form.rb +5 -1
  73. data/app/forms/decidim/user_group_form.rb +5 -1
  74. data/app/helpers/decidim/cells_helper.rb +3 -15
  75. data/app/helpers/decidim/check_boxes_tree_helper.rb +21 -12
  76. data/app/helpers/decidim/cookies_helper.rb +1 -1
  77. data/app/helpers/decidim/decidim_form_helper.rb +1 -1
  78. data/app/helpers/decidim/filter_params_helper.rb +30 -0
  79. data/app/helpers/decidim/map_helper.rb +86 -23
  80. data/app/helpers/decidim/orders_helper.rb +6 -1
  81. data/app/helpers/decidim/paginate_helper.rb +3 -1
  82. data/app/helpers/decidim/scopes_helper.rb +4 -4
  83. data/app/helpers/decidim/translations_helper.rb +7 -1
  84. data/app/jobs/decidim/machine_translation_fields_job.rb +30 -0
  85. data/app/jobs/decidim/machine_translation_resource_job.rb +113 -0
  86. data/app/jobs/decidim/machine_translation_save_job.rb +33 -0
  87. data/app/mailers/decidim/reported_mailer.rb +8 -1
  88. data/app/models/decidim/action_log.rb +1 -1
  89. data/app/models/decidim/area.rb +3 -0
  90. data/app/models/decidim/area_type.rb +4 -0
  91. data/app/models/decidim/attachment.rb +30 -2
  92. data/app/models/decidim/attachment_collection.rb +3 -0
  93. data/app/models/decidim/authorization.rb +3 -0
  94. data/app/models/decidim/category.rb +4 -0
  95. data/app/models/decidim/component.rb +7 -0
  96. data/app/models/decidim/content_block.rb +11 -1
  97. data/app/models/decidim/contextual_help_section.rb +4 -0
  98. data/app/models/decidim/follow.rb +3 -1
  99. data/app/models/decidim/messaging/message.rb +1 -1
  100. data/app/models/decidim/moderation.rb +1 -1
  101. data/app/models/decidim/newsletter.rb +3 -0
  102. data/app/models/decidim/oauth_application.rb +2 -0
  103. data/app/models/decidim/organization.rb +53 -9
  104. data/app/models/decidim/scope.rb +4 -1
  105. data/app/models/decidim/scope_type.rb +3 -0
  106. data/app/models/decidim/share_token.rb +49 -0
  107. data/app/models/decidim/static_page.rb +4 -1
  108. data/app/models/decidim/static_page_topic.rb +3 -0
  109. data/app/models/decidim/user_base_entity.rb +6 -2
  110. data/app/permissions/decidim/permissions.rb +9 -0
  111. data/app/presenters/decidim/log/base_presenter.rb +1 -1
  112. data/app/presenters/decidim/log/value_types/default_presenter.rb +1 -1
  113. data/app/presenters/decidim/official_author_presenter.rb +36 -0
  114. data/app/presenters/decidim/resource_locator_presenter.rb +63 -12
  115. data/app/queries/decidim/similar_emendations.rb +4 -4
  116. data/app/scrubbers/decidim/user_input_scrubber.rb +1 -1
  117. data/app/serializers/decidim/importers/participatory_space_components_importer.rb +1 -1
  118. data/app/services/decidim/base_diff_renderer.rb +17 -0
  119. data/app/services/decidim/open_data_exporter.rb +2 -0
  120. data/app/services/decidim/resource_search.rb +95 -6
  121. data/app/services/decidim/static_map_generator.rb +10 -26
  122. data/app/uploaders/decidim/application_uploader.rb +15 -1
  123. data/app/uploaders/decidim/attachment_uploader.rb +23 -17
  124. data/app/uploaders/decidim/banner_image_uploader.rb +1 -1
  125. data/app/uploaders/decidim/hero_image_uploader.rb +1 -1
  126. data/app/uploaders/decidim/homepage_image_uploader.rb +1 -1
  127. data/app/uploaders/decidim/image_uploader.rb +6 -2
  128. data/app/uploaders/decidim/oauth_application_logo_uploader.rb +1 -1
  129. data/app/uploaders/decidim/official_image_footer_uploader.rb +1 -1
  130. data/app/uploaders/decidim/official_image_header_uploader.rb +1 -1
  131. data/app/uploaders/decidim/organization_logo_uploader.rb +1 -1
  132. data/app/uploaders/decidim/record_image_uploader.rb +15 -0
  133. data/app/validators/etiquette_validator.rb +0 -7
  134. data/app/validators/geocoding_validator.rb +9 -4
  135. data/app/validators/passthru_validator.rb +111 -0
  136. data/app/validators/scope_belongs_to_component_validator.rb +16 -0
  137. data/app/validators/uploader_content_type_validator.rb +44 -0
  138. data/app/views/decidim/authorization_modals/_content.html.erb +2 -2
  139. data/app/views/decidim/devise/registrations/new.html.erb +3 -1
  140. data/app/views/decidim/devise/sessions/new.html.erb +3 -1
  141. data/app/views/decidim/messaging/conversations/_error_modal.html.erb +21 -0
  142. data/app/views/decidim/messaging/conversations/error.js.erb +10 -0
  143. data/app/views/decidim/notification_mailer/event_received.html.erb +2 -2
  144. data/app/views/decidim/reported_mailer/report.html.erb +49 -3
  145. data/app/views/decidim/scopes/_scopes_picker_input.html.erb +15 -14
  146. data/app/views/decidim/searches/_filters.html.erb +1 -0
  147. data/app/views/decidim/shared/_login_modal.html.erb +14 -3
  148. data/app/views/decidim/shared/_static_map.html.erb +1 -1
  149. data/app/views/layouts/decidim/_head.html.erb +2 -0
  150. data/app/views/layouts/decidim/_js_configuration.html.erb +7 -1
  151. data/config/locales/am-ET.yml +1 -0
  152. data/config/locales/ar.yml +3 -4
  153. data/config/locales/bg.yml +1508 -0
  154. data/config/locales/ca.yml +35 -8
  155. data/config/locales/cs.yml +34 -7
  156. data/config/locales/da.yml +1 -0
  157. data/config/locales/de.yml +23 -4
  158. data/config/locales/el.yml +0 -4
  159. data/config/locales/en.yml +30 -3
  160. data/config/locales/eo.yml +92 -0
  161. data/config/locales/es-MX.yml +28 -1
  162. data/config/locales/es-PY.yml +28 -1
  163. data/config/locales/es.yml +44 -17
  164. data/config/locales/et.yml +1 -0
  165. data/config/locales/eu.yml +3 -4
  166. data/config/locales/fi-plain.yml +28 -1
  167. data/config/locales/fi.yml +29 -2
  168. data/config/locales/fr-CA.yml +32 -4
  169. data/config/locales/fr.yml +61 -33
  170. data/config/locales/ga-IE.yml +0 -8
  171. data/config/locales/gl.yml +3 -4
  172. data/config/locales/hr.yml +1 -0
  173. data/config/locales/hu.yml +7 -4
  174. data/config/locales/id-ID.yml +3 -4
  175. data/config/locales/is-IS.yml +3 -9
  176. data/config/locales/is.yml +463 -0
  177. data/config/locales/it.yml +36 -8
  178. data/config/locales/ja-JP.yml +25 -16
  179. data/config/locales/ja.yml +1605 -0
  180. data/config/locales/ko-KR.yml +1 -0
  181. data/config/locales/ko.yml +1 -0
  182. data/config/locales/lt.yml +1 -0
  183. data/config/locales/{lv-LV.yml → lv.yml} +0 -4
  184. data/config/locales/mt.yml +1 -0
  185. data/config/locales/nl.yml +25 -3
  186. data/config/locales/no.yml +133 -6
  187. data/config/locales/om-ET.yml +1 -0
  188. data/config/locales/pl.yml +88 -71
  189. data/config/locales/pt-BR.yml +3 -4
  190. data/config/locales/pt.yml +10 -4
  191. data/config/locales/ro-RO.yml +10 -4
  192. data/config/locales/ru.yml +3 -10
  193. data/config/locales/sk.yml +3 -4
  194. data/config/locales/sl.yml +8 -7
  195. data/config/locales/so-SO.yml +1 -0
  196. data/config/locales/sr-CS.yml +0 -7
  197. data/config/locales/sv.yml +17 -6
  198. data/config/locales/ti-ER.yml +1 -0
  199. data/config/locales/tr-TR.yml +3 -4
  200. data/config/locales/uk.yml +3 -11
  201. data/config/locales/vi-VN.yml +1 -0
  202. data/config/locales/vi.yml +1 -0
  203. data/config/locales/zh-CN.yml +1584 -0
  204. data/config/locales/zh-TW.yml +1 -0
  205. data/db/migrate/20200525184143_add_enable_machine_translation_to_decidim_organizations.rb +7 -0
  206. data/db/migrate/20200702073419_create_decidim_share_tokens.rb +16 -0
  207. data/db/migrate/20200707132401_add_comments_max_length_to_decidim_organization.rb +7 -0
  208. data/db/migrate/20200730142511_add_file_upload_settings_to_decidim_organizations.rb +36 -0
  209. data/db/migrate/20200806092109_add_machine_translation_display_priority_to_organizations.rb +17 -0
  210. data/db/migrate/20201004160335_remove_notifications_with_continuity_badge.rb +9 -0
  211. data/db/seeds.rb +5 -4
  212. data/lib/decidim/authorable.rb +22 -1
  213. data/lib/decidim/authorization_form_builder.rb +7 -0
  214. data/lib/decidim/coauthorable.rb +22 -0
  215. data/lib/decidim/component_manifest.rb +1 -1
  216. data/lib/decidim/content_processor.rb +52 -29
  217. data/lib/decidim/content_renderers/base_renderer.rb +1 -1
  218. data/lib/decidim/content_renderers/hashtag_renderer.rb +2 -0
  219. data/lib/decidim/content_renderers/link_renderer.rb +4 -1
  220. data/lib/decidim/content_renderers/user_group_renderer.rb +3 -1
  221. data/lib/decidim/content_renderers/user_renderer.rb +3 -1
  222. data/lib/decidim/core.rb +67 -12
  223. data/lib/decidim/core/engine.rb +60 -21
  224. data/lib/decidim/core/test.rb +6 -0
  225. data/lib/decidim/core/test/factories.rb +34 -8
  226. data/lib/decidim/core/test/shared_examples/amendable/accept_amendment_examples.rb +4 -4
  227. data/lib/decidim/core/test/shared_examples/amendable_proposals_interface_examples.rb +8 -8
  228. data/lib/decidim/core/test/shared_examples/comments_examples.rb +52 -1
  229. data/lib/decidim/core/test/shared_examples/embed_resource_examples.rb +49 -0
  230. data/lib/decidim/core/test/shared_examples/follows_examples.rb +3 -3
  231. data/lib/decidim/core/test/shared_examples/manage_component_share_tokens.rb +83 -0
  232. data/lib/decidim/core/test/shared_examples/map_examples.rb +186 -0
  233. data/lib/decidim/core/test/shared_examples/preview_component_with_share_token_examples.rb +55 -0
  234. data/lib/decidim/core/test/shared_examples/resource_search_examples.rb +200 -0
  235. data/lib/decidim/core/test/shared_examples/scopable_resource_examples.rb +43 -0
  236. data/lib/decidim/core/test/shared_examples/scope_helper_examples.rb +12 -1
  237. data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +2 -2
  238. data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +15 -2
  239. data/lib/decidim/core/test/shared_examples/simple_event.rb +7 -0
  240. data/lib/decidim/core/test/shared_examples/system_endorse_resource_examples.rb +1 -0
  241. data/lib/decidim/core/test/shared_examples/traceable_interface_examples.rb +1 -1
  242. data/lib/decidim/core/test/shared_examples/uncommentable_component_examples.rb +1 -1
  243. data/lib/decidim/core/version.rb +1 -1
  244. data/lib/decidim/diffy_extension.rb +21 -0
  245. data/lib/decidim/events/base_event.rb +11 -9
  246. data/lib/decidim/exporters.rb +7 -0
  247. data/lib/decidim/exporters/csv.rb +15 -1
  248. data/lib/decidim/exporters/excel.rb +1 -1
  249. data/lib/decidim/exporters/export_manifest.rb +29 -0
  250. data/lib/decidim/exporters/pdf.rb +56 -0
  251. data/lib/decidim/file_validator_humanizer.rb +98 -0
  252. data/lib/decidim/form_builder.rb +65 -54
  253. data/lib/decidim/geocodable.rb +79 -0
  254. data/lib/decidim/has_attachments.rb +10 -0
  255. data/lib/decidim/has_upload_validations.rb +36 -0
  256. data/lib/decidim/map.rb +214 -0
  257. data/lib/decidim/map/autocomplete.rb +67 -0
  258. data/lib/decidim/map/dynamic_map.rb +89 -0
  259. data/lib/decidim/map/frontend.rb +97 -0
  260. data/lib/decidim/map/geocoding.rb +115 -0
  261. data/lib/decidim/map/provider.rb +12 -0
  262. data/lib/decidim/map/provider/autocomplete/here.rb +20 -0
  263. data/lib/decidim/map/provider/autocomplete/osm.rb +20 -0
  264. data/lib/decidim/map/provider/dynamic_map/here.rb +51 -0
  265. data/lib/decidim/map/provider/dynamic_map/osm.rb +13 -0
  266. data/lib/decidim/map/provider/geocoding/here.rb +58 -0
  267. data/lib/decidim/map/provider/geocoding/osm.rb +30 -0
  268. data/lib/decidim/map/provider/here.rb +21 -0
  269. data/lib/decidim/map/provider/osm.rb +22 -0
  270. data/lib/decidim/map/provider/static_map/here.rb +35 -0
  271. data/lib/decidim/map/provider/static_map/osm.rb +29 -0
  272. data/lib/decidim/map/static_map.rb +133 -0
  273. data/lib/decidim/map/utility.rb +38 -0
  274. data/lib/decidim/organization_settings.rb +267 -0
  275. data/lib/decidim/resource_manifest.rb +1 -1
  276. data/lib/decidim/scopable.rb +9 -6
  277. data/lib/decidim/scopable_component.rb +29 -1
  278. data/lib/decidim/scopable_participatory_space.rb +19 -0
  279. data/lib/decidim/scopable_resource.rb +21 -0
  280. data/lib/decidim/search_resource_fields_mapper.rb +15 -2
  281. data/lib/decidim/searchable.rb +4 -0
  282. data/lib/decidim/settings_manifest.rb +2 -1
  283. data/lib/decidim/shareable_with_token.rb +27 -0
  284. data/lib/decidim/snippets.rb +30 -0
  285. data/lib/decidim/translatable_attributes.rb +42 -4
  286. data/lib/decidim/translatable_resource.rb +78 -0
  287. data/lib/decidim/view_model.rb +1 -0
  288. data/lib/tasks/decidim_locales_tasks.rake +35 -0
  289. data/lib/tasks/decidim_tasks.rake +1 -0
  290. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.bg.js +14 -0
  291. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.da.js +14 -0
  292. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.eo.js +17 -0
  293. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.et.js +18 -0
  294. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr-CA.js +16 -0
  295. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ga.js +15 -0
  296. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.hr.js +13 -0
  297. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.is.js +14 -0
  298. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ja.js +16 -0
  299. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lt.js +16 -0
  300. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lv.js +17 -0
  301. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.mt.js +15 -0
  302. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sl.js +14 -0
  303. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sr.js +16 -0
  304. metadata +138 -26
  305. data/app/helpers/decidim/multi_translation_helper.rb +0 -0
  306. data/lib/decidim/hashtaggable.rb +0 -24
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "geocoder/stores/active_record"
4
+
5
+ module Decidim
6
+ # This concern overrides some of the Active Record functionality injected by
7
+ # the Geocoder gem in order to pass the geocoding searches through Decidim's
8
+ # own API which configures the geocoder correctly for each search. This is
9
+ # used when the `model.geocode` and `model.reverse_geocode` methods are called
10
+ # for the Active Record models.
11
+ #
12
+ # NOTE: This module is automatically loaded for all active record models in
13
+ # the "decidim.geocoding_extensions" initializer. It does not need to be
14
+ # included separately into any models.
15
+ module Geocodable
16
+ extend ActiveSupport::Concern
17
+
18
+ class_methods do
19
+ # Avoid double loading Geocoder::Store::ActiveRecord since it's already
20
+ # loaded by this concern (below in the included block).
21
+ def geocoder_init(options)
22
+ @geocoder_options = {} unless defined?(@geocoder_options)
23
+ @geocoder_options.merge! options
24
+ end
25
+ end
26
+
27
+ included do
28
+ include Geocoder::Store::ActiveRecord
29
+
30
+ private
31
+
32
+ def do_lookup(_reverse = false)
33
+ RecordGeocoder.with_record(self) do
34
+ super
35
+ end
36
+ end
37
+ end
38
+
39
+ module RecordGeocoder
40
+ def self.with_record(record)
41
+ @record = record
42
+ yield
43
+ ensure
44
+ @record = nil
45
+ end
46
+
47
+ def self.utility
48
+ return if @record.blank?
49
+ return unless Decidim::Map.available?(:geocoding)
50
+ return unless @record.respond_to?(:organization)
51
+
52
+ Decidim::Map.geocoding(organization: @record.organization)
53
+ end
54
+
55
+ def self.search(query, options = {})
56
+ if (util = utility)
57
+ util.search(query, options.compact)
58
+ else
59
+ Geocoder.search(query, options)
60
+ end
61
+ end
62
+
63
+ # Make the calculation functions work within the geocoded record, e.g.
64
+ # `distance_to`.
65
+ module Calculations
66
+ extend Geocoder::Calculations
67
+ end
68
+ end
69
+
70
+ # Change the `Geocoder` module reference under the Geocoder::Store::Base
71
+ # module which initiates the geocoding searches. This allows passing the
72
+ # geocoding queries through Decidim's own API that configures the geocoder
73
+ # correctly for each query.
74
+ #
75
+ # Overrides this call with the method defined above:
76
+ # https://git.io/JJEpq
77
+ ::Geocoder::Store::Base.const_set(:Geocoder, RecordGeocoder)
78
+ end
79
+ end
@@ -43,5 +43,15 @@ module Decidim
43
43
  documents.reject(&:attachment_collection_id?)
44
44
  end
45
45
  end
46
+
47
+ # Attachment context for the file uploaders checks (e.g. which kind of files
48
+ # the user is allowed to upload in this context).
49
+ #
50
+ # Override this in the model class if it is for a different context.
51
+ #
52
+ # Returns a Symbol.
53
+ def attachment_context
54
+ :participant
55
+ end
46
56
  end
47
57
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module HasUploadValidations
7
+ extend ActiveSupport::Concern
8
+
9
+ class_methods do
10
+ def validates_upload(attribute, options = {})
11
+ max_size = options[:max_size] || ->(record) { record.maximum_upload_size }
12
+
13
+ validates(
14
+ attribute,
15
+ file_size: { less_than_or_equal_to: max_size },
16
+ uploader_content_type: true
17
+ )
18
+ end
19
+
20
+ def validates_avatar(attribute = :avatar)
21
+ validates_upload(
22
+ attribute,
23
+ max_size: ->(record) { record.maximum_avatar_size }
24
+ )
25
+ end
26
+ end
27
+
28
+ def maximum_upload_size
29
+ Decidim.organization_settings(organization).upload_maximum_file_size
30
+ end
31
+
32
+ def maximum_avatar_size
33
+ Decidim.organization_settings(organization).upload_maximum_file_size_avatar
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Decidim configuration.
4
+ module Decidim
5
+ # A module containing the map functionality for Decidim.
6
+ module Map
7
+ autoload :Autocomplete, "decidim/map/autocomplete"
8
+ autoload :DynamicMap, "decidim/map/dynamic_map"
9
+ autoload :Geocoding, "decidim/map/geocoding"
10
+ autoload :Provider, "decidim/map/provider"
11
+ autoload :StaticMap, "decidim/map/static_map"
12
+ autoload :Utility, "decidim/map/utility"
13
+ autoload :Frontend, "decidim/map/frontend"
14
+
15
+ # Public: Returns a boolean indicating whether the mapping functionality has
16
+ # been configured.
17
+ #
18
+ # @return [Boolean] A boolean indicating whether the mapping functionality
19
+ # has been configured.
20
+ def self.configured?
21
+ configuration.present?
22
+ end
23
+
24
+ # Public: Returns a boolean indicating if the category of mapping services
25
+ # is available for this instance that the provided key represents.
26
+ #
27
+ # @param *categories [Symbol] The utility category key to check the
28
+ # availability for.
29
+ # @return [Boolean] A boolean indicating if the category of mapping services
30
+ # is available.
31
+ def self.available?(*categories)
32
+ categories.all? { |category| utility_class(category).present? }
33
+ end
34
+
35
+ # Public: Returns the full maps configuration hash.
36
+ #
37
+ # @return [Hash] The full map functionality configuration hash.
38
+ def self.configuration
39
+ Decidim.maps
40
+ end
41
+
42
+ # Public: Creates a new instance of the correct mapping utility class for
43
+ # the category specified by the key argument.
44
+ #
45
+ # @param category [Symbol] The utility category key for the utility to be
46
+ # created.
47
+ # @param options [Hash] The options for the utility constructor method.
48
+ # @return [Decidim::Map::Utility] A new instance of the mapping utility.
49
+ def self.utility(category, options)
50
+ return unless (klass = utility_class(category))
51
+
52
+ config = utility_configuration(category)
53
+ options[:config] = config.except(:provider)
54
+ klass.new(options)
55
+ end
56
+
57
+ # Public: Returns the utility class module namespace for each category of
58
+ # map utilities. The configured utility class (through Decidim.maps) is
59
+ # should be under these namespaces.
60
+ #
61
+ # @return [Hash<Symbol, Module>] The modules within which the utility
62
+ # classes should be defined in.
63
+ def self.utility_modules
64
+ @utility_modules ||= {}
65
+ end
66
+
67
+ # Public: Registers a new category of map modules.
68
+ #
69
+ # @param category [Symbol] The key for the category.
70
+ # @param mod [Module] The module to be assigned for the category.
71
+ # @return [Module] The module which was assigned for the category.
72
+ def self.register_category(category, mod)
73
+ @utility_modules ||= {}
74
+ @utility_modules[category] = mod
75
+
76
+ # Dynamically define the category method.
77
+ module_eval %{
78
+ def self.#{category}(options)
79
+ utility(:#{category}, options)
80
+ end
81
+ }, __FILE__, __LINE__ - 4
82
+
83
+ mod
84
+ end
85
+
86
+ # Public: Unregisters the given category of map modules. Mostly used for
87
+ # testing but there can be also actual use cases for this.
88
+ #
89
+ # @param category [Symbol] The key for the category.
90
+ # @return [Module, nil] The module which was previously assigned for the
91
+ # category or nil if no module was previously assigned for it.
92
+ def self.unregister_category(category)
93
+ return unless @utility_modules
94
+
95
+ mod = @utility_modules.delete(category)
96
+ @utility_configuration.delete(category) if @utility_configuration
97
+ singleton_class.instance_eval do
98
+ undef_method(category) if method_defined?(category)
99
+ end
100
+ mod
101
+ end
102
+
103
+ # Public: Sets and returns the utility specific configuration hash which
104
+ # contains the prepared configuration objects for each category of
105
+ # utilities.
106
+ #
107
+ # For example, given the following configuration:
108
+ # Decidim.configure do |config|
109
+ # config.maps = {
110
+ # provider: :osm,
111
+ # api_key: "apikey",
112
+ # global_conf: "value",
113
+ # dynamic: {
114
+ # tile_layer: {
115
+ # url: "https://tiles.example.org/{z}/{x}/{y}.png?{foo}",
116
+ # foo: "bar"
117
+ # }
118
+ # },
119
+ # static: {
120
+ # url: "https://staticmap.example.org/"
121
+ # },
122
+ # geocoding: {
123
+ # provider: :alternative,
124
+ # api_key: "gc_apikey",
125
+ # host: "https://nominatim.example.org/"
126
+ # }
127
+ # }
128
+ # end
129
+ #
130
+ # This would result in the following kind of configuration hash returned
131
+ # by this method:
132
+ # {
133
+ # dynamic: {
134
+ # provider: :osm,
135
+ # api_key: "apikey",
136
+ # global_conf: "value",
137
+ # tile_layer: {
138
+ # url: "https://tiles.example.org/{z}/{x}/{y}.png?{foo}",
139
+ # foo: "bar"
140
+ # }
141
+ # }
142
+ # static: {
143
+ # provider: :osm,
144
+ # api_key: "apikey",
145
+ # global_conf: "value",
146
+ # url: "https://staticmap.example.org/"
147
+ # }
148
+ # geocoding: {
149
+ # provider: :alternative,
150
+ # api_key: "gc_apikey",
151
+ # global_conf: "value",
152
+ # host: "https://nominatim.example.org/"
153
+ # }
154
+ # }
155
+ #
156
+ # @param category [Symbol, nil] The key of the utility category for which to
157
+ # fetch the configuration for. When nil, returns the whole configuration
158
+ # hash.
159
+ # @return [Hash] The configuration hash.
160
+ def self.utility_configuration(category = nil)
161
+ @utility_configuration ||= {}.tap do |config|
162
+ break {} unless configuration
163
+
164
+ global_config = configuration.except(*utility_modules.keys)
165
+ utility_modules.keys.each do |key|
166
+ utility_config = configuration.fetch(key, {})
167
+ next if utility_config == false
168
+
169
+ unless utility_config.is_a?(Hash)
170
+ config[key] = global_config
171
+ next
172
+ end
173
+
174
+ config[key] = global_config.merge(utility_config)
175
+ end
176
+ end
177
+ return @utility_configuration[category] if category
178
+
179
+ @utility_configuration
180
+ end
181
+
182
+ # Public: Resets the utility configuration to its initial state so that it
183
+ # is reloaded when utility_configuration is called the next time. It should
184
+ # not be necessary to call this ever but it is useful for the tests as the
185
+ # configurations can change.
186
+ #
187
+ # @return [nil]
188
+ def self.reset_utility_configuration!
189
+ @utility_configuration = nil
190
+ end
191
+
192
+ # Public: Returns the full utility class name in the correct module
193
+ # namespace for the given utility category. For example, if the provider
194
+ # :osm is configured for the :dynamic utilities, the utility class returned
195
+ # by this method is `Decidim::Map::Provider::DynamicMap::Osm`.
196
+ #
197
+ # @param category [Symbol] The category of utilities. E.g. `:dynamic`.
198
+ # @return [Class] The configured mapping service provider key.
199
+ def self.utility_class(category)
200
+ return unless (ns = utility_modules[category])
201
+
202
+ config = utility_configuration(category)
203
+ return if config.blank?
204
+ return unless (key = config[:provider])
205
+
206
+ # Define the last part of the class name from the category provider's key,
207
+ # e.g. by turning `:osm` to "Osm" or `:some_service` to "SomeService".
208
+ subclass_name = key.to_s.camelize
209
+ return unless ns.const_defined?(subclass_name)
210
+
211
+ ns.const_get(subclass_name)
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Map
5
+ # A base class for autocomplete geocoding functionality, common to all
6
+ # autocomplete map services.
7
+ class Autocomplete < Map::Frontend
8
+ # A builder for the geocoding autocompletion to be attached to the views.
9
+ # Provides all the necessary functionality to initialize the front-end
10
+ # geocoding autocompletion functionality.
11
+ class Builder < Decidim::Map::Frontend::Builder
12
+ # Displays the geocoding field element's markup for the view.
13
+ #
14
+ # @param object_name [String, Symbol] The name for the object for which
15
+ # the field is generated for.
16
+ # @param method [String, Symbol] The method/property in the object that
17
+ # the field is for.
18
+ # @param options [Hash] Extra options for the field.
19
+ # @return [String] The field element's markup.
20
+ def geocoding_field(object_name, method, options = {})
21
+ options[:autocomplete] ||= "off"
22
+
23
+ template.text_field(
24
+ object_name,
25
+ method,
26
+ options.merge("data-decidim-geocoding" => view_options.to_json)
27
+ )
28
+ end
29
+ end
30
+
31
+ # This module will be included in the main application's form builder in
32
+ # order to provide the geocoding_field method for the normal form
33
+ # builders. This allows you to include geocoding autocompletion in the
34
+ # forms using the following code:
35
+ #
36
+ # <%= form_for record do |form| %>
37
+ # <%= form.geocoding_field(:address) %>
38
+ # <% end %>
39
+ module FormBuilder
40
+ def geocoding_field(attribute, options = {}, geocoding_options = {})
41
+ @autocomplete_utility ||= Decidim::Map.autocomplete(
42
+ organization: @template.current_organization
43
+ )
44
+ return text_field(attribute, options) unless @autocomplete_utility
45
+
46
+ # Decidim::Map::Autocomplete::Builder
47
+ builder = @autocomplete_utility.create_builder(
48
+ @template,
49
+ geocoding_options
50
+ )
51
+
52
+ unless @template.snippets.any?(:geocoding)
53
+ @template.snippets.add(:geocoding, builder.stylesheet_snippets)
54
+ @template.snippets.add(:geocoding, builder.javascript_snippets)
55
+
56
+ # This will display the snippets in the <head> part of the page.
57
+ @template.snippets.add(:head, @template.snippets.for(:geocoding))
58
+ end
59
+
60
+ field(attribute, options) do |opts|
61
+ builder.geocoding_field(@object_name, attribute, opts)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Map
5
+ # A base class for dynamic mapping functionality, common to all dynamic map
6
+ # services.
7
+ class DynamicMap < Map::Frontend
8
+ # Creates a builder class for the front-end that is used to build the map
9
+ # HTML markup.
10
+ #
11
+ # @param (see Decidim::Map::DynamicMap::Builder#initialize)
12
+ #
13
+ # @return [Decidim::Map::DynamicMap::Builder] The builder object that can
14
+ # be used to build the map's markup.
15
+ def create_builder(template, options = {})
16
+ builder_class.new(template, builder_options.merge(options))
17
+ end
18
+
19
+ # Returns the builder class for the map. Allows fetching the class name
20
+ # dynamically also in the utility classes that extend this class.
21
+ #
22
+ # @return [Class] The class for the builder object.
23
+ def builder_class
24
+ self.class.const_get(:Builder)
25
+ end
26
+
27
+ # Returns the options for the default builder object.
28
+ #
29
+ # @return [Hash] The default options for the map builder.
30
+ def builder_options
31
+ {
32
+ marker_color: organization.colors.fetch("primary", "#ef604d"),
33
+ tile_layer: tile_layer_configuration
34
+ }
35
+ end
36
+
37
+ protected
38
+
39
+ # Prepares the tile layer configuration hash to be passed for the
40
+ # builder.
41
+ #
42
+ # @return The tile layer configuration hash.
43
+ def tile_layer_configuration
44
+ tile_layer = configuration.fetch(:tile_layer, {})
45
+ tile_layer_options = tile_layer.except(:url).tap do |config|
46
+ config.fetch(:api_key, nil) == true &&
47
+ config[:api_key] = configuration.fetch(:api_key, nil)
48
+ end
49
+
50
+ {
51
+ url: tile_layer.fetch(:url, nil),
52
+ options: tile_layer_options
53
+ }
54
+ end
55
+
56
+ # A builder for the dynamic maps to be used in the views. Provides all the
57
+ # necessary functionality to display and initialize the maps.
58
+ class Builder < Decidim::Map::Frontend::Builder
59
+ # Displays the map element's markup for the view.
60
+ #
61
+ # @param html_options [Hash] Extra options to pass to the map element.
62
+ # @return [String] The map element's markup.
63
+ def map_element(html_options = {})
64
+ map_html_options = {
65
+ "data-decidim-map" => view_options.to_json,
66
+ # The data-markers-data is kept for backwards compatibility
67
+ "data-markers-data" => options.fetch(:markers, []).to_json
68
+ }.merge(html_options)
69
+
70
+ content = template.capture { yield }.html_safe if block_given?
71
+
72
+ template.content_tag(:div, map_html_options) do
73
+ (content || "")
74
+ end
75
+ end
76
+
77
+ # @see Decidim::Map::View::Builder#stylesheet_snippets
78
+ def stylesheet_snippets
79
+ template.stylesheet_link_tag("decidim/map")
80
+ end
81
+
82
+ # @see Decidim::Map::View::Builder#javascript_snippets
83
+ def javascript_snippets
84
+ template.javascript_include_tag("decidim/map/provider/default")
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end