decidim-core 0.23.6 → 0.24.0.rc1

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 (455) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/images/decidim/icons.svg +1 -1
  4. data/app/assets/javascripts/decidim/core/bundle.js +1 -1
  5. data/app/assets/javascripts/decidim/core/bundle.js.map +1 -1
  6. data/app/assets/javascripts/decidim/editor/history_override.js.es6 +117 -0
  7. data/app/assets/javascripts/decidim/editor/linebreak_module.js.es6 +83 -0
  8. data/app/assets/javascripts/decidim/editor/modified_backspace_offset1.js.es6 +98 -0
  9. data/app/assets/javascripts/decidim/editor/modified_backspace_offset_any.js.es6 +48 -0
  10. data/app/assets/javascripts/decidim/editor/modified_backspace_utils.js.es6 +31 -0
  11. data/app/assets/javascripts/decidim/editor/modified_enter.js.es6 +118 -0
  12. data/app/assets/javascripts/decidim/editor.js.es6 +15 -4
  13. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +25 -0
  14. data/app/assets/javascripts/decidim/geocoding/attach_input.js.es6 +41 -4
  15. data/app/assets/javascripts/decidim/input_character_counter.js.es6 +6 -1
  16. data/app/assets/javascripts/decidim/map/controller/markers.js.es6 +27 -9
  17. data/app/assets/javascripts/decidim/session_timeouter.js.es6 +78 -0
  18. data/app/assets/javascripts/decidim.js.es6 +1 -0
  19. data/app/assets/stylesheets/decidim/_variables.scss +9 -0
  20. data/app/assets/stylesheets/decidim/email.scss +14 -2
  21. data/app/assets/stylesheets/decidim/extras/_external-links.scss +0 -1
  22. data/app/assets/stylesheets/decidim/extras/_process_stats.scss +1 -1
  23. data/app/assets/stylesheets/decidim/extras/_results-per-page.scss +1 -0
  24. data/app/assets/stylesheets/decidim/modules/_author-avatar.scss +2 -2
  25. data/app/assets/stylesheets/decidim/modules/_buttons.scss +2 -2
  26. data/app/assets/stylesheets/decidim/modules/_cards.scss +18 -1
  27. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +1 -1
  28. data/app/assets/stylesheets/decidim/modules/_comments.scss +5 -1
  29. data/app/assets/stylesheets/decidim/modules/_conference-speaker.scss +4 -3
  30. data/app/assets/stylesheets/decidim/modules/_data-picker.scss +7 -0
  31. data/app/assets/stylesheets/decidim/modules/_extra.scss +4 -0
  32. data/app/assets/stylesheets/decidim/modules/_forms.scss +4 -0
  33. data/app/assets/stylesheets/decidim/modules/_loading-spinner.scss +34 -0
  34. data/app/assets/stylesheets/decidim/modules/_modules.scss +1 -1
  35. data/app/assets/stylesheets/decidim/modules/_opinion-toggle.scss +1 -1
  36. data/app/assets/stylesheets/decidim/modules/_reveal.scss +6 -0
  37. data/app/assets/stylesheets/decidim/modules/_signup.scss +1 -0
  38. data/app/assets/stylesheets/decidim/modules/{_process-stats.scss → _space-stats.scss} +1 -1
  39. data/app/cells/decidim/activity/show.erb +1 -1
  40. data/app/cells/decidim/activity_cell.rb +11 -14
  41. data/app/cells/decidim/address/details.erb +5 -5
  42. data/app/cells/decidim/address_cell.rb +0 -21
  43. data/app/cells/decidim/announcement/show.erb +4 -4
  44. data/app/cells/decidim/announcement_cell.rb +22 -2
  45. data/app/cells/decidim/author/flag_user.erb +10 -0
  46. data/app/cells/decidim/author/profile_minicard.erb +1 -1
  47. data/app/cells/decidim/author_cell.rb +9 -1
  48. data/app/cells/decidim/card_m/top.erb +1 -1
  49. data/app/cells/decidim/card_m_cell.rb +1 -1
  50. data/app/cells/decidim/content_blocks/cta/show.erb +14 -0
  51. data/app/cells/decidim/content_blocks/cta_cell.rb +35 -0
  52. data/app/cells/decidim/content_blocks/cta_settings_form/show.erb +9 -0
  53. data/app/cells/decidim/content_blocks/cta_settings_form_cell.rb +13 -0
  54. data/app/cells/decidim/content_blocks/hero_cell.rb +14 -0
  55. data/app/cells/decidim/content_blocks/highlighted_elements/elements.erb +0 -0
  56. data/app/cells/decidim/content_blocks/highlighted_elements/heading.erb +0 -0
  57. data/app/cells/decidim/content_blocks/highlighted_elements/show.erb +4 -0
  58. data/app/cells/decidim/content_blocks/highlighted_elements_cell.rb +51 -0
  59. data/app/cells/decidim/content_blocks/highlighted_elements_settings_form/show.erb +3 -0
  60. data/app/cells/decidim/content_blocks/highlighted_elements_settings_form_cell.rb +28 -0
  61. data/app/cells/decidim/content_blocks/last_activity_cell.rb +11 -0
  62. data/app/cells/decidim/content_blocks/metrics_cell.rb +0 -6
  63. data/app/cells/decidim/content_blocks/stats_cell.rb +0 -6
  64. data/app/cells/decidim/date/show.erb +31 -0
  65. data/app/cells/decidim/date_cell.rb +50 -0
  66. data/app/cells/decidim/endorsement_buttons_cell.rb +3 -3
  67. data/app/cells/decidim/flag_modal/flag_user.erb +24 -0
  68. data/app/cells/decidim/flag_modal/show.erb +24 -0
  69. data/app/cells/decidim/flag_modal_cell.rb +25 -0
  70. data/app/cells/decidim/profile/inaccessible.erb +9 -0
  71. data/app/cells/decidim/profile_cell.rb +9 -1
  72. data/app/cells/decidim/profile_sidebar/show.erb +10 -1
  73. data/app/cells/decidim/profile_sidebar_cell.rb +1 -0
  74. data/app/cells/decidim/reported_content/show.erb +5 -0
  75. data/app/cells/decidim/reported_content_cell.rb +44 -0
  76. data/app/cells/decidim/scopes_picker/scope_picker_prompt.erb +3 -0
  77. data/app/cells/decidim/scopes_picker/scope_picker_values.erb +5 -0
  78. data/app/cells/decidim/scopes_picker/show.erb +14 -0
  79. data/app/cells/decidim/scopes_picker_cell.rb +93 -0
  80. data/app/cells/decidim/tos_page/announcement.erb +1 -1
  81. data/app/cells/decidim/tos_page/form.erb +15 -13
  82. data/app/cells/decidim/tos_page_cell.rb +10 -8
  83. data/app/cells/decidim/translation_bar_cell.rb +1 -1
  84. data/app/cells/decidim/user_conversation/conversation_header.erb +1 -1
  85. data/app/cells/decidim/user_conversations_cell.rb +1 -1
  86. data/app/commands/decidim/create_report.rb +11 -1
  87. data/app/commands/decidim/create_user_report.rb +67 -0
  88. data/app/commands/decidim/destroy_account.rb +0 -2
  89. data/app/commands/decidim/gallery_methods.rb +2 -2
  90. data/app/commands/decidim/multiple_attachments_methods.rb +14 -10
  91. data/app/commands/decidim/search.rb +5 -2
  92. data/app/commands/decidim/update_notifications_settings.rb +1 -0
  93. data/app/commands/decidim/update_user_group.rb +1 -0
  94. data/app/controllers/concerns/decidim/devise_controllers.rb +1 -1
  95. data/app/controllers/concerns/decidim/flaggable.rb +5 -1
  96. data/app/controllers/concerns/decidim/force_authentication.rb +11 -3
  97. data/app/controllers/concerns/decidim/locale_switcher.rb +5 -0
  98. data/app/controllers/concerns/decidim/needs_permission.rb +7 -1
  99. data/app/controllers/concerns/decidim/orderable.rb +3 -1
  100. data/app/controllers/concerns/decidim/user_blocked_checker.rb +26 -0
  101. data/app/controllers/decidim/application_controller.rb +22 -0
  102. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +3 -1
  103. data/app/controllers/decidim/devise/sessions_controller.rb +10 -6
  104. data/app/controllers/decidim/errors_controller.rb +1 -1
  105. data/app/controllers/decidim/locales_controller.rb +1 -1
  106. data/app/controllers/decidim/profiles_controller.rb +6 -0
  107. data/app/controllers/decidim/report_users_controller.rb +42 -0
  108. data/app/controllers/decidim/scopes_controller.rb +19 -10
  109. data/app/controllers/decidim/timeouts_controller.rb +28 -0
  110. data/app/controllers/decidim/user_activities_controller.rb +5 -0
  111. data/app/controllers/decidim/user_timeline_controller.rb +1 -0
  112. data/app/events/decidim/demoted_membership_event.rb +2 -2
  113. data/app/events/decidim/invited_to_group_event.rb +2 -2
  114. data/app/events/decidim/join_request_accepted_event.rb +2 -2
  115. data/app/events/decidim/join_request_created_event.rb +2 -2
  116. data/app/events/decidim/join_request_rejected_event.rb +2 -2
  117. data/app/events/decidim/promoted_to_admin_event.rb +2 -2
  118. data/app/events/decidim/removed_from_group_event.rb +2 -2
  119. data/app/forms/decidim/account_form.rb +2 -2
  120. data/app/forms/decidim/invite_user_form.rb +2 -2
  121. data/app/forms/decidim/messaging/conversation_form.rb +1 -1
  122. data/app/forms/decidim/messaging/message_form.rb +1 -1
  123. data/app/forms/decidim/notifications_settings_form.rb +20 -0
  124. data/app/forms/url_validator.rb +20 -0
  125. data/app/helpers/decidim/action_authorization_helper.rb +2 -0
  126. data/app/helpers/decidim/application_helper.rb +1 -3
  127. data/app/helpers/decidim/cells_helper.rb +6 -0
  128. data/app/helpers/decidim/filters_helper.rb +9 -0
  129. data/app/helpers/decidim/messaging/conversation_helper.rb +11 -1
  130. data/app/helpers/decidim/newsletters_helper.rb +7 -9
  131. data/app/helpers/decidim/scopes_helper.rb +1 -1
  132. data/app/jobs/decidim/block_user_job.rb +11 -0
  133. data/app/jobs/decidim/export_job.rb +2 -2
  134. data/app/jobs/decidim/find_and_update_descendants_job.rb +48 -0
  135. data/app/jobs/decidim/machine_translation_resource_job.rb +3 -0
  136. data/app/jobs/decidim/machine_translation_save_job.rb +29 -0
  137. data/app/jobs/decidim/update_search_indexes_job.rb +11 -0
  138. data/app/jobs/decidim/user_report_job.rb +11 -0
  139. data/app/mailers/decidim/block_user_mailer.rb +21 -0
  140. data/app/mailers/decidim/reported_mailer.rb +33 -3
  141. data/app/mailers/decidim/user_report_mailer.rb +21 -0
  142. data/app/models/decidim/area.rb +0 -1
  143. data/app/models/decidim/area_type.rb +1 -1
  144. data/app/models/decidim/attachment.rb +3 -2
  145. data/app/models/decidim/attachment_collection.rb +1 -1
  146. data/app/models/decidim/authorization.rb +4 -0
  147. data/app/models/decidim/category.rb +6 -1
  148. data/app/models/decidim/impersonation_log.rb +5 -7
  149. data/app/models/decidim/metric.rb +2 -2
  150. data/app/models/decidim/moderation.rb +12 -0
  151. data/app/models/decidim/organization.rb +5 -1
  152. data/app/models/decidim/scope.rb +5 -2
  153. data/app/models/decidim/scope_type.rb +1 -1
  154. data/app/models/decidim/share_token.rb +1 -1
  155. data/app/models/decidim/static_page.rb +11 -1
  156. data/app/models/decidim/static_page_topic.rb +4 -0
  157. data/app/models/decidim/user.rb +13 -8
  158. data/app/models/decidim/user_base_entity.rb +13 -13
  159. data/app/models/decidim/user_block.rb +10 -0
  160. data/app/models/decidim/user_group.rb +1 -4
  161. data/app/models/decidim/user_moderation.rb +22 -0
  162. data/app/models/decidim/user_report.rb +31 -0
  163. data/app/permissions/decidim/permissions.rb +1 -3
  164. data/app/permissions/decidim/report_user_permissions.rb +13 -0
  165. data/app/presenters/decidim/admin_log/impersonation_log_presenter.rb +39 -0
  166. data/app/presenters/decidim/admin_log/organization_presenter.rb +1 -2
  167. data/app/presenters/decidim/admin_log/user_moderation_presenter.rb +63 -0
  168. data/app/presenters/decidim/admin_log/user_presenter.rb +18 -9
  169. data/app/presenters/decidim/home_stats_presenter.rb +3 -3
  170. data/app/presenters/decidim/log/diff_presenter.rb +4 -3
  171. data/app/presenters/decidim/log/resource_presenter.rb +4 -4
  172. data/app/presenters/decidim/log/user_presenter.rb +1 -1
  173. data/app/presenters/decidim/menu_presenter.rb +12 -7
  174. data/app/presenters/decidim/nil_presenter.rb +0 -2
  175. data/app/presenters/decidim/user_presenter.rb +1 -1
  176. data/app/queries/decidim/metrics/blocked_users_metric_manage.rb +26 -0
  177. data/app/queries/decidim/metrics/followers_metric_manage.rb +3 -0
  178. data/app/queries/decidim/metrics/participants_metric_manage.rb +3 -0
  179. data/app/queries/decidim/metrics/reported_users_metric_manage.rb +26 -0
  180. data/app/queries/decidim/metrics/user_reports_metric_manage.rb +26 -0
  181. data/app/queries/decidim/user_groups/accepted_memberships.rb +1 -1
  182. data/app/queries/decidim/user_groups/admin_memberships.rb +1 -1
  183. data/app/queries/decidim/user_groups/member_memberships.rb +1 -1
  184. data/app/services/decidim/activity_search.rb +1 -3
  185. data/app/services/decidim/base_diff_renderer.rb +1 -1
  186. data/app/services/decidim/data_portability_exporter.rb +1 -0
  187. data/app/services/decidim/email_notification_generator.rb +2 -2
  188. data/app/services/decidim/events_manager.rb +1 -1
  189. data/app/services/decidim/open_data_exporter.rb +36 -7
  190. data/app/services/decidim/zip_stream/zip_stream_writer.rb +3 -3
  191. data/app/uploaders/decidim/application_uploader.rb +22 -2
  192. data/app/uploaders/decidim/attachment_uploader.rb +2 -4
  193. data/app/uploaders/decidim/downloader.rb +9 -0
  194. data/app/uploaders/decidim/image_uploader.rb +9 -21
  195. data/app/uploaders/decidim/open_data_uploader.rb +5 -0
  196. data/app/uploaders/decidim/record_image_uploader.rb +2 -2
  197. data/app/validators/etiquette_validator.rb +0 -7
  198. data/app/validators/uploader_content_type_validator.rb +4 -2
  199. data/app/views/decidim/application/_document.html.erb +1 -1
  200. data/app/views/decidim/block_user_mailer/notify.html.erb +7 -0
  201. data/app/views/decidim/devise/confirmations/new.html.erb +1 -1
  202. data/app/views/decidim/devise/registrations/edit.html.erb +1 -1
  203. data/app/views/decidim/devise/unlocks/new.html.erb +1 -1
  204. data/app/views/decidim/messaging/conversations/_conversation.html.erb +1 -1
  205. data/app/views/decidim/messaging/conversations/_messages.html.erb +1 -1
  206. data/app/views/decidim/messaging/conversations/_show.html.erb +4 -4
  207. data/app/views/decidim/notifications_settings/show.html.erb +11 -0
  208. data/app/views/decidim/pages/_standalone.html.erb +3 -1
  209. data/app/views/decidim/reported_mailer/report.html.erb +9 -17
  210. data/app/views/decidim/shared/_check_boxes_tree.html.erb +3 -3
  211. data/app/views/decidim/shared/_component_announcement.html.erb +2 -2
  212. data/app/views/decidim/shared/participatory_space_filters/_filters.html.erb +1 -1
  213. data/app/views/decidim/user_report_mailer/notify.html.erb +7 -0
  214. data/app/views/decidim/widgets/_data_picker.html.erb +1 -1
  215. data/app/views/layouts/decidim/_application.html.erb +1 -0
  216. data/app/views/layouts/decidim/_js_configuration.html.erb +1 -1
  217. data/app/views/layouts/decidim/_main_footer.html.erb +6 -4
  218. data/app/views/layouts/decidim/_timeout_modal.html.erb +21 -0
  219. data/config/initializers/active_support.rb +7 -0
  220. data/config/initializers/devise.rb +1 -1
  221. data/config/initializers/omniauth.rb +1 -1
  222. data/config/locales/ar.yml +1 -7
  223. data/config/locales/bg.yml +1 -13
  224. data/config/locales/ca.yml +46 -17
  225. data/config/locales/cs.yml +118 -53
  226. data/config/locales/de.yml +83 -18
  227. data/config/locales/el.yml +1 -14
  228. data/config/locales/en.yml +79 -14
  229. data/config/locales/eo.yml +0 -1
  230. data/config/locales/es-MX.yml +31 -14
  231. data/config/locales/es-PY.yml +31 -14
  232. data/config/locales/es.yml +34 -17
  233. data/config/locales/eu.yml +4 -10
  234. data/config/locales/fi-plain.yml +80 -16
  235. data/config/locales/fi.yml +85 -21
  236. data/config/locales/fr-CA.yml +79 -14
  237. data/config/locales/fr.yml +76 -11
  238. data/config/locales/gl.yml +1 -15
  239. data/config/locales/hu.yml +1 -12
  240. data/config/locales/id-ID.yml +1 -7
  241. data/config/locales/is-IS.yml +0 -9
  242. data/config/locales/it.yml +72 -19
  243. data/config/locales/ja.yml +1 -14
  244. data/config/locales/lv.yml +1 -12
  245. data/config/locales/nl.yml +38 -13
  246. data/config/locales/no.yml +7 -14
  247. data/config/locales/pl.yml +81 -14
  248. data/config/locales/pt-BR.yml +1 -7
  249. data/config/locales/pt.yml +1 -14
  250. data/config/locales/ro-RO.yml +15 -25
  251. data/config/locales/ru.yml +7 -12
  252. data/config/locales/sk.yml +2 -13
  253. data/config/locales/sr-CS.yml +0 -9
  254. data/config/locales/sv.yml +5 -27
  255. data/config/locales/tr-TR.yml +65 -14
  256. data/config/locales/uk.yml +7 -9
  257. data/config/locales/zh-CN.yml +1 -14
  258. data/config/routes.rb +9 -4
  259. data/db/migrate/20170713131206_add_admin_to_users.rb +1 -1
  260. data/db/migrate/20180206143340_fix_reference_for_all_resources.rb +2 -0
  261. data/db/migrate/20180314085339_rename_maximum_votes_per_proposal_to_threshold_per_proposal.rb +2 -2
  262. data/db/migrate/20200929171508_remove_show_statistics_from_organizations.rb +7 -0
  263. data/db/migrate/20201010124755_create_decidim_user_moderations.rb +12 -0
  264. data/db/migrate/20201010124756_create_decidim_user_reports.rb +16 -0
  265. data/db/migrate/20201010224433_add_suspension_fields_to_decidim_users.rb +8 -0
  266. data/db/migrate/20201011074641_create_decidim_user_suspensions.rb +14 -0
  267. data/db/migrate/20201011081626_add_current_suspension_id_to_decidim_users.rb +7 -0
  268. data/db/migrate/20201013071533_add_reported_content_to_moderations.rb +7 -0
  269. data/db/migrate/20201019074554_add_locale_to_moderation_reports.rb +7 -0
  270. data/db/migrate/20201127114444_encrypt_authorization_metadatas.rb +35 -0
  271. data/db/migrate/20201128130723_add_allow_public_access_to_static_pages.rb +17 -0
  272. data/db/migrate/20201218144706_update_table_block_user_functionality.rb +8 -0
  273. data/db/migrate/20201218145252_rename_decidim_user_fields_for_block_functionality.rb +9 -0
  274. data/db/migrate/20210208134328_add_email_on_moderations_to_users.rb +7 -0
  275. data/db/seeds.rb +14 -13
  276. data/lib/decidim/amendable.rb +3 -2
  277. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_finder_base.rb +1 -1
  278. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_list.rb +4 -4
  279. data/{app/functions/decidim/core → lib/decidim/api/functions}/component_list_base.rb +3 -1
  280. data/lib/decidim/api/functions/needs_api_default_order.rb +24 -0
  281. data/{app/functions/decidim/core → lib/decidim/api/functions}/needs_api_filter_and_order.rb +0 -0
  282. data/{app/functions/decidim/core → lib/decidim/api/functions}/participatory_space_finder_base.rb +2 -2
  283. data/{app/functions/decidim/core → lib/decidim/api/functions}/participatory_space_list_base.rb +3 -1
  284. data/{app/functions/decidim/core → lib/decidim/api/functions}/user_entity_finder.rb +1 -4
  285. data/{app/functions/decidim/core → lib/decidim/api/functions}/user_entity_list.rb +1 -3
  286. data/{app/types/decidim/core → lib/decidim/api/input_filters}/base_input_filter.rb +0 -0
  287. data/{app/types/decidim/core → lib/decidim/api/input_filters}/component_input_filter.rb +20 -22
  288. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_hastaggable_input_filter.rb +1 -1
  289. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_localized_input_filter.rb +3 -3
  290. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_publishable_input_filter.rb +6 -6
  291. data/{app/types/decidim/core → lib/decidim/api/input_filters}/has_timestamp_input_filter.rb +12 -12
  292. data/{app/types/decidim/core → lib/decidim/api/input_filters}/participatory_space_input_filter.rb +0 -1
  293. data/lib/decidim/api/input_filters/user_entity_input_filter.rb +89 -0
  294. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/base_input_sort.rb +3 -2
  295. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/component_input_sort.rb +10 -11
  296. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_endorsable_input_sort.rb +2 -4
  297. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_localized_input_sort.rb +3 -3
  298. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/has_publishable_input_sort.rb +1 -1
  299. data/lib/decidim/api/input_sorts/has_timestamp_input_sort.rb +12 -0
  300. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/participatory_space_input_sort.rb +1 -1
  301. data/{app/types/decidim/core → lib/decidim/api/input_sorts}/user_entity_input_sort.rb +4 -4
  302. data/lib/decidim/api/{amendable_entity_interface.rb → interfaces/amendable_entity_interface.rb} +5 -5
  303. data/lib/decidim/api/interfaces/amendable_interface.rb +17 -0
  304. data/lib/decidim/api/{attachable_interface.rb → interfaces/attachable_interface.rb} +3 -3
  305. data/lib/decidim/api/interfaces/author_interface.rb +32 -0
  306. data/lib/decidim/api/interfaces/authorable_interface.rb +23 -0
  307. data/lib/decidim/api/{categorizable_interface.rb → interfaces/categorizable_interface.rb} +3 -3
  308. data/lib/decidim/api/interfaces/coauthorable_interface.rb +30 -0
  309. data/lib/decidim/api/interfaces/component_interface.rb +22 -0
  310. data/lib/decidim/api/interfaces/endorsable_interface.rb +19 -0
  311. data/lib/decidim/api/{fingerprint_interface.rb → interfaces/fingerprint_interface.rb} +3 -3
  312. data/lib/decidim/api/interfaces/participatory_space_interface.rb +48 -0
  313. data/lib/decidim/api/interfaces/participatory_space_resourceable_interface.rb +25 -0
  314. data/lib/decidim/api/{scopable_interface.rb → interfaces/scopable_interface.rb} +3 -3
  315. data/lib/decidim/api/interfaces/timestamps_interface.rb +15 -0
  316. data/lib/decidim/api/interfaces/traceable_interface.rb +14 -0
  317. data/lib/decidim/api/scalars/date_time_type.rb +17 -0
  318. data/lib/decidim/api/scalars/date_type.rb +17 -0
  319. data/lib/decidim/api/types/amendment_type.rb +19 -0
  320. data/lib/decidim/api/types/area_api_type.rb +16 -0
  321. data/lib/decidim/api/types/area_type_type.rb +13 -0
  322. data/lib/decidim/api/types/attachment_type.rb +13 -0
  323. data/lib/decidim/api/types/category_type.rb +14 -0
  324. data/{app/types/decidim/core → lib/decidim/api/types}/component_type.rb +2 -4
  325. data/lib/decidim/api/types/coordinates_type.rb +21 -0
  326. data/lib/decidim/api/types/decidim_type.rb +13 -0
  327. data/lib/decidim/api/types/fingerprint_type.rb +12 -0
  328. data/lib/decidim/api/types/hashtag_type.rb +13 -0
  329. data/lib/decidim/api/types/localized_string_type.rb +13 -0
  330. data/lib/decidim/api/types/metric_history_type.rb +18 -0
  331. data/lib/decidim/api/types/metric_type.rb +13 -0
  332. data/lib/decidim/api/types/organization_type.rb +17 -0
  333. data/lib/decidim/api/types/participatory_space_link_type.rb +22 -0
  334. data/lib/decidim/api/types/participatory_space_type.rb +10 -0
  335. data/lib/decidim/api/types/scope_api_type.rb +16 -0
  336. data/lib/decidim/api/types/session_type.rb +22 -0
  337. data/lib/decidim/api/types/statistic_type.rb +20 -0
  338. data/lib/decidim/api/types/trace_version_type.rb +21 -0
  339. data/lib/decidim/api/types/translated_field_type.rb +36 -0
  340. data/lib/decidim/api/types/user_group_type.rb +64 -0
  341. data/lib/decidim/api/types/user_type.rb +67 -0
  342. data/lib/decidim/attachment_attributes.rb +57 -0
  343. data/lib/decidim/attributes/clean_string.rb +37 -0
  344. data/lib/decidim/attributes.rb +1 -0
  345. data/lib/decidim/coauthorable.rb +3 -3
  346. data/lib/decidim/component_manifest.rb +17 -0
  347. data/lib/decidim/content_block_manifest.rb +1 -1
  348. data/lib/decidim/content_parsers/hashtag_parser.rb +3 -6
  349. data/lib/decidim/content_parsers/user_group_parser.rb +2 -5
  350. data/lib/decidim/content_parsers/user_parser.rb +2 -5
  351. data/lib/decidim/content_processor.rb +1 -1
  352. data/lib/decidim/content_renderers/hashtag_renderer.rb +3 -6
  353. data/lib/decidim/core/api.rb +71 -16
  354. data/lib/decidim/core/engine.rb +35 -6
  355. data/lib/decidim/core/test/factories.rb +53 -15
  356. data/lib/decidim/core/test/shared_examples/admin_resource_gallery_examples.rb +1 -1
  357. data/lib/decidim/core/test/shared_examples/amendable/amendment_accepted_event_examples.rb +1 -1
  358. data/lib/decidim/core/test/shared_examples/amendable/amendment_promoted_event_examples.rb +1 -1
  359. data/lib/decidim/core/test/shared_examples/amendable/amendment_rejected_event_examples.rb +1 -1
  360. data/lib/decidim/core/test/shared_examples/categorizable_interface_examples.rb +6 -14
  361. data/lib/decidim/core/test/shared_examples/comments_examples.rb +11 -9
  362. data/lib/decidim/core/test/shared_examples/component_type.rb +1 -1
  363. data/lib/decidim/core/test/shared_examples/controller_render_views.rb +28 -0
  364. data/lib/decidim/core/test/shared_examples/follows_examples.rb +1 -1
  365. data/lib/decidim/core/test/shared_examples/logo_email.rb +1 -1
  366. data/lib/decidim/core/test/shared_examples/map_examples.rb +1 -1
  367. data/lib/decidim/core/test/shared_examples/process_announcements_examples.rb +1 -1
  368. data/lib/decidim/core/test/shared_examples/reportable.rb +8 -0
  369. data/lib/decidim/core/test/shared_examples/rich_text_editor_examples.rb +1 -1
  370. data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +2 -3
  371. data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +46 -0
  372. data/lib/decidim/core/test/shared_examples/static_pages_examples.rb +43 -0
  373. data/lib/decidim/core/test.rb +2 -0
  374. data/lib/decidim/core/version.rb +1 -1
  375. data/lib/decidim/core.rb +11 -3
  376. data/lib/decidim/diffy_extension.rb +2 -2
  377. data/lib/decidim/exporters/csv.rb +3 -2
  378. data/lib/decidim/exporters/export_data.rb +1 -1
  379. data/lib/decidim/faker/internet.rb +17 -0
  380. data/lib/decidim/faker/localized.rb +43 -20
  381. data/lib/decidim/file_validator_humanizer.rb +6 -4
  382. data/lib/decidim/form_builder.rb +33 -22
  383. data/lib/decidim/gamification/badge_scorer.rb +3 -2
  384. data/lib/decidim/gamification/base_event.rb +2 -2
  385. data/lib/decidim/geocodable.rb +2 -0
  386. data/lib/decidim/has_category.rb +1 -1
  387. data/lib/decidim/has_private_users.rb +1 -1
  388. data/lib/decidim/importers/import_manifest.rb +36 -0
  389. data/lib/decidim/map/autocomplete.rb +11 -1
  390. data/lib/decidim/metric_operation.rb +5 -6
  391. data/lib/decidim/participatory_space_resourceable.rb +1 -3
  392. data/lib/decidim/query_extensions.rb +90 -69
  393. data/lib/decidim/randomable.rb +6 -1
  394. data/lib/decidim/record_encryptor.rb +131 -0
  395. data/lib/decidim/reportable.rb +26 -0
  396. data/lib/decidim/resource_manifest.rb +3 -0
  397. data/lib/decidim/resourceable.rb +6 -6
  398. data/lib/decidim/scopable.rb +1 -1
  399. data/lib/decidim/search_resource_fields_mapper.rb +1 -1
  400. data/lib/decidim/searchable.rb +9 -0
  401. data/lib/decidim/settings_manifest.rb +2 -1
  402. data/lib/decidim/shareable_with_token.rb +0 -1
  403. data/lib/decidim/translatable_attributes.rb +2 -1
  404. data/lib/decidim/translatable_resource.rb +10 -0
  405. data/lib/decidim/user_reportable.rb +33 -0
  406. data/lib/decidim/view_model.rb +26 -0
  407. data/lib/premailer/adapter/decidim.rb +4 -4
  408. data/lib/tasks/decidim_data_portability_tasks.rake +4 -4
  409. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ko.js +18 -0
  410. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.vi.js +14 -0
  411. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.zh-CN.js +14 -0
  412. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.zh-TW.js +14 -0
  413. metadata +190 -95
  414. data/app/functions/decidim/core/participatory_space_finder.rb +0 -11
  415. data/app/functions/decidim/core/participatory_space_list.rb +0 -11
  416. data/app/helpers/decidim/cache_helper.rb +0 -14
  417. data/app/types/decidim/core/amendment_type.rb +0 -26
  418. data/app/types/decidim/core/area_api_type.rb +0 -16
  419. data/app/types/decidim/core/area_type_type.rb +0 -14
  420. data/app/types/decidim/core/attachment_type.rb +0 -14
  421. data/app/types/decidim/core/category_type.rb +0 -16
  422. data/app/types/decidim/core/coordinates_type.rb +0 -19
  423. data/app/types/decidim/core/date_time_type.rb +0 -12
  424. data/app/types/decidim/core/date_type.rb +0 -13
  425. data/app/types/decidim/core/decidim_type.rb +0 -19
  426. data/app/types/decidim/core/fingerprint_type.rb +0 -15
  427. data/app/types/decidim/core/has_timestamp_input_sort.rb +0 -12
  428. data/app/types/decidim/core/hashtag_type.rb +0 -13
  429. data/app/types/decidim/core/localized_string_type.rb +0 -14
  430. data/app/types/decidim/core/metric_history_type.rb +0 -17
  431. data/app/types/decidim/core/metric_type.rb +0 -14
  432. data/app/types/decidim/core/organization_type.rb +0 -20
  433. data/app/types/decidim/core/participatory_space_link_type.rb +0 -24
  434. data/app/types/decidim/core/participatory_space_type.rb +0 -12
  435. data/app/types/decidim/core/scope_api_type.rb +0 -16
  436. data/app/types/decidim/core/session_type.rb +0 -19
  437. data/app/types/decidim/core/statistic_type.rb +0 -22
  438. data/app/types/decidim/core/trace_version_type.rb +0 -29
  439. data/app/types/decidim/core/translated_field_type.rb +0 -45
  440. data/app/types/decidim/core/user_entity_input_filter.rb +0 -81
  441. data/app/types/decidim/core/user_group_type.rb +0 -51
  442. data/app/types/decidim/core/user_type.rb +0 -52
  443. data/app/views/decidim/shared/_announcement.html.erb +0 -1
  444. data/app/views/decidim/shared/_flag_modal.html.erb +0 -20
  445. data/db/migrate/20210302150803_invalidate_all_sessions_for_deleted_users.rb +0 -11
  446. data/lib/decidim/api/amendable_interface.rb +0 -18
  447. data/lib/decidim/api/author_interface.rb +0 -29
  448. data/lib/decidim/api/authorable_interface.rb +0 -22
  449. data/lib/decidim/api/coauthorable_interface.rb +0 -29
  450. data/lib/decidim/api/component_interface.rb +0 -20
  451. data/lib/decidim/api/endorsable_interface.rb +0 -22
  452. data/lib/decidim/api/participatory_space_interface.rb +0 -47
  453. data/lib/decidim/api/participatory_space_resourceable_interface.rb +0 -21
  454. data/lib/decidim/api/timestamps_interface.rb +0 -21
  455. data/lib/decidim/api/traceable_interface.rb +0 -14
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "decidim/api/component_interface"
4
- require "decidim/api/participatory_space_interface"
5
-
6
3
  module Decidim
7
4
  # This module's job is to extend the API with custom fields related to
8
5
  # decidim-core.
@@ -12,91 +9,115 @@ module Decidim
12
9
  # type - A GraphQL::BaseType to extend.
13
10
  #
14
11
  # Returns nothing.
15
- def self.define(type)
16
- Decidim.participatory_space_manifests.each do |participatory_space_manifest|
17
- type.field participatory_space_manifest.name.to_s.camelize(:lower),
18
- type: type.types[participatory_space_manifest.query_type.constantize],
19
- description: "Lists all #{participatory_space_manifest.name}",
20
- function: participatory_space_manifest.query_list.constantize.new(manifest: participatory_space_manifest)
21
-
22
- type.field participatory_space_manifest.name.to_s.singularize.camelize(:lower),
23
- type: participatory_space_manifest.query_type.constantize,
24
- description: "Finds a #{participatory_space_manifest.name.to_s.singularize}",
25
- function: participatory_space_manifest.query_finder.constantize.new(manifest: participatory_space_manifest)
12
+ def self.included(type)
13
+ type.field :participatory_processes,
14
+ [Decidim::ParticipatoryProcesses::ParticipatoryProcessType],
15
+ null: true,
16
+ description: "Lists all participatory_processes" do
17
+ argument :filter, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputFilter, "This argument let's you filter the results", required: false
18
+ argument :order, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputSort, "This argument let's you order the results", required: false
26
19
  end
27
20
 
28
- type.field :component, Decidim::Core::ComponentInterface do
29
- description "Lists the components this space contains."
30
- argument :id, !types.ID, "The ID of the component to be found"
21
+ type.field :participatory_process,
22
+ Decidim::ParticipatoryProcesses::ParticipatoryProcessType,
23
+ null: true,
24
+ description: "Finds a participatory_process" do
25
+ argument :id, GraphQL::Types::ID, "The ID of the participatory space", required: false
26
+ argument :slug, String, "The slug of the participatory process", required: false
27
+ end
31
28
 
32
- resolve lambda { |_, args, ctx|
33
- component = Decidim::Component.published.find_by(id: args[:id])
34
- component&.organization == ctx[:current_organization] ? component : nil
35
- }
29
+ type.field :component, Decidim::Core::ComponentInterface, null: true do
30
+ description "Lists the components this space contains."
31
+ argument :id, GraphQL::Types::ID, required: true, description: "The ID of the component to be found"
36
32
  end
37
33
 
38
- type.field :session do
39
- type Core::SessionType
40
- description "Return's information about the logged in user"
34
+ type.field :session, Core::SessionType, description: "Return's information about the logged in user", null: true
41
35
 
42
- resolve lambda { |_obj, _args, ctx|
43
- ctx[:current_user]
44
- }
45
- end
36
+ type.field :decidim, Core::DecidimType, "Decidim's framework properties.", null: true
37
+
38
+ type.field :organization, Core::OrganizationType, "The current organization", null: true
46
39
 
47
- type.field :decidim, Core::DecidimType, "Decidim's framework properties." do
48
- resolve ->(_obj, _args, _ctx) { Decidim }
40
+ type.field :hashtags, [Core::HashtagType], null: true, description: "The hashtags for current organization" do
41
+ argument :name, GraphQL::Types::String, "The name of the hashtag", required: false
49
42
  end
50
43
 
51
- type.field :organization, Core::OrganizationType, "The current organization" do
52
- resolve ->(_obj, _args, ctx) { ctx[:current_organization] }
44
+ type.field :metrics, type: [Decidim::Core::MetricType], null: true do
45
+ argument :names, [GraphQL::Types::String], "The names of the metrics you want to retrieve", camelize: false, required: false
46
+ argument :space_type, GraphQL::Types::String, "The type of ParticipatorySpace you want to filter with", camelize: false, required: false
47
+ argument :space_id, GraphQL::Types::Int, "The ID of ParticipatorySpace you want to filter with", camelize: false, required: false
53
48
  end
54
49
 
55
- type.field :hashtags do
56
- type types[Core::HashtagType]
57
- description "The hashtags for current organization"
58
- argument :name, types.String, "The name of the hashtag"
50
+ type.field :user,
51
+ type: Core::AuthorInterface, null: true,
52
+ description: "A participant (user or group) in the current organization" do
53
+ argument :id, GraphQL::Types::ID, "The ID of the participant", required: false
54
+ argument :nickname, GraphQL::Types::String, "The @nickname of the participant", required: false
55
+ end
59
56
 
60
- resolve lambda { |_obj, args, ctx|
61
- Decidim::HashtagsResolver.new(ctx[:current_organization], args[:name]).hashtags
62
- }
57
+ type.field :users,
58
+ type: [Core::AuthorInterface], null: true,
59
+ description: "The participants (users or groups) for the current organization" do
60
+ argument :order, Decidim::Core::UserEntityInputSort, "Provides several methods to order the results", required: false
61
+ argument :filter, Decidim::Core::UserEntityInputFilter, "Provides several methods to filter the results", required: false
63
62
  end
63
+ end
64
64
 
65
- type.field :metrics do
66
- type types[Decidim::Core::MetricType]
67
- argument :names, types[types.String], "The names of the metrics you want to retrieve"
68
- argument :space_type, types.String, "The type of ParticipatorySpace you want to filter with"
69
- argument :space_id, types.Int, "The ID of ParticipatorySpace you want to filter with"
70
-
71
- resolve lambda { |_, args, ctx|
72
- manifests = if args[:names].blank?
73
- Decidim.metrics_registry.all
74
- else
75
- Decidim.metrics_registry.all.select do |manifest|
76
- args[:names].include?(manifest.metric_name.to_s)
77
- end
78
- end
79
- filters = {}
80
- if args[:space_type].present? && args[:space_id].present?
81
- filters[:participatory_space_type] = args[:space_type]
82
- filters[:participatory_space_id] = args[:space_id]
83
- end
65
+ def participatory_processes(filter: {}, order: {})
66
+ manifest = Decidim.participatory_space_manifests.select { |m| m.name == :participatory_processes }.first
67
+ Decidim::Core::ParticipatorySpaceListBase.new(manifest: manifest).call(object, { filter: filter, order: order }, context)
68
+ end
69
+
70
+ def participatory_process(id: nil, slug: nil)
71
+ manifest = Decidim.participatory_space_manifests.select { |m| m.name == :participatory_processes }.first
72
+ Decidim::Core::ParticipatorySpaceFinderBase.new(manifest: manifest).call(object, { id: id, slug: slug }, context)
73
+ end
74
+
75
+ def component(id: {})
76
+ component = Decidim::Component.published.find_by(id: id)
77
+ component&.organization == context[:current_organization] ? component : nil
78
+ end
79
+
80
+ def session
81
+ context[:current_user]
82
+ end
83
+
84
+ def decidim
85
+ Decidim
86
+ end
87
+
88
+ def organization
89
+ context[:current_organization]
90
+ end
84
91
 
85
- manifests.map do |manifest|
86
- Decidim::Core::MetricResolver.new(manifest.metric_name, ctx[:current_organization], filters)
92
+ def hashtags(name: nil)
93
+ Decidim::HashtagsResolver.new(context[:current_organization], name).hashtags
94
+ end
95
+
96
+ def metrics(names: [], space_type: nil, space_id: nil)
97
+ manifests = if names.blank?
98
+ Decidim.metrics_registry.all
99
+ else
100
+ Decidim.metrics_registry.all.select do |manifest|
101
+ names.include?(manifest.metric_name.to_s)
102
+ end
87
103
  end
88
- }
104
+ filters = {}
105
+ if space_type.present? && space_id.present?
106
+ filters[:participatory_space_type] = space_type
107
+ filters[:participatory_space_id] = space_id
89
108
  end
90
109
 
91
- type.field :user,
92
- type: Core::AuthorInterface,
93
- description: "A participant (user or group) in the current organization",
94
- function: Core::UserEntityFinder.new
110
+ manifests.map do |manifest|
111
+ Decidim::Core::MetricResolver.new(manifest.metric_name, context[:current_organization], filters)
112
+ end
113
+ end
95
114
 
96
- type.field :users,
97
- type: type.types[Core::AuthorInterface],
98
- description: "The participants (users or groups) for the current organization",
99
- function: Core::UserEntityList.new
115
+ def user(id: nil, nickname: nil)
116
+ Core::UserEntityFinder.new.call(object, { id: id, nickname: nickname }, context)
117
+ end
118
+
119
+ def users(filter: {}, order: {})
120
+ Core::UserEntityList.new.call(object, { filter: filter, order: order }, context)
100
121
  end
101
122
  end
102
123
  end
@@ -12,7 +12,12 @@ module Decidim
12
12
  def order_randomly(seed)
13
13
  transaction do
14
14
  connection.execute("SELECT setseed(#{connection.quote(seed)})")
15
- order(Arel.sql("RANDOM()")).load
15
+ # Include the record IDs as a base number for the order calculation
16
+ # in order to avoid PostgreSQL random ordering when the records are
17
+ # updated. PostgreSQL can randomly change the base ordering in case
18
+ # the records are changed which is not desired as we want consistent
19
+ # orders for the records.
20
+ order(arel_table[primary_key] * Arel.sql("RANDOM()")).load
16
21
  end
17
22
  end
18
23
  end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # A concern that provides attribute encryption e.g. to active record models.
7
+ #
8
+ # Use this e.g. in models as follows:
9
+ #
10
+ # class Example < ApplicationRecord
11
+ # include Decidim::RecordEncryptor
12
+ #
13
+ # encrypt_attribute :name, type: :string
14
+ # encrypt_attribute :metadata, type: :hash
15
+ # end
16
+ module RecordEncryptor
17
+ extend ActiveSupport::Concern
18
+
19
+ included do
20
+ # Store the encrypted attributes in a class accessor
21
+ cattr_accessor :encrypted_attributes
22
+
23
+ before_save :ensure_encrypted_attributes if respond_to?(:before_save)
24
+ end
25
+
26
+ class_methods do
27
+ # Public: Defines an attribute that should be encrypted
28
+ def encrypt_attribute(attribute, type:)
29
+ self.encrypted_attributes ||= []
30
+ raise "The attribute #{attribute} is already defined as encrypted" if encrypted_attributes.include?(attribute)
31
+
32
+ encrypted_attributes << attribute
33
+
34
+ # Defines the suffix for the encrypt and decrypt methods. E.g. when
35
+ # the `type` is `:hash`, method `decrypt_hash_values` would be called
36
+ # for decryption and `encrypt_hash_values` would be called for
37
+ # encryption.
38
+ method_suffix = begin
39
+ case type
40
+ when :hash
41
+ "hash_values"
42
+ else
43
+ "value"
44
+ end
45
+ end
46
+
47
+ # Dynamically defines the getter and setter for the encrypted attribute.
48
+ # E.g. when called as `encrypt_attribute :name, type: :string`, this
49
+ # would define the following methods:
50
+ #
51
+ # def name
52
+ # decrypt_value(super)
53
+ # end
54
+ #
55
+ # def name=(value)
56
+ # super(encrypt_value(value))
57
+ # end
58
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
59
+ def #{attribute}
60
+ return @#{attribute}_decrypted if instance_variable_defined?(:@#{attribute}_decrypted)
61
+
62
+ encrypted_value = begin
63
+ if defined?(super)
64
+ super
65
+ elsif instance_variable_defined?(:@#{attribute})
66
+ @#{attribute}
67
+ end
68
+ end
69
+ @#{attribute}_decrypted = decrypt_#{method_suffix}(encrypted_value)
70
+ end
71
+
72
+ def #{attribute}=(value)
73
+ remove_instance_variable(:@#{attribute}_decrypted) if instance_variable_defined?(:@#{attribute}_decrypted)
74
+ encrypted_value = encrypt_#{method_suffix}(value)
75
+
76
+ if defined?(super)
77
+ super(encrypted_value)
78
+ else
79
+ @#{attribute} = encrypted_value
80
+ end
81
+ end
82
+ RUBY
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ # Re-assign the encrypted attributes before save so they are also saved when
89
+ # they are modified without calling the accessors. This could happen e.g.
90
+ # for hashes which are modified directly as follows:
91
+ #
92
+ # record = Example.find(1)
93
+ # record.metadata["foo"] = "bar"
94
+ # record.save!
95
+ #
96
+ # This will also clear the cached attributes during saving so that next time
97
+ # they are accessed, they will be updated according to the stored values.
98
+ def ensure_encrypted_attributes
99
+ self.class.encrypted_attributes.each do |attr|
100
+ send("#{attr}=", send(attr))
101
+ end
102
+ end
103
+
104
+ def decrypt_value(value)
105
+ Decidim::AttributeEncryptor.decrypt(value)
106
+ rescue ActiveSupport::MessageEncryptor::InvalidMessage
107
+ # Support for legacy unencrypted values. This is necessary e.g. when
108
+ # migrating the original unencrypted values to encrypted values.
109
+ value
110
+ end
111
+
112
+ def encrypt_value(value)
113
+ Decidim::AttributeEncryptor.encrypt(value)
114
+ end
115
+
116
+ def decrypt_hash_values(hash)
117
+ return hash unless hash.is_a?(Hash)
118
+
119
+ hash.transform_values { |value| ActiveSupport::JSON.decode(decrypt_value(value)) }
120
+ end
121
+
122
+ def encrypt_hash_values(hash)
123
+ return hash unless hash.is_a?(Hash)
124
+
125
+ # The values are stored in JSON encoded format in order to match the
126
+ # PostgreSQL adapter's default functionality as you can see at:
127
+ # https://git.io/JkdYJ
128
+ hash.transform_values { |value| encrypt_value(ActiveSupport::JSON.encode(value)) }
129
+ end
130
+ end
131
+ end
@@ -42,6 +42,32 @@ module Decidim
42
42
  def reported_content_url
43
43
  raise NotImplementedError
44
44
  end
45
+
46
+ # Public: The collection of attribute names that are considered
47
+ # to be reportable.
48
+ def reported_attributes
49
+ raise NotImplementedError
50
+ end
51
+
52
+ # Public: An `Array` of `String` that will be concatenated to
53
+ # the reported searchable content. This content is used
54
+ # in the admin dashboard to filter moderations.
55
+ def reported_searchable_content_extras
56
+ []
57
+ end
58
+
59
+ # Public: The reported searchable content in a text format so
60
+ # moderations can be filtered by content.
61
+ def reported_searchable_content_text
62
+ reported_searchable_content_extras.concat(
63
+ reported_attributes.map do |attribute_name|
64
+ attribute_value = attributes.with_indifferent_access[attribute_name]
65
+ next attribute_value.values.join("\n") if attribute_value.is_a? Hash
66
+
67
+ attribute_value
68
+ end
69
+ ).join("\n")
70
+ end
45
71
  end
46
72
  end
47
73
  end
@@ -36,6 +36,9 @@ module Decidim
36
36
  # The main card to render an instance of the resource.
37
37
  attribute :card, String
38
38
 
39
+ # The reported content to render an instance of the resource.
40
+ attribute :reported_content_cell, String
41
+
39
42
  # Set this to `true` if you want this resource to be searchable. It requires
40
43
  # the model to include the `Decidim::Searchable` concern.
41
44
  attribute :searchable, Boolean, default: false
@@ -93,7 +93,7 @@ module Decidim
93
93
  # - the visibility of its participatory space.
94
94
  # - the visibility of the resource itself.
95
95
  def visible?
96
- !component.participatory_space.try(:private_space?) && component.published? && resource_visible?
96
+ component.participatory_space.try(:visible?) && component.published? && resource_visible?
97
97
  end
98
98
 
99
99
  # Check only the resource visibility not its hierarchy.
@@ -102,11 +102,11 @@ module Decidim
102
102
  #
103
103
  # @return If the resource is also Publicable checks if the resource is published, otherwise returns true by default.
104
104
  def resource_visible?
105
- if respond_to?(:published?)
106
- published?
107
- else
108
- true
109
- end
105
+ return !hidden? && published? if respond_to?(:hidden?) && respond_to?(:published?)
106
+ return published? if respond_to?(:published?)
107
+ return !hidden? if respond_to?(:hidden?)
108
+
109
+ true
110
110
  end
111
111
 
112
112
  # Public: Whether the permissions for this object actions can be set at resource level.
@@ -74,7 +74,7 @@ module Decidim
74
74
  def scope_belongs_to_organization
75
75
  return if !scope || !organization
76
76
 
77
- errors.add(:scope, :invalid) unless organization.scopes.where(id: scope.id).exists?
77
+ errors.add(:scope, :invalid) unless organization.scopes.exists?(id: scope.id)
78
78
  end
79
79
  end
80
80
  end
@@ -128,7 +128,7 @@ module Decidim
128
128
 
129
129
  content = Array.wrap(content).collect do |item|
130
130
  text = if item.is_a?(Hash)
131
- item.dig(locale).presence || item.dig("machine_translations", locale) || ""
131
+ item[locale].presence || item.dig("machine_translations", locale) || ""
132
132
  else
133
133
  item
134
134
  end
@@ -87,22 +87,31 @@ module Decidim
87
87
  return unless org
88
88
 
89
89
  searchables_in_org = searchable_resources.by_organization(org.id)
90
+
90
91
  if self.class.search_resource_fields_mapper.index_on_update?(self)
91
92
  if searchables_in_org.empty?
92
93
  add_to_index_as_search_resource
93
94
  else
94
95
  fields = self.class.search_resource_fields_mapper.mapped(self)
95
96
  searchables_in_org.find_each do |sr|
97
+ next if sr.blank?
98
+
96
99
  sr.update(contents_to_searchable_resource_attributes(fields, sr.locale))
97
100
  end
98
101
  end
99
102
  elsif searchables_in_org.any?
100
103
  searchables_in_org.destroy_all
101
104
  end
105
+
106
+ find_and_update_descendants
102
107
  end
103
108
 
104
109
  private
105
110
 
111
+ def find_and_update_descendants
112
+ Decidim::FindAndUpdateDescendantsJob.perform_later(self)
113
+ end
114
+
106
115
  def contents_to_searchable_resource_attributes(fields, locale)
107
116
  contents = fields[:i18n][locale]
108
117
  content_a = I18n.transliterate(contents[:A] || "")
@@ -95,7 +95,8 @@ module Decidim
95
95
  text: { klass: String, default: nil },
96
96
  array: { klass: Array, default: [] },
97
97
  enum: { klass: String, default: nil },
98
- scope: { klass: Integer, default: nil }
98
+ scope: { klass: Integer, default: nil },
99
+ time: { klass: Time, default: nil }
99
100
  }.freeze
100
101
 
101
102
  attribute :type, Symbol, default: :boolean
@@ -12,7 +12,6 @@ module Decidim
12
12
  included do
13
13
  has_many :share_tokens,
14
14
  class_name: "Decidim::ShareToken",
15
- foreign_key: "token_for_id",
16
15
  foreign_type: "token_for_type",
17
16
  inverse_of: :token_for,
18
17
  as: :token_for,
@@ -43,7 +43,8 @@ module Decidim
43
43
 
44
44
  define_method attribute_name do
45
45
  field = public_send(name) || {}
46
- field[locale.to_s] || field[locale.to_sym]
46
+ value = field[locale.to_s] || field[locale.to_sym]
47
+ attribute_set[attribute_name].coerce(value)
47
48
  end
48
49
 
49
50
  define_method "#{attribute_name}=" do |value|
@@ -73,6 +73,16 @@ module Decidim
73
73
  errors.add(field, :invalid)
74
74
  end
75
75
  end
76
+
77
+ # Public: Returns the original language in which the resource was created or
78
+ # the organization's default locale.
79
+ def content_original_language
80
+ field_name = self.class.translatable_fields_list.first
81
+ field_value = self[field_name]
82
+ return field_value.except("machine_translations").keys.first if field_value && field_value.except("machine_translations").keys.count == 1
83
+
84
+ organization.default_locale
85
+ end
76
86
  end
77
87
  end
78
88
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # A concern with the components needed when you want a model to be reportable
7
+ module UserReportable
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ has_one :user_moderation, class_name: "Decidim::UserModeration", foreign_key: :decidim_user_id, dependent: :destroy
12
+ has_many :user_reports, through: :user_moderation, source: :reports, class_name: "Decidim::UserReport"
13
+
14
+ def report_count
15
+ user_moderation&.report_count.to_i
16
+ end
17
+
18
+ # Public: Check if the user has reported the reportable.
19
+ #
20
+ # Returns Boolean.
21
+ def reported_by?(user)
22
+ user_reports.where(user: user).any?
23
+ end
24
+
25
+ # Public: Checks if the reportable has been reported or not.
26
+ #
27
+ # Returns Boolean.
28
+ def reported?
29
+ report_count&.positive?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -13,17 +13,43 @@ module Decidim
13
13
  include Decidim::ActionAuthorization
14
14
  include Decidim::ActionAuthorizationHelper
15
15
  include Decidim::ReplaceButtonsHelper
16
+ include Cell::Caching::Notifications
16
17
  include Decidim::MarkupHelper
17
18
  include Decidim::FilterParamsHelper
18
19
 
19
20
  delegate :current_organization, to: :controller
20
21
 
22
+ cache :show, if: :perform_caching? do
23
+ cache_hash
24
+ end
25
+
21
26
  def current_user
22
27
  context&.dig(:current_user) || controller&.current_user
23
28
  end
24
29
 
30
+ def call(*)
31
+ identifier = self.class.name.sub(/Cell$/, "").underscore
32
+ instrument(:cell, identifier: identifier) do |_payload|
33
+ super
34
+ end
35
+ end
36
+
25
37
  private
26
38
 
39
+ def instrument(name, **options)
40
+ ActiveSupport::Notifications.instrument("render_#{name}.action_view", options) do |payload|
41
+ yield payload
42
+ end
43
+ end
44
+
45
+ def perform_caching?
46
+ cache_hash.present?
47
+ end
48
+
49
+ def cache_hash
50
+ nil
51
+ end
52
+
27
53
  def decidim
28
54
  Decidim::Core::Engine.routes.url_helpers
29
55
  end
@@ -16,10 +16,10 @@ class Premailer
16
16
  # @return [String] a plain text.
17
17
  def to_plain_text
18
18
  html_src = begin
19
- @doc.at("body").inner_html
20
- rescue StandardError
21
- ""
22
- end
19
+ @doc.at("body").inner_html
20
+ rescue StandardError
21
+ ""
22
+ end
23
23
 
24
24
  html_src = @doc.to_html unless html_src && html_src.present?
25
25
 
@@ -12,7 +12,7 @@ namespace :decidim do
12
12
  #
13
13
  desc "Deletes User records by ID using a CSV file"
14
14
  task right_to_be_forgotten: :environment do
15
- log = ActiveSupport::Logger.new(Rails.root.join("log", "right_to_be_forgotten.log"))
15
+ log = ActiveSupport::Logger.new(Rails.root.join("log/right_to_be_forgotten.log"))
16
16
  begin
17
17
  path = ENV["FILE_PATH"].presence || "tmp/forgotten_users.csv" # Good file
18
18
  file_path = Rails.root.join(path)
@@ -74,11 +74,11 @@ namespace :decidim do
74
74
  task delete_data_portability_files: :environment do
75
75
  puts "DELETE DATA PORTABILITY FILES: -------------- START"
76
76
  uploader = Decidim::DataPortabilityUploader.new
77
- case uploader.fog_provider
78
- when "fog" # file system
77
+ case uploader.provider
78
+ when "file" # file system
79
79
  puts "Deleting files from filesystem..."
80
80
  delete_data_portability_files_from_fs(uploader)
81
- when "fog/aws"
81
+ when "aws"
82
82
  puts "Deleting files from aws..."
83
83
  delete_data_portability_files_from_aws(uploader)
84
84
  else
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Korean translation for foundation-datepicker, language file from bootstrap-datepicker
3
+ * This is a port from https://github.com/moment/moment/blob/develop/src/locale/ko.js
4
+ */
5
+ ;(function($){
6
+ $.fn.fdatepicker.dates['ko'] = {
7
+ days: ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"],
8
+ daysShort: ["일", "월", "화", "수", "목", "금", "토"],
9
+ daysMin: ["일", "월", "화", "수", "목", "금", "토"],
10
+ months: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
11
+ monthsShort: ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
12
+ today: "오늘",
13
+ clear: "삭제",
14
+ format: "YYYY-MM-DD",
15
+ titleFormat: "yyyy년mm월",
16
+ weekStart: 0
17
+ };
18
+ }(jQuery));