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
@@ -6,8 +6,17 @@ shared_examples "scope helpers" do
6
6
  let(:organization) { create(:organization) }
7
7
  let(:scopes_enabled) { true }
8
8
  let(:participatory_space_scope) { nil }
9
- let(:component) { create(:component, manifest_name: "dummy", participatory_space: participatory_space) }
9
+ let(:component_scope) { nil }
10
+ let(:component) do
11
+ create(
12
+ :component,
13
+ manifest_name: "dummy",
14
+ participatory_space: participatory_space,
15
+ settings: { scopes_enabled: scopes_enabled, scope_id: component_scope&.id }
16
+ )
17
+ end
10
18
  let(:scope) { create(:scope, organization: organization) }
19
+ let(:subscope) { create(:subscope, organization: organization) }
11
20
  let(:resource) { create(:dummy_resource, component: component, scope: scope) }
12
21
 
13
22
  before do
@@ -36,12 +45,14 @@ shared_examples "scope helpers" do
36
45
 
37
46
  context "when the process has a different scope than the organization" do
38
47
  let(:participatory_space_scope) { create(:scope, organization: organization) }
48
+ let(:component_scope) { participatory_space_scope }
39
49
 
40
50
  it { is_expected.to be_truthy }
41
51
  end
42
52
 
43
53
  context "when the process has the same scope as the organization" do
44
54
  let(:participatory_space_scope) { scope }
55
+ let(:component_scope) { scope }
45
56
 
46
57
  it { is_expected.to be_falsey }
47
58
  end
@@ -36,7 +36,7 @@ shared_examples "global search of participatory spaces" do
36
36
  it "updates the associated SearchableResource after published ParticipatorySpace update" do
37
37
  searchable = ::Decidim::SearchableResource.find_by(resource_type: participatory_space.class.name, resource_id: participatory_space.id)
38
38
  created_at = searchable.created_at
39
- updated_title = "Brand new title"
39
+ updated_title = { "en" => "Brand new title" }
40
40
  participatory_space.update(title: updated_title)
41
41
 
42
42
  participatory_space.save!
@@ -44,7 +44,7 @@ shared_examples "global search of participatory spaces" do
44
44
 
45
45
  organization.available_locales.each do |locale|
46
46
  searchable = ::Decidim::SearchableResource.find_by(resource_type: participatory_space.class.name, resource_id: participatory_space.id, locale: locale)
47
- expect(searchable.content_a).to eq updated_title
47
+ expect(searchable.content_a).to eq updated_title[locale.to_s].to_s
48
48
  expect(searchable.updated_at).to be > created_at
49
49
  end
50
50
  end
@@ -12,16 +12,29 @@ shared_examples "searchable results" do
12
12
  before do
13
13
  expect(searchables).not_to be_empty
14
14
  expect(term).not_to be_empty
15
+ end
15
16
 
17
+ it "contains these searchables" do
16
18
  fill_in "term", with: term
17
19
  find("input#term").native.send_keys :enter
18
- end
19
20
 
20
- it "contains these searchables" do
21
21
  expect(page).to have_current_path decidim.search_path, ignore_query: true
22
22
  expect(page).to have_content(/results for the search: "#{term}"/i)
23
23
  expect(page).to have_selector(".filters__section")
24
24
  expect(page.find("#search-count .section-heading").text.to_i).to be_positive
25
25
  end
26
+
27
+ it "finds content by hashtag" do
28
+ if respond_to?(:hashtag)
29
+ fill_in "term", with: hashtag
30
+ find("input#term").native.send_keys :enter
31
+
32
+ expect(page.find("#search-count .section-heading").text.to_i).to be_positive
33
+
34
+ within "#results" do
35
+ expect(page).to have_content(hashtag)
36
+ end
37
+ end
38
+ end
26
39
  end
27
40
  end
@@ -89,6 +89,13 @@ shared_examples_for "a simple event" do |skip_space_checks|
89
89
  end
90
90
  end
91
91
 
92
+ describe "safe_resource_text" do
93
+ it "is generated correctly" do
94
+ expect(subject.safe_resource_text).to be_kind_of(String)
95
+ expect(subject.safe_resource_text).to be_html_safe
96
+ end
97
+ end
98
+
92
99
  describe "notification_title" do
93
100
  it "is generated correctly" do
94
101
  expect(subject.notification_title).to be_kind_of(String)
@@ -12,6 +12,7 @@ shared_context "with resources to be endorsed or not" do
12
12
  # Should be overriden and create 3 extra resources in the current component
13
13
  let!(:resources) {}
14
14
  end
15
+
15
16
  shared_examples "Endorse resource system specs" do
16
17
  def expect_page_not_to_include_endorsements
17
18
  expect(page).to have_no_button("Endorse")
@@ -6,7 +6,7 @@ shared_examples_for "traceable interface" do
6
6
  describe "traceable", versioning: true do
7
7
  let(:version_author) { try(:author) || model.try(:creator_identity) || model.try(:normalized_author) }
8
8
 
9
- before { Decidim.traceability.update!(model, version_author, title: "test") }
9
+ before { Decidim.traceability.update!(model, version_author, title: { en: "test" }) }
10
10
 
11
11
  context "when field createdAt" do
12
12
  let(:query) { "{ versions { createdAt } }" }
@@ -14,7 +14,7 @@ shared_examples "an uncommentable component" do
14
14
 
15
15
  visit_component
16
16
 
17
- ressources.each do |ressource|
17
+ resources.each do |ressource|
18
18
  expect(page).not_to have_link(resource_locator(ressource).path)
19
19
  end
20
20
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-core version.
5
5
  module Core
6
6
  def self.version
7
- "0.22.0"
7
+ "0.23.0"
8
8
  end
9
9
  end
10
10
  end
@@ -22,5 +22,26 @@ module Decidim
22
22
  UnescapedHtmlFormatter.new(self, options).to_s
23
23
  end
24
24
  end
25
+
26
+ # The private "split" method SplitDiff needs to be overriden to take into
27
+ # account the new :unescaped_html format, and the fact that the tags
28
+ # <ins> <del> are not there anymore
29
+ Diffy::SplitDiff.module_eval do
30
+ private
31
+
32
+ def split
33
+ return [split_left, split_right] unless @format == :unescaped_html
34
+
35
+ [unescaped_split_left, unescaped_split_right]
36
+ end
37
+
38
+ def unescaped_split_left
39
+ @diff.gsub(%r{<li class="ins">([\s\S]*?)<\/li>}, "")
40
+ end
41
+
42
+ def unescaped_split_right
43
+ @diff.gsub(%r{<li class="del">([\s\S]*?)<\/li>}, "")
44
+ end
45
+ end
25
46
  end
26
47
  end
@@ -69,18 +69,20 @@ module Decidim
69
69
 
70
70
  def resource_text; end
71
71
 
72
+ def safe_resource_text
73
+ translated_attribute(resource_text).to_s.html_safe
74
+ end
75
+
72
76
  def resource_title
73
77
  return unless resource
74
78
 
75
- if resource.is_a?(Decidim::Hashtaggable)
76
- translated_title = translated_attribute(resource.title)
77
- renderer = Decidim::ContentRenderers::HashtagRenderer.new(translated_title)
78
- renderer.render(links: false).html_safe
79
- elsif resource.respond_to?(:title)
80
- translated_attribute(resource.title)
81
- elsif resource.respond_to?(:name)
82
- translated_attribute(resource.name)
83
- end
79
+ title = if resource.respond_to?(:title)
80
+ translated_attribute(resource.title)
81
+ elsif resource.respond_to?(:name)
82
+ translated_attribute(resource.name)
83
+ end
84
+
85
+ Decidim::ContentProcessor.render_without_format(title, links: false).html_safe
84
86
  end
85
87
 
86
88
  private
@@ -6,8 +6,15 @@ module Decidim
6
6
  autoload :JSON, "decidim/exporters/json"
7
7
  autoload :CSV, "decidim/exporters/csv"
8
8
  autoload :Excel, "decidim/exporters/excel"
9
+ autoload :PDF, "decidim/exporters/pdf"
9
10
  autoload :ExportData, "decidim/exporters/export_data"
10
11
 
12
+ # Necessary for the i18n normalizer to locate strings not directly invoked in views:
13
+
14
+ # i18n-tasks-use t('decidim.admin.exports.formats.JSON')
15
+ # i18n-tasks-use t('decidim.admin.exports.formats.CSV')
16
+ # i18n-tasks-use t('decidim.admin.exports.formats.Excel')
17
+
11
18
  # Get the exporter class constant from the format as a string.
12
19
  #
13
20
  # format - The exporter format as a string. i.e "CSV"
@@ -18,12 +18,26 @@ module Decidim
18
18
  def export(col_sep = Decidim.default_csv_col_sep)
19
19
  data = ::CSV.generate(headers: headers, write_headers: true, col_sep: col_sep) do |csv|
20
20
  processed_collection.each do |resource|
21
- csv << headers.map { |header| resource[header] }
21
+ csv << headers.map { |header| custom_sanitize(resource[header]) }
22
22
  end
23
23
  end
24
24
  ExportData.new(data, "csv")
25
25
  end
26
26
 
27
+ protected
28
+
29
+ def custom_sanitize(value)
30
+ # rubocop:disable Style/AndOr
31
+ return value unless value.instance_of?(String) and invalid_first_chars.include?(value.first)
32
+
33
+ # rubocop:enable Style/AndOr
34
+ value.dup.prepend("'")
35
+ end
36
+
37
+ def invalid_first_chars
38
+ %w(= + - @)
39
+ end
40
+
27
41
  private
28
42
 
29
43
  def headers
@@ -36,7 +36,7 @@ module Decidim
36
36
  end
37
37
 
38
38
  processed_collection.each_with_index do |resource, index|
39
- sheet.row(index + 1).replace(headers.map { |header| resource[header] })
39
+ sheet.row(index + 1).replace(headers.map { |header| custom_sanitize(resource[header]) })
40
40
  end
41
41
 
42
42
  output = StringIO.new
@@ -71,6 +71,35 @@ module Decidim
71
71
  def serializer(serializer = nil)
72
72
  @serializer ||= serializer || Decidim::Exporters::Serializer
73
73
  end
74
+
75
+ DEFAULT_FORMATS = %w(CSV JSON Excel).freeze
76
+
77
+ # Public: Sets the available formats if an argument is provided and
78
+ # loads the required exporters, returns the array with the default available
79
+ # formats otherwise.
80
+ #
81
+ # The formats array is used to define which exporters are available
82
+ # in the component. Each member of the array is a string with the name
83
+ # of the exporter class that will instantiated when needed.
84
+ #
85
+ # formats - The array containing the available formats.
86
+ #
87
+ # Returns the stored formats if previously stored, or
88
+ # the default formats array.
89
+ def formats(formats = nil)
90
+ load_exporters(formats)
91
+ @formats ||= formats || DEFAULT_FORMATS
92
+ end
93
+
94
+ private
95
+
96
+ # Private: Loads the given exporters when formats argument is provided.
97
+ #
98
+ # formats - The array containing the formats for which to load exporters.
99
+ #
100
+ def load_exporters(formats)
101
+ formats&.each { |f| require "decidim/exporters/#{f.underscore}" }
102
+ end
74
103
  end
75
104
  end
76
105
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "wicked_pdf"
4
+
5
+ module Decidim
6
+ module Exporters
7
+ # Exports a PDF using the provided hash, given a collection and a
8
+ # Serializer. This is an abstract class that should be inherited
9
+ # to create PDF exporters, with each PDF exporter class setting
10
+ # the desired template, layout and orientation.
11
+ #
12
+ class PDF < Exporter
13
+ # Public: Exports a PDF version of the collection by rendering
14
+ # the template into html and then converting it to PDF.
15
+ #
16
+ # Returns an ExportData instance.
17
+ def export
18
+ html = controller.render_to_string(
19
+ template: template,
20
+ layout: layout,
21
+ locals: locals
22
+ )
23
+
24
+ document = WickedPdf.new.pdf_from_string(html, orientation: orientation)
25
+
26
+ ExportData.new(document, "pdf")
27
+ end
28
+
29
+ # may be overwritten if needed
30
+ def orientation
31
+ "Portrait"
32
+ end
33
+
34
+ # implementing classes should return a valid ERB path here
35
+ def template
36
+ raise NotImplementedError
37
+ end
38
+
39
+ # implementing classes should return a valid ERB path here
40
+ def layout
41
+ raise NotImplementedError
42
+ end
43
+
44
+ # This method may be overwritten if the template needs more local variables
45
+ def locals
46
+ { collection: collection }
47
+ end
48
+
49
+ protected
50
+
51
+ def controller
52
+ raise NotImplementedError
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class fetches the file validation conditions from the active record
5
+ # model objects which have specific validators and uploaders attached to them.
6
+ # This class is used to convert these validation conditions to a human
7
+ # readable format in the front-end and to simplify the code where these are
8
+ # needed from.
9
+ #
10
+ # This considers if the validation conditions and the uploader have been set
11
+ # directly to the record being validated or if they should be read from
12
+ # another object in case the PassthruValidator is in charge of the
13
+ # validations.
14
+ class FileValidatorHumanizer
15
+ def initialize(record, attribute)
16
+ @record = record
17
+ @attribute = attribute
18
+ @passthru_validator ||= record.singleton_class.validators_on(
19
+ attribute
20
+ ).find { |validator| validator.is_a?(PassthruValidator) }
21
+ end
22
+
23
+ def uploader
24
+ @uploader ||= passthru_uploader || record.send(attribute)
25
+ end
26
+
27
+ def messages
28
+ messages = []
29
+
30
+ if (file_size = max_file_size)
31
+ file_size_mb = (((file_size / 1024 / 1024) * 100) / 100).round
32
+ messages << I18n.t(
33
+ "max_file_size",
34
+ megabytes: file_size_mb,
35
+ scope: "decidim.forms.file_validation"
36
+ )
37
+ end
38
+
39
+ if (extensions = extension_whitelist)
40
+ messages << I18n.t(
41
+ "allowed_file_extensions",
42
+ extensions: extensions.join(" "),
43
+ scope: "decidim.forms.file_validation"
44
+ )
45
+ end
46
+
47
+ messages
48
+ end
49
+
50
+ def max_file_size
51
+ # First try if the record itself has a file size validator defined.
52
+ validator = record.singleton_class.validators_on(attribute).find do |v|
53
+ v.is_a?(::ActiveModel::Validations::FileSizeValidator)
54
+ end
55
+ if validator
56
+ lte = validator.options[:less_than_or_equal_to]
57
+ return lte if lte.is_a?(Numeric)
58
+ return lte.call(record) if lte.respond_to?(:call)
59
+ end
60
+ return unless passthru_validator
61
+
62
+ # If not, check for the same validator from the pass through record.
63
+ validator = passthru_validator.target_validators(attribute).find do |v|
64
+ v.is_a?(::ActiveModel::Validations::FileSizeValidator)
65
+ end
66
+ return unless validator
67
+
68
+ lte = validator.options[:less_than_or_equal_to]
69
+ return lte if lte.is_a?(Numeric)
70
+
71
+ lte.call(passthru_record) if lte.respond_to?(:call)
72
+ end
73
+
74
+ def extension_whitelist
75
+ return unless uploader.respond_to?(:extension_whitelist, true)
76
+
77
+ # It may be a private method in some uploaders which is why we need to use
78
+ # `#send`.
79
+ uploader.send(:extension_whitelist)
80
+ end
81
+
82
+ private
83
+
84
+ attr_reader :record, :attribute, :passthru_validator
85
+
86
+ def passthru_record
87
+ return unless passthru_validator
88
+
89
+ @passthru_record ||= passthru_validator.validation_record(record)
90
+ end
91
+
92
+ def passthru_uploader
93
+ return unless passthru_record
94
+
95
+ passthru_record.send(passthru_validator.target_attribute(attribute))
96
+ end
97
+ end
98
+ end
@@ -8,6 +8,7 @@ module Decidim
8
8
  class FormBuilder < FoundationRailsHelper::FormBuilder
9
9
  include ActionView::Context
10
10
  include Decidim::TranslatableAttributes
11
+ include Decidim::Map::Autocomplete::FormBuilder
11
12
 
12
13
  # Public: generates a check boxes input from a collection and adds help
13
14
  # text and errors.
@@ -32,7 +33,7 @@ module Decidim
32
33
  # text and errors.
33
34
  #
34
35
  # attribute - the name of the field
35
- # collection - the collection from which we will render the check boxes
36
+ # collection - the collection from which we will render the radio buttons
36
37
  # value_attribute - a Symbol or a Proc defining how to find the value attribute
37
38
  # text_attribute - a Symbol or a Proc defining how to find the text attribute
38
39
  # options - a Hash with options
@@ -45,6 +46,14 @@ module Decidim
45
46
  end
46
47
  # rubocop:enable Metrics/ParameterLists
47
48
 
49
+ def create_language_selector(locales, tabs_id, name)
50
+ if Decidim.available_locales.count > 4
51
+ language_selector_select(locales, tabs_id, name)
52
+ else
53
+ language_tabs(locales, tabs_id, name)
54
+ end
55
+ end
56
+
48
57
  # Public: Generates an form field for each locale.
49
58
  #
50
59
  # type - The form field's type, like `text_area` or `text_input`
@@ -60,22 +69,10 @@ module Decidim
60
69
  label_tabs = content_tag(:div, class: "label--tabs") do
61
70
  field_label = label_i18n(name, options[:label] || label_for(name))
62
71
 
63
- tabs_panels = "".html_safe
64
- if options[:label] != false
65
- tabs_panels = content_tag(:ul, class: "tabs tabs--lang", id: tabs_id, data: { tabs: true }) do
66
- locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
67
- string + content_tag(:li, class: tab_element_class_for("title", index)) do
68
- title = I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
69
- element_class = nil
70
- element_class = "is-tab-error" if error?(name_with_locale(name, locale))
71
- tab_content_id = sanitize_tabs_selector "#{tabs_id}-#{name}-panel-#{index}"
72
- content_tag(:a, title, href: "##{tab_content_id}", class: element_class)
73
- end
74
- end
75
- end
76
- end
72
+ language_selector = "".html_safe
73
+ language_selector = create_language_selector(locales, tabs_id, name) if options[:label] != false
77
74
 
78
- safe_join [field_label, tabs_panels]
75
+ safe_join [field_label, language_selector]
79
76
  end
80
77
 
81
78
  hashtaggable = options.delete(:hashtaggable)
@@ -284,14 +281,18 @@ module Decidim
284
281
  # options - An optional Hash with options:
285
282
  # - multiple - Multiple mode, to allow multiple scopes selection.
286
283
  # - label - Show label?
287
- # - checkboxes_on_top - Show checked picker values on top (default) or below the picker prompt
284
+ # - checkboxes_on_top - Show checked picker values on top (default) or below the picker prompt (only for multiple pickers)
285
+ # - namespace - prepend a custom name to the html element's DOM id.
288
286
  #
289
287
  # Also it should receive a block that returns a Hash with :url and :text for each selected scope (and for null scope for prompt)
290
288
  #
291
289
  # Returns a String.
292
290
  def scopes_picker(attribute, options = {})
293
- id = "#{@object_name}_#{attribute}"
294
- id = "#{self.options[:namespace]}_#{id}" if self.options.has_key?(:namespace)
291
+ id = if self.options.has_key?(:namespace)
292
+ "#{self.options[:namespace]}_#{sanitize_for_dom_selector(@object_name)}"
293
+ else
294
+ "#{sanitize_for_dom_selector(@object_name)}_#{attribute}"
295
+ end
295
296
 
296
297
  picker_options = {
297
298
  id: id,
@@ -309,7 +310,7 @@ module Decidim
309
310
  picker_options: picker_options,
310
311
  prompt_params: prompt_params,
311
312
  scopes: scopes,
312
- checkboxes_on_top: options[:checkboxes_on_top])
313
+ values_on_top: !options[:multiple] || options[:checkboxes_on_top])
313
314
  template += error_and_help_text(attribute, options)
314
315
  template.html_safe
315
316
  end
@@ -450,47 +451,23 @@ module Decidim
450
451
  # rubocop:enable Metrics/PerceivedComplexity
451
452
 
452
453
  def upload_help(attribute, _options = {})
453
- file = object.send attribute
454
+ humanizer = FileValidatorHumanizer.new(object, attribute)
454
455
 
455
- content_tag(:div, class: "help-text") do
456
- file_size_validator = object.singleton_class.validators_on(
457
- attribute
458
- ).find { |validator| validator.is_a?(::ActiveModel::Validations::FileSizeValidator) }
459
- if file_size_validator
460
- lte = file_size_validator.options[:less_than_or_equal_to]
461
- max_file_size = lte.call(nil) if lte && lte.lambda?
456
+ help_scope = begin
457
+ if humanizer.uploader.is_a?(Decidim::ImageUploader)
458
+ "decidim.forms.file_help.image"
459
+ else
460
+ "decidim.forms.file_help.file"
462
461
  end
462
+ end
463
463
 
464
- help_scope = begin
465
- if file.is_a?(Decidim::ImageUploader)
466
- "decidim.forms.file_help.image"
467
- else
468
- "decidim.forms.file_help.file"
469
- end
470
- end
464
+ content_tag(:div, class: "help-text") do
471
465
  help_messages = %w(message_1 message_2)
472
466
 
473
467
  inner = "<p>#{I18n.t("explanation", scope: help_scope)}</p>".html_safe
474
468
  inner + content_tag(:ul) do
475
469
  messages = help_messages.each.map { |msg| I18n.t(msg, scope: help_scope) }
476
-
477
- if max_file_size
478
- file_size_mb = (((max_file_size / 1024 / 1024) * 100) / 100).round
479
- messages << I18n.t(
480
- "max_file_size",
481
- megabytes: file_size_mb,
482
- scope: "decidim.forms.file_validation"
483
- )
484
- end
485
-
486
- if file.respond_to?(:extension_whitelist, true)
487
- allowed_extensions = file.send(:extension_whitelist)
488
- messages << I18n.t(
489
- "allowed_file_extensions",
490
- extensions: allowed_extensions.join(" "),
491
- scope: "decidim.forms.file_validation"
492
- )
493
- end
470
+ messages += humanizer.messages
494
471
 
495
472
  messages.map { |msg| content_tag(:li, msg) }.join("\n").html_safe
496
473
  end.html_safe
@@ -653,7 +630,7 @@ module Decidim
653
630
  def find_validator(attribute, klass)
654
631
  return unless object.respond_to?(:_validators)
655
632
 
656
- object._validators[attribute].find { |validator| validator.class == klass }
633
+ object._validators[attribute.to_sym].find { |validator| validator.class == klass }
657
634
  end
658
635
 
659
636
  # Private: Override method from FoundationRailsHelper to render the text of the
@@ -818,6 +795,10 @@ module Decidim
818
795
  id.tr("[", "-").tr("]", "-")
819
796
  end
820
797
 
798
+ def sanitize_for_dom_selector(name)
799
+ name.to_s.parameterize.underscore
800
+ end
801
+
821
802
  def extension_whitelist_help(extension_whitelist)
822
803
  content_tag :p, class: "extensions-help help-text" do
823
804
  safe_join([
@@ -872,5 +853,35 @@ module Decidim
872
853
 
873
854
  content_tag(:span, prefix + input + postfix, class: "row collapse")
874
855
  end
856
+
857
+ def language_selector_select(locales, tabs_id, name)
858
+ content_tag(:div) do
859
+ content_tag(:select, id: tabs_id, class: "language-change") do
860
+ locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
861
+ title = if error?(name_with_locale(name, locale))
862
+ I18n.with_locale(locale) { I18n.t("name_with_error", scope: "locale") }
863
+ else
864
+ I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
865
+ end
866
+ tab_content_id = sanitize_tabs_selector "#{tabs_id}-#{name}-panel-#{index}"
867
+ string + content_tag(:option, title, value: "##{tab_content_id}")
868
+ end
869
+ end
870
+ end
871
+ end
872
+
873
+ def language_tabs(locales, tabs_id, name)
874
+ content_tag(:ul, class: "tabs tabs--lang", id: tabs_id, data: { tabs: true }) do
875
+ locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
876
+ string + content_tag(:li, class: tab_element_class_for("title", index)) do
877
+ title = I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
878
+ element_class = nil
879
+ element_class = "is-tab-error" if error?(name_with_locale(name, locale))
880
+ tab_content_id = sanitize_tabs_selector "#{tabs_id}-#{name}-panel-#{index}"
881
+ content_tag(:a, title, href: "##{tab_content_id}", class: element_class)
882
+ end
883
+ end
884
+ end
885
+ end
875
886
  end
876
887
  end