decidim-decidim_awesome 0.10.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-decidim_awesome might be problematic. Click here for more details.

Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +177 -60
  4. data/app/cells/concerns/decidim/decidim_awesome/global_menu_cell_override.rb +20 -0
  5. data/app/cells/concerns/decidim/decidim_awesome/{proposal_m_cell_override.rb → proposal_l_cell_override.rb} +10 -4
  6. data/app/cells/decidim/decidim_awesome/content_blocks/map/show.erb +5 -12
  7. data/app/cells/decidim/decidim_awesome/content_blocks/map_cell.rb +9 -5
  8. data/app/cells/decidim/decidim_awesome/voting/proposal_metadata_cell.rb +54 -0
  9. data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal/modal.erb +18 -0
  10. data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal/show.erb +37 -32
  11. data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_cell.rb +9 -4
  12. data/app/commands/concerns/decidim/decidim_awesome/admin/needs_constraint_helpers.rb +2 -2
  13. data/app/commands/concerns/decidim/decidim_awesome/proposals/admin/update_proposal_override.rb +31 -0
  14. data/app/commands/concerns/decidim/decidim_awesome/proposals/create_collaborative_draft_override.rb +27 -0
  15. data/app/commands/concerns/decidim/decidim_awesome/proposals/create_proposal_override.rb +27 -0
  16. data/app/commands/concerns/decidim/decidim_awesome/proposals/update_collaborative_draft_override.rb +27 -0
  17. data/app/commands/concerns/decidim/decidim_awesome/proposals/update_proposal_override.rb +26 -0
  18. data/app/commands/decidim/decidim_awesome/admin/create_constraint.rb +1 -1
  19. data/app/commands/decidim/decidim_awesome/admin/create_proposal_custom_field.rb +4 -3
  20. data/app/commands/decidim/decidim_awesome/admin/destroy_custom_redirect.rb +1 -1
  21. data/app/commands/decidim/decidim_awesome/admin/destroy_menu_hack.rb +1 -1
  22. data/app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb +6 -3
  23. data/app/commands/decidim/decidim_awesome/admin/rename_scope_label.rb +1 -1
  24. data/app/commands/decidim/decidim_awesome/admin/update_constraint.rb +1 -1
  25. data/app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb +2 -2
  26. data/app/commands/decidim/decidim_awesome/command.rb +1 -7
  27. data/app/controllers/concerns/decidim/decidim_awesome/admin/maintenance_context.rb +43 -0
  28. data/app/controllers/concerns/decidim/decidim_awesome/admin_accountability/admin/filterable_helper.rb +1 -1
  29. data/app/controllers/concerns/decidim/decidim_awesome/content_security_policy.rb +34 -0
  30. data/app/controllers/concerns/decidim/decidim_awesome/limit_pending_amendments.rb +35 -0
  31. data/app/controllers/concerns/decidim/decidim_awesome/not_found_redirect.rb +1 -1
  32. data/app/controllers/concerns/decidim/decidim_awesome/proposals/proposal_votes_controller_override.rb +3 -3
  33. data/app/controllers/decidim/decidim_awesome/admin/application_controller.rb +2 -0
  34. data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +14 -10
  35. data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +10 -9
  36. data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +23 -20
  37. data/app/controllers/decidim/decidim_awesome/admin/custom_redirects_controller.rb +6 -10
  38. data/app/controllers/decidim/decidim_awesome/admin/maintenance_controller.rb +76 -0
  39. data/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +6 -10
  40. data/app/controllers/decidim/decidim_awesome/admin/proposal_custom_fields_controller.rb +14 -6
  41. data/app/controllers/decidim/decidim_awesome/admin/scoped_admins_controller.rb +2 -2
  42. data/app/controllers/decidim/decidim_awesome/admin/scoped_styles_controller.rb +2 -2
  43. data/app/controllers/decidim/decidim_awesome/blank_component_controller.rb +8 -3
  44. data/app/controllers/decidim/decidim_awesome/editor_images_controller.rb +3 -3
  45. data/app/controllers/decidim/decidim_awesome/iframe_component/iframe_controller.rb +18 -5
  46. data/app/forms/concerns/decidim/decidim_awesome/proposals/proposal_form_override.rb +21 -0
  47. data/app/forms/{decidim → concerns/decidim}/decidim_awesome/proposals/proposal_wizard_create_step_form_override.rb +2 -1
  48. data/app/forms/decidim/decidim_awesome/admin/config_form.rb +28 -14
  49. data/app/forms/decidim/decidim_awesome/admin/custom_redirect_form.rb +2 -2
  50. data/app/forms/decidim/decidim_awesome/admin/intergram_form.rb +4 -0
  51. data/app/forms/decidim/decidim_awesome/admin/menu_form.rb +4 -4
  52. data/app/helpers/concerns/decidim/decidim_awesome/amendments_helper_override.rb +65 -0
  53. data/app/helpers/concerns/decidim/decidim_awesome/breadcrumb_helper_override.rb +23 -0
  54. data/app/helpers/concerns/decidim/decidim_awesome/proposals/application_helper_override.rb +110 -0
  55. data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +6 -27
  56. data/app/helpers/decidim/decidim_awesome/map_helper.rb +8 -27
  57. data/app/jobs/decidim/decidim_awesome/destroy_private_data_job.rb +22 -0
  58. data/app/jobs/decidim/decidim_awesome/migrate_legacy_images_job.rb +5 -4
  59. data/app/middleware/decidim/decidim_awesome/current_config.rb +3 -5
  60. data/app/models/concerns/decidim/decidim_awesome/has_proposal_extra_fields.rb +39 -10
  61. data/app/models/decidim/decidim_awesome/awesome_config.rb +1 -1
  62. data/app/models/decidim/decidim_awesome/paper_trail_version.rb +3 -3
  63. data/app/models/decidim/decidim_awesome/proposal_extra_field.rb +35 -1
  64. data/app/models/decidim/decidim_awesome/vote_weight.rb +2 -2
  65. data/app/overrides/decidim/proposals/admin/proposals/show/add_private_body.html.erb.deface +7 -0
  66. data/app/overrides/decidim/proposals/admin/proposals/show/replace_body.html.erb.deface +5 -0
  67. data/app/overrides/decidim/proposals/proposals/_proposal_aside/limit_amendments_modal.html.erb.deface +5 -0
  68. data/app/overrides/decidim/proposals/proposals/_vote_button/replace_vote_button.html.erb.deface +1 -1
  69. data/app/overrides/layouts/decidim/_decidim_javascript/add_awesome_tags.html.erb.deface +6 -0
  70. data/app/overrides/layouts/decidim/_head/add_awesome_tags.html.erb.deface +4 -11
  71. data/app/overrides/layouts/decidim/admin/_header/{replace_scripts.html.erb.deface → add_awesome_tags.html.erb.deface} +4 -4
  72. data/app/packs/entrypoints/decidim_admin_decidim_awesome.js +1 -2
  73. data/app/packs/entrypoints/decidim_admin_decidim_awesome_global.js +4 -0
  74. data/app/packs/entrypoints/decidim_admin_decidim_awesome_global.scss +1 -0
  75. data/app/packs/entrypoints/decidim_decidim_awesome.js +2 -2
  76. data/app/packs/entrypoints/decidim_decidim_awesome_map.scss +1 -1
  77. data/app/packs/entrypoints/decidim_editor.js +14 -0
  78. data/app/packs/src/decidim/decidim_awesome/admin/auto_edit.js +96 -69
  79. data/app/packs/src/decidim/decidim_awesome/admin/check_redirections.js +46 -41
  80. data/app/packs/src/decidim/decidim_awesome/admin/codemirror.js +3 -3
  81. data/app/packs/src/decidim/decidim_awesome/admin/constraint_form_events.js +115 -0
  82. data/app/packs/src/decidim/decidim_awesome/admin/custom_fields_builder.js +9 -5
  83. data/app/packs/src/decidim/decidim_awesome/admin/form_exit_warn.js +22 -11
  84. data/app/packs/src/decidim/decidim_awesome/admin/proposal_sortings.js +26 -8
  85. data/app/packs/src/decidim/decidim_awesome/admin/tabs_change.js +31 -0
  86. data/app/packs/src/decidim/decidim_awesome/admin/user_picker.js +34 -21
  87. data/app/packs/src/decidim/decidim_awesome/amendments/show_modal_on_limits.js +28 -0
  88. data/app/packs/src/decidim/decidim_awesome/awesome_admin.js +5 -16
  89. data/app/packs/src/decidim/decidim_awesome/awesome_admin_global.js +1 -0
  90. data/app/packs/src/decidim/decidim_awesome/awesome_application.js +1 -15
  91. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/fetcher.js +33 -11
  92. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/meetings_fetcher.js +9 -12
  93. data/app/packs/src/decidim/decidim_awesome/awesome_map/api/proposals_fetcher.js +28 -0
  94. data/app/packs/src/decidim/decidim_awesome/awesome_map/awesome_map.js +3 -4
  95. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/controller.js +12 -12
  96. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/meetings_controller.js +11 -7
  97. data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/proposals_controller.js +6 -13
  98. data/app/packs/src/decidim/decidim_awesome/awesome_map/controls_ui.js +51 -20
  99. data/app/packs/src/decidim/decidim_awesome/awesome_map/load_map.js +27 -18
  100. data/app/packs/src/decidim/decidim_awesome/editor/index.js +94 -0
  101. data/app/packs/src/decidim/decidim_awesome/forms/autosave.js +28 -23
  102. data/app/packs/src/decidim/decidim_awesome/forms/custom_fields_renderer.js +29 -25
  103. data/app/packs/src/decidim/decidim_awesome/forms/rich_text_plugin.js +27 -32
  104. data/app/packs/src/decidim/decidim_awesome/proposals/custom_fields.js +31 -15
  105. data/app/packs/src/decidim/decidim_awesome/proposals/images.js +16 -10
  106. data/app/packs/src/decidim/decidim_awesome/voting/voting_cards.js +47 -38
  107. data/app/packs/stylesheets/decidim/decidim_awesome/admin/auto_edits.scss +11 -12
  108. data/app/packs/stylesheets/decidim/decidim_awesome/admin/check_redirections.scss +15 -0
  109. data/app/packs/stylesheets/decidim/decidim_awesome/admin/codemirror.scss +24 -12
  110. data/app/packs/stylesheets/decidim/decidim_awesome/admin/constraints.scss +49 -29
  111. data/app/packs/stylesheets/decidim/decidim_awesome/admin/custom_fields.scss +28 -71
  112. data/app/packs/stylesheets/decidim/decidim_awesome/admin/custom_styles.scss +48 -0
  113. data/app/packs/stylesheets/decidim/decidim_awesome/admin/intergram_fixes.scss +11 -0
  114. data/app/packs/stylesheets/decidim/decidim_awesome/admin/user_picker.scss +17 -26
  115. data/app/packs/stylesheets/decidim/decidim_awesome/amendments/modal.scss +5 -0
  116. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin.scss +11 -49
  117. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin_global.scss +19 -0
  118. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_application.scss +4 -19
  119. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_iframe/iframe.scss +1 -1
  120. data/app/packs/stylesheets/decidim/decidim_awesome/awesome_map/map.scss +41 -35
  121. data/app/packs/stylesheets/decidim/decidim_awesome/forms/autosave.scss +6 -6
  122. data/app/packs/stylesheets/decidim/decidim_awesome/forms/custom_fields.scss +118 -0
  123. data/app/packs/stylesheets/decidim/decidim_awesome/shared/spinner.scss +26 -0
  124. data/app/packs/stylesheets/decidim/decidim_awesome/voting/voting_cards.scss +41 -59
  125. data/app/permissions/decidim/decidim_awesome/admin/permissions.rb +14 -3
  126. data/app/permissions/decidim/decidim_awesome/permissions.rb +3 -4
  127. data/app/presenters/concerns/decidim/decidim_awesome/breadcrumb_root_menu_item_presenter_override.rb +23 -0
  128. data/app/presenters/{decidim → concerns/decidim}/decidim_awesome/menu_item_presenter_override.rb +10 -2
  129. data/app/presenters/{decidim → concerns/decidim}/decidim_awesome/menu_presenter_override.rb +8 -0
  130. data/app/presenters/concerns/decidim/decidim_awesome/proposals/proposal_presenter_override.rb +20 -0
  131. data/app/presenters/decidim/decidim_awesome/admin_log/component_presenter_override.rb +30 -0
  132. data/app/presenters/decidim/decidim_awesome/participatory_space_role_presenter.rb +1 -1
  133. data/app/presenters/decidim/decidim_awesome/private_data_presenter.rb +70 -0
  134. data/app/presenters/decidim/decidim_awesome/user_entity_presenter.rb +1 -1
  135. data/app/queries/decidim/decidim_awesome/private_data_finder.rb +19 -0
  136. data/app/serializers/concerns/decidim/decidim_awesome/proposals/proposal_serializer_methods.rb +72 -0
  137. data/app/serializers/concerns/decidim/decidim_awesome/proposals/proposal_serializer_override.rb +38 -0
  138. data/app/serializers/decidim/decidim_awesome/proposals/private_proposal_serializer.rb +34 -0
  139. data/app/types/concerns/decidim/decidim_awesome/add_proposal_type_custom_fields.rb +59 -0
  140. data/app/types/concerns/decidim/decidim_awesome/{proposal_type_override.rb → add_proposal_type_vote_weights.rb} +3 -1
  141. data/app/views/decidim/decidim_awesome/admin/admin_accountability/index.html.erb +23 -17
  142. data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +50 -48
  143. data/app/views/decidim/decidim_awesome/admin/config/_autoedit_box_label.html.erb +7 -2
  144. data/app/views/decidim/decidim_awesome/admin/config/_constraints.html.erb +25 -18
  145. data/app/views/decidim/decidim_awesome/admin/config/_form_admins.html.erb +7 -6
  146. data/app/views/decidim/decidim_awesome/admin/config/_form_editors.html.erb +12 -16
  147. data/app/views/decidim/decidim_awesome/admin/config/_form_livechat.html.erb +39 -23
  148. data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_custom_fields.html.erb +35 -17
  149. data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_private_custom_fields.html.erb +1 -0
  150. data/app/views/decidim/decidim_awesome/admin/config/_form_proposals.html.erb +68 -80
  151. data/app/views/decidim/decidim_awesome/admin/config/_form_styles.html.erb +16 -12
  152. data/app/views/decidim/decidim_awesome/admin/config/_form_surveys.html.erb +8 -6
  153. data/app/views/decidim/decidim_awesome/admin/config/show.html.erb +22 -12
  154. data/app/views/decidim/decidim_awesome/admin/constraints/_form.html.erb +1 -49
  155. data/app/views/decidim/decidim_awesome/admin/constraints/new.html.erb +14 -9
  156. data/app/views/decidim/decidim_awesome/admin/constraints/show.html.erb +14 -9
  157. data/app/views/decidim/decidim_awesome/admin/custom_redirects/_form.html.erb +20 -5
  158. data/app/views/decidim/decidim_awesome/admin/custom_redirects/edit.html.erb +5 -5
  159. data/app/views/decidim/decidim_awesome/admin/custom_redirects/index.html.erb +14 -13
  160. data/app/views/decidim/decidim_awesome/admin/custom_redirects/new.html.erb +5 -5
  161. data/app/views/decidim/decidim_awesome/admin/maintenance/_private_data.html.erb +44 -0
  162. data/app/views/decidim/decidim_awesome/admin/maintenance/show.html.erb +44 -0
  163. data/app/views/decidim/decidim_awesome/admin/menu_hacks/_form.html.erb +6 -6
  164. data/app/views/decidim/decidim_awesome/admin/menu_hacks/edit.html.erb +21 -12
  165. data/app/views/decidim/decidim_awesome/admin/menu_hacks/index.html.erb +39 -42
  166. data/app/views/decidim/decidim_awesome/admin/menu_hacks/new.html.erb +21 -12
  167. data/app/views/decidim/decidim_awesome/admin/proposals/_editor.html.erb +8 -5
  168. data/app/views/decidim/decidim_awesome/admin/proposals/_private_body.html.erb +20 -0
  169. data/app/views/decidim/decidim_awesome/admin/shared/_filters_with_date.html.erb +14 -18
  170. data/app/views/decidim/decidim_awesome/amendments/_modal.html.erb +23 -0
  171. data/app/views/decidim/decidim_awesome/custom_fields/_form_render.html.erb +8 -2
  172. data/app/views/decidim/decidim_awesome/iframe_component/iframe/show.html.erb +7 -12
  173. data/app/views/decidim/decidim_awesome/map_component/map/_map_template.html.erb +53 -37
  174. data/app/views/decidim/decidim_awesome/map_component/map/show.html.erb +14 -5
  175. data/app/views/decidim/decidim_awesome/voting/voting_cards/_show_vote_button.html.erb +0 -3
  176. data/app/views/layouts/decidim/decidim_awesome/_awesome_config.html.erb +9 -7
  177. data/app/views/layouts/decidim/decidim_awesome/_intergram_widget.html.erb +9 -6
  178. data/app/views/layouts/decidim/decidim_awesome/admin/_base.html.erb +12 -0
  179. data/app/views/layouts/decidim/decidim_awesome/admin/application.html.erb +1 -73
  180. data/app/views/layouts/decidim/decidim_awesome/admin/maintenance.html.erb +19 -0
  181. data/config/assets.rb +3 -33
  182. data/config/i18n-tasks.yml +23 -3
  183. data/config/locales/ca.yml +28 -17
  184. data/config/locales/cs.yml +39 -14
  185. data/config/locales/de.yml +25 -15
  186. data/config/locales/en.yml +125 -35
  187. data/config/locales/es.yml +26 -16
  188. data/config/locales/eu.yml +7 -3
  189. data/config/locales/fr.yml +25 -16
  190. data/config/locales/hu.yml +43 -8
  191. data/config/locales/it.yml +8 -15
  192. data/config/locales/ja.yml +26 -15
  193. data/config/locales/lt.yml +0 -4
  194. data/config/locales/nl.yml +9 -14
  195. data/config/locales/pt-BR.yml +9 -14
  196. data/config/locales/ro-RO.yml +0 -3
  197. data/config/locales/sv.yml +9 -9
  198. data/config/rubocop/disabled.yml +11 -0
  199. data/config/rubocop/faker.yml +480 -0
  200. data/config/rubocop/rails.yml +88 -0
  201. data/config/rubocop/rspec.yml +65 -0
  202. data/config/rubocop/ruby.yml +1210 -0
  203. data/db/migrate/20240306175331_rename_editor_images_awesome_config.rb +18 -0
  204. data/db/migrate/20240531224204_add_decidim_awesome_proposal_private_fields.rb +29 -0
  205. data/db/migrate/20240729164227_add_decidim_awesome_proposal_private_fields_date.rb +20 -0
  206. data/db/seeds.rb +3 -3
  207. data/lib/decidim/decidim_awesome/admin_engine.rb +26 -7
  208. data/lib/decidim/decidim_awesome/api/types/localized_custom_fields_type.rb +22 -0
  209. data/lib/decidim/decidim_awesome/api/types/translated_custom_fields_type.rb +51 -0
  210. data/lib/decidim/decidim_awesome/awesome.rb +70 -19
  211. data/lib/decidim/decidim_awesome/awesome_helpers.rb +6 -2
  212. data/lib/decidim/decidim_awesome/checksums.yml +46 -44
  213. data/lib/decidim/decidim_awesome/config.rb +1 -1
  214. data/lib/decidim/decidim_awesome/custom_fields.rb +13 -5
  215. data/lib/decidim/decidim_awesome/engine.rb +165 -56
  216. data/lib/decidim/decidim_awesome/iframe_component/component.rb +1 -2
  217. data/lib/decidim/decidim_awesome/lock.rb +47 -0
  218. data/lib/decidim/decidim_awesome/map_component/component.rb +1 -1
  219. data/lib/decidim/decidim_awesome/menu.rb +165 -0
  220. data/lib/decidim/decidim_awesome/menu_hacker.rb +4 -8
  221. data/lib/decidim/decidim_awesome/system_checker.rb +2 -4
  222. data/lib/decidim/decidim_awesome/test/factories.rb +10 -10
  223. data/lib/decidim/decidim_awesome/test/initializer.rb +7 -12
  224. data/lib/decidim/decidim_awesome/test/layouts/decidim/_head.html.erb +2 -2
  225. data/lib/decidim/decidim_awesome/test/layouts/decidim/admin/_header.html.erb +2 -2
  226. data/lib/decidim/decidim_awesome/test/shared_examples/{box_label_editor.rb → box_label_editor_examples.rb} +17 -17
  227. data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +23 -5
  228. data/lib/decidim/decidim_awesome/test/shared_examples/custom_fields_examples.rb +155 -0
  229. data/lib/decidim/decidim_awesome/test/shared_examples/custom_redirects_contexts.rb +7 -7
  230. data/lib/decidim/decidim_awesome/test/shared_examples/editor_examples.rb +42 -58
  231. data/lib/decidim/decidim_awesome/test/shared_examples/menu_hack_contexts.rb +9 -8
  232. data/lib/decidim/decidim_awesome/test/shared_examples/scoped_admins_examples.rb +32 -24
  233. data/lib/decidim/decidim_awesome/test/shared_examples/summary_examples.rb +97 -22
  234. data/lib/decidim/decidim_awesome/version.rb +2 -2
  235. data/lib/decidim/decidim_awesome/voting_manifest.rb +5 -10
  236. data/lib/decidim/decidim_awesome.rb +1 -2
  237. data/lib/tasks/decidim_awesome_active_storage_migrations_tasks.rake +1 -1
  238. data/lib/tasks/decidim_awesome_upgrade_tasks.rake +4 -0
  239. data/package.json +21 -30
  240. metadata +83 -60
  241. data/app/cells/decidim/decidim_awesome/voting/voting_cards_counter/show.erb +0 -15
  242. data/app/cells/decidim/decidim_awesome/voting/voting_cards_counter/vote_button.erb +0 -15
  243. data/app/cells/decidim/decidim_awesome/voting/voting_cards_counter_cell.rb +0 -21
  244. data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_modal/show.erb +0 -16
  245. data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal_modal_cell.rb +0 -20
  246. data/app/cells/decidim/proposals/proposal_m/footer.erb +0 -13
  247. data/app/helpers/decidim/decidim_awesome/amendments_helper_override.rb +0 -48
  248. data/app/helpers/decidim/decidim_awesome/proposals/application_helper_override.rb +0 -78
  249. data/app/overrides/layouts/decidim/_head/add_awesome_legacy_scripts.rb +0 -14
  250. data/app/overrides/layouts/decidim/admin/_header/replace_styles.html.erb.deface +0 -3
  251. data/app/packs/entrypoints/decidim_admin_decidim_awesome_custom_fields.js +0 -2
  252. data/app/packs/entrypoints/decidim_decidim_awesome_admin_form_exit_warn.js +0 -1
  253. data/app/packs/src/decidim/decidim_awesome/admin/constraints.js +0 -55
  254. data/app/packs/src/decidim/decidim_awesome/editors/editor.js +0 -218
  255. data/app/packs/src/decidim/decidim_awesome/editors/tabs_focus.js +0 -22
  256. data/app/packs/stylesheets/decidim/decidim_awesome/editors/markdown_editor.scss +0 -19
  257. data/app/packs/stylesheets/decidim/decidim_awesome/editors/quill_editor.scss +0 -58
  258. data/app/packs/stylesheets/vendor/select2-foundation-theme.scss +0 -348
  259. data/app/serializers/concerns/decidim/decidim_awesome/proposal_serializer_override.rb +0 -64
  260. data/app/views/decidim/decidim_awesome/admin/config/_modal.html.erb +0 -11
  261. data/app/views/decidim/decidim_awesome/voting/voting_cards/_proposal_m_cell_footer.erb +0 -15
@@ -8,16 +8,15 @@ module Decidim
8
8
  class ConfigForm < Decidim::Form
9
9
  include ActionView::Helpers::SanitizeHelper
10
10
 
11
- attribute :allow_images_in_full_editor, Boolean
12
- attribute :allow_images_in_small_editor, Boolean
11
+ attribute :allow_images_in_editors, Boolean
12
+ attribute :allow_videos_in_editors, Boolean
13
13
  attribute :allow_images_in_proposals, Boolean
14
- attribute :use_markdown_editor, Boolean
15
- attribute :allow_images_in_markdown_editor, Boolean
16
14
  attribute :auto_save_forms, Boolean
17
15
  attribute :scoped_styles, Hash
18
16
  attribute :proposal_custom_fields, Hash
17
+ attribute :proposal_private_custom_fields, Hash
19
18
  attribute :scoped_admins, Hash
20
- attribute :menu, Array[MenuForm]
19
+ attribute :menu, [MenuForm]
21
20
  attribute :intergram_for_admins, Boolean
22
21
  attribute :intergram_for_admins_settings, IntergramForm
23
22
  attribute :intergram_for_public, Boolean
@@ -36,7 +35,8 @@ module Decidim
36
35
  attr_accessor :valid_keys
37
36
 
38
37
  validate :css_syntax, if: ->(form) { form.scoped_styles.present? }
39
- validate :json_syntax, if: ->(form) { form.proposal_custom_fields.present? }
38
+ validate :json_syntax
39
+
40
40
  validates :validate_title_min_length, presence: true, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 100 }
41
41
  validates :validate_title_max_caps_percent, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }
42
42
  validates :validate_title_max_marks_together, presence: true, numericality: { greater_than_or_equal_to: 1 }
@@ -65,26 +65,27 @@ module Decidim
65
65
 
66
66
  SassC::Engine.new(code).render
67
67
  rescue SassC::SyntaxError => e
68
- errors.add(:scoped_styles, I18n.t("config.form.errors.incorrect_css", key: key, scope: "decidim.decidim_awesome.admin"))
68
+ errors.add(:scoped_styles, I18n.t("config.form.errors.incorrect_css", key:, scope: "decidim.decidim_awesome.admin"))
69
69
  errors.add(key.to_sym, e.message)
70
70
  end
71
71
  end
72
72
 
73
73
  def json_syntax
74
- proposal_custom_fields.each do |key, code|
75
- next unless code
74
+ fields = {}
75
+ fields.merge!(proposal_custom_fields: proposal_custom_fields.values) if proposal_custom_fields.present?
76
+ fields.merge!(proposal_private_custom_fields: proposal_private_custom_fields.values) if proposal_private_custom_fields.present?
77
+ fields.each do |key, values|
78
+ next if values.blank?
76
79
 
77
- JSON.parse(code)
78
- rescue JSON::ParserError => e
79
- errors.add(:scoped_styles, I18n.t("config.form.errors.incorrect_json", key: key, scope: "decidim.decidim_awesome.admin"))
80
+ values.each { |code| JSON.parse(code) }
81
+ rescue JSON::JSONError => e
82
+ errors.add(key, I18n.t("config.form.errors.incorrect_json", key:, scope: "decidim.decidim_awesome.admin"))
80
83
  errors.add(key.to_sym, e.message)
81
84
  end
82
85
  end
83
86
 
84
87
  # formBuilder has a bug and do not sanitize text if users copy/paste text with format in the label input
85
88
  def sanitize_labels!
86
- return unless proposal_custom_fields
87
-
88
89
  proposal_custom_fields.transform_values! do |code|
89
90
  next unless code
90
91
 
@@ -97,6 +98,19 @@ module Decidim
97
98
  rescue JSON::ParserError
98
99
  code
99
100
  end
101
+
102
+ proposal_private_custom_fields.transform_values! do |code|
103
+ next unless code
104
+
105
+ json = JSON.parse(code)
106
+ json.map! do |item|
107
+ item["label"] = strip_tags(item["label"])
108
+ item
109
+ end
110
+ JSON.generate(json)
111
+ rescue JSON::ParserError
112
+ code
113
+ end
100
114
  end
101
115
  end
102
116
  end
@@ -18,8 +18,8 @@ module Decidim
18
18
  sanitize_url(origin),
19
19
  {
20
20
  destination: sanitize_url(destination, strip_host: false),
21
- active: active,
22
- pass_query: pass_query
21
+ active:,
22
+ pass_query:
23
23
  }
24
24
  ]
25
25
  end
@@ -13,6 +13,10 @@ module Decidim
13
13
  attribute :intro_message, String
14
14
  attribute :auto_response, String
15
15
  attribute :auto_no_response, String
16
+
17
+ def color
18
+ super || current_organization.colors["secondary"] || "#E91E63"
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -27,10 +27,10 @@ module Decidim
27
27
  def to_params
28
28
  {
29
29
  label: raw_label,
30
- position: position,
31
- url: url,
32
- target: target,
33
- visibility: visibility
30
+ position:,
31
+ url:,
32
+ target:,
33
+ visibility:
34
34
  }
35
35
  end
36
36
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ module AmendmentsHelperOverride
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ # original method
10
+ alias_method :decidim_amendments_form_field_for, :amendments_form_field_for
11
+
12
+ # override with custom fields if scope applies
13
+ def amendments_form_field_for(attribute, form, original_resource)
14
+ custom_fields, custom_private_fields = awesome_custom_fields(attribute, form)
15
+ content = if custom_fields.blank?
16
+ decidim_amendments_form_field_for(attribute, form, original_resource)
17
+ else
18
+ render_amendment_custom_fields_override(custom_fields, attribute, form, original_resource)
19
+ end
20
+ if custom_private_fields.present?
21
+ content = content_tag("div", content)
22
+ content += content_tag("div", render_amendment_custom_fields_override(custom_private_fields, :private_body, form, original_resource))
23
+ end
24
+ content
25
+ end
26
+
27
+ private
28
+
29
+ def render_amendment_custom_fields_override(custom_fields, attribute, form, original_resource)
30
+ # ensure decidim_editor is available as it is only required if the original FormBuilder is called
31
+ append_stylesheet_pack_tag "decidim_editor"
32
+ append_javascript_pack_tag "decidim_editor", defer: false
33
+
34
+ custom_fields.translate!
35
+ body = amendments_form_fields_value(original_resource, attribute)
36
+ custom_fields.apply_xml(body) if body.present?
37
+ # TODO: find a way to add errors as form is not the parent form
38
+ # form.object.errors.add(attribute, custom_fields.errors) if custom_fields.errors
39
+
40
+ editor_image = Decidim::EditorImage.new
41
+ editor_options = form.send(:editor_options, editor_image, { context: "participant", lines: 10 })
42
+ editor_upload = form.send(:editor_upload, editor_image, editor_options[:upload])
43
+ render partial: "decidim/decidim_awesome/custom_fields/form_render", locals: { spec: custom_fields.to_json, editor_options:, editor_upload:, form:, name: attribute }
44
+ end
45
+
46
+ # Amendments don't use a URL specifying participatory space and component
47
+ # context for awesome config constraints must be obtained from the resource
48
+ def awesome_custom_fields(attribute, _form)
49
+ return unless attribute == :body
50
+
51
+ component = amendable.try(:component)
52
+ return unless component
53
+ return if component.settings.participatory_texts_enabled?
54
+
55
+ awesome_config = Decidim::DecidimAwesome::Config.new(component.organization)
56
+ awesome_config.context_from_component(component)
57
+
58
+ pub = awesome_config.collect_sub_configs_values("proposal_custom_field")
59
+ priv = awesome_config.collect_sub_configs_values("proposal_private_custom_field")
60
+ [pub.presence && Decidim::DecidimAwesome::CustomFields.new(pub), priv.presence && Decidim::DecidimAwesome::CustomFields.new(priv)]
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ module BreadcrumbHelperOverride
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ def active_breadcrumb_item(target_menu)
10
+ active_item = ::Decidim::MenuPresenter.new(target_menu, self).active_item_for_breadcrumb
11
+
12
+ return if active_item.blank?
13
+
14
+ {
15
+ label: active_item.label,
16
+ url: active_item.url,
17
+ active: active_item.active?
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ module Proposals
6
+ module ApplicationHelperOverride
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ alias_method :decidim_text_editor_for_proposal_body, :text_editor_for_proposal_body
11
+ alias_method :decidim_render_proposal_body, :render_proposal_body
12
+
13
+ # If the content is safe, HTML tags are sanitized, otherwise, they are stripped.
14
+ def render_proposal_body(proposal)
15
+ if awesome_proposal_custom_fields.present? || awesome_config[:allow_images_in_editors]
16
+ content = present(proposal).body(links: true, strip_tags: false)
17
+ sanitized = decidim_sanitize_editor_admin(content, {})
18
+ Decidim::ContentProcessor.render_without_format(sanitized).html_safe
19
+ else
20
+ decidim_render_proposal_body(proposal)
21
+ end
22
+ end
23
+
24
+ # replace normal method to draw the editor
25
+ def text_editor_for_proposal_body(form)
26
+ custom_fields = awesome_proposal_custom_fields_for(:body)
27
+ custom_private_fields = awesome_proposal_custom_fields_for(:private_body)
28
+
29
+ content = if custom_fields.empty?
30
+ decidim_text_editor_for_proposal_body(form)
31
+ else
32
+ render_proposal_custom_fields_override(custom_fields, form, :body)
33
+ end
34
+
35
+ unless custom_private_fields.empty?
36
+ content = content_tag("div", content)
37
+ content += content_tag("div", render_proposal_custom_fields_override(custom_private_fields, form, :private_body))
38
+ end
39
+ content
40
+ end
41
+
42
+ # replace admin method to draw the editor (multi lang)
43
+ def admin_editor_for_proposal_body(form)
44
+ custom_fields = awesome_proposal_custom_fields_for(:body)
45
+
46
+ return if custom_fields.empty?
47
+
48
+ locales = form.send(:locales)
49
+ return render_proposal_custom_fields_override(custom_fields, form, "body_#{locales.first}", locales.first) if locales.length == 1
50
+
51
+ tabs_id = form.send(:sanitize_tabs_selector, form.options[:tabs_id] || "#{form.object_name}-body-tabs")
52
+
53
+ label_tabs = form.content_tag(:div, class: "label--tabs") do
54
+ language_selector = "".html_safe
55
+ language_selector = form.create_language_selector(locales, tabs_id, "body") if form.options[:label] != false
56
+
57
+ safe_join [content_tag("label"), language_selector]
58
+ end
59
+
60
+ tabs_content = form.content_tag(:div, class: "tabs-content", data: { tabs_content: tabs_id }) do
61
+ locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
62
+ tab_content_id = "#{tabs_id}-body-panel-#{index}"
63
+ string + content_tag(:div, class: form.send(:tab_element_class_for, "panel", index), id: tab_content_id, "aria-hidden": index.zero? ? "false" : "true") do
64
+ render_proposal_custom_fields_override(custom_fields, form, "body_#{locale}", locale)
65
+ end
66
+ end
67
+ end
68
+
69
+ safe_join [label_tabs, tabs_content]
70
+ end
71
+
72
+ def render_proposal_custom_fields_override(custom_fields, form, name, locale = nil)
73
+ # ensure decidim_editor is available as it is only required if the original FormBuilder is called
74
+ append_stylesheet_pack_tag "decidim_editor"
75
+ append_javascript_pack_tag "decidim_editor", defer: false
76
+
77
+ custom_fields.translate!
78
+
79
+ body = if name == :private_body
80
+ if form_presenter.proposal.private_body.is_a?(Hash) && locale.present?
81
+ form_presenter.private_body(extras: false, all_locales: locale.present?).with_indifferent_access[locale]
82
+ else
83
+ form_presenter.private_body(extras: false)
84
+ end
85
+ elsif form_presenter.proposal.body.is_a?(Hash) && locale.present?
86
+ form_presenter.body(extras: false, all_locales: locale.present?).with_indifferent_access[locale]
87
+ else
88
+ form_presenter.body(extras: false)
89
+ end
90
+
91
+ custom_fields.apply_xml(body) if body.present?
92
+ form.object.errors.add(name, custom_fields.errors) if custom_fields.errors
93
+ editor_image = Decidim::EditorImage.new
94
+ editor_options = form.send(:editor_options, editor_image, { context: "participant", lines: 10 })
95
+ editor_upload = form.send(:editor_upload, editor_image, editor_options[:upload])
96
+ render partial: "decidim/decidim_awesome/custom_fields/form_render", locals: { spec: custom_fields.to_json, editor_options:, editor_upload:, form:, name: }
97
+ end
98
+
99
+ def awesome_proposal_custom_fields_for(name)
100
+ if name == :private_body
101
+ Decidim::DecidimAwesome::CustomFields.new(awesome_proposal_private_custom_fields)
102
+ else
103
+ Decidim::DecidimAwesome::CustomFields.new(awesome_proposal_custom_fields)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -8,40 +8,19 @@ module Decidim
8
8
 
9
9
  include Decidim::TranslatableAttributes
10
10
 
11
- def check(status)
12
- content_tag(:span, icon(status ? "check" : "x", class: "icon", aria_label: status, role: "img"), class: "text-#{status ? "success" : "alert"}")
13
- end
11
+ delegate :menus, :config_enabled?, to: "Decidim::DecidimAwesome::Menu"
14
12
 
15
- def menus
16
- @menus ||= {
17
- editors: config_enabled?([:allow_images_in_full_editor, :allow_images_in_small_editor, :use_markdown_editor, :allow_images_in_markdown_editor]),
18
- proposals: config_enabled?([:allow_images_in_proposals,
19
- :validate_title_min_length, :validate_title_max_caps_percent,
20
- :validate_title_max_marks_together, :validate_title_start_with_caps,
21
- :validate_body_min_length, :validate_body_max_caps_percent,
22
- :validate_body_max_marks_together, :validate_body_start_with_caps]),
23
- surveys: config_enabled?(:auto_save_forms),
24
- styles: config_enabled?(:scoped_styles),
25
- proposal_custom_fields: config_enabled?(:proposal_custom_fields),
26
- admins: config_enabled?(:scoped_admins),
27
- menu_hacks: config_enabled?(:menu),
28
- custom_redirects: config_enabled?(:custom_redirects),
29
- livechat: config_enabled?([:intergram_for_admins, :intergram_for_public])
30
- }
13
+ def check(status)
14
+ content_tag(:span, icon(status ? "check-line" : "close-line", class: "inline-block", aria_label: status, role: "img"), class: "fill-#{status ? "success" : "alert"}")
31
15
  end
32
16
 
33
17
  # returns only non :disabled vars in config
34
18
  def enabled_configs(vars)
35
- vars.filter do |var|
36
- config_enabled? var
19
+ vars.filter do |conf|
20
+ config_enabled?(conf)
37
21
  end
38
22
  end
39
23
 
40
- # ensure boolean value
41
- def config_enabled?(var)
42
- DecidimAwesome.enabled?(var)
43
- end
44
-
45
24
  def participatory_space_manifests
46
25
  manifests = OTHER_MANIFESTS.index_with { |m| I18n.t("decidim.decidim_awesome.admin.config.#{m}") }
47
26
  Decidim.participatory_space_manifests.pluck(:name).each do |name|
@@ -71,7 +50,7 @@ module Decidim
71
50
  space = model_for_manifest(manifest)
72
51
  return {} unless space&.column_names&.include? "slug"
73
52
 
74
- components = Component.where(participatory_space: space.find_by(slug: slug))
53
+ components = Component.where(participatory_space: space.find_by(slug:))
75
54
  components.to_h do |item|
76
55
  [item.id, "#{item.id}: #{translated_attribute(item.name)}"]
77
56
  end
@@ -11,14 +11,12 @@ module Decidim
11
11
 
12
12
  # rubocop:disable Metrics/CyclomaticComplexity
13
13
  # rubocop:disable Metrics/PerceivedComplexity:
14
- def awesome_map_for(components, &block)
14
+ def awesome_map_for(components, &)
15
15
  return unless map_utility_dynamic
16
16
 
17
- map = awesome_builder.map_element({ class: "google-map", id: "awesome-map-container" }, &block)
18
- help = content_tag(:div, class: "map__help") do
19
- sr_content = content_tag(:p, t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "show-for-sr")
20
-
21
- sr_content
17
+ map = awesome_builder.map_element({ class: "dynamic-map", id: "awesome-map-container" }, &)
18
+ help = content_tag(:div, class: "map__skip-container") do
19
+ content_tag(:p, t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "sr-only")
22
20
  end
23
21
 
24
22
  html_options = {
@@ -30,7 +28,7 @@ module Decidim
30
28
  type: component.manifest.name,
31
29
  name: translated_attribute(component.name),
32
30
  url: Decidim::EngineRouter.main_proxy(component).root_path,
33
- amendments: component.manifest.name == :proposals ? Decidim::Proposals::Proposal.where(component: component).only_emendations.count : 0
31
+ amendments: component.manifest.name == :proposals ? Decidim::Proposals::Proposal.where(component:).only_emendations.count : 0
34
32
  }
35
33
  end.to_json,
36
34
  "data-hide-controls" => settings_source.try(:hide_controls),
@@ -51,7 +49,7 @@ module Decidim
51
49
  }
52
50
 
53
51
  content_tag(:div, html_options) do
54
- content_tag :div, class: "row column" do
52
+ content_tag :div, class: "w-full" do
55
53
  help + map
56
54
  end
57
55
  end
@@ -71,7 +69,6 @@ module Decidim
71
69
  try(:current_component) || self
72
70
  end
73
71
 
74
- # rubocop:disable Rails/HelperInstanceVariable
75
72
  def current_categories(categories)
76
73
  return @current_categories if @current_categories
77
74
 
@@ -97,26 +94,12 @@ module Decidim
97
94
  }
98
95
  builder = map_utility_dynamic.create_builder(self, options)
99
96
 
100
- # We need awesome map listeners before initialize the official map
101
- unless snippets.any?(:awesome_map_styles) || snippets.any?(:awesome_map_scripts)
102
- snippets.add(:awesome_map_styles, stylesheet_pack_tag("decidim_decidim_awesome_map"))
103
- snippets.add(:awesome_map_scripts, javascript_pack_tag("decidim_decidim_awesome_map", defer: false))
104
- snippets.add(:head, snippets.for(:awesome_map_styles))
105
- snippets.add(DecidimAwesome.legacy_version? ? :head : :foot, snippets.for(:awesome_map_scripts))
106
- end
107
-
108
- unless snippets.any?(:map_styles) || snippets.any?(:map_scripts)
109
- snippets.add(:map_styles, builder.stylesheet_snippets)
110
- snippets.add(:map_scripts, builder.javascript_snippets)
111
-
112
- snippets.add(:head, snippets.for(:map_styles))
113
- snippets.add(DecidimAwesome.legacy_version? ? :head : :foot, snippets.for(:map_scripts))
114
- end
97
+ append_stylesheet_pack_tag("decidim_decidim_awesome_map")
98
+ append_javascript_pack_tag("decidim_decidim_awesome_map")
115
99
 
116
100
  builder
117
101
  end
118
102
 
119
- # rubocop:disable Style/FormatStringToken
120
103
  def append_category(category)
121
104
  @h += @golden_ratio_conjugate
122
105
  @h %= 1
@@ -129,8 +112,6 @@ module Decidim
129
112
  color: format("#%02x%02x%02x", r, g, b)
130
113
  )
131
114
  end
132
- # rubocop:enable Style/FormatStringToken
133
- # rubocop:enable Rails/HelperInstanceVariable
134
115
 
135
116
  # HSV values in [0..1[
136
117
  # returns [r, g, b] values from 0 to 255
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DecidimAwesome
5
+ class DestroyPrivateDataJob < ApplicationJob
6
+ queue_as :default
7
+
8
+ # Destroys private data associated with the resource
9
+ def perform(resource)
10
+ extra_fields = Decidim::DecidimAwesome::ProposalExtraField.where(
11
+ proposal: Decidim::Proposals::Proposal.where(component: resource)
12
+ ).where("private_body_updated_at < ?", DecidimAwesome.private_data_expiration_time.ago)
13
+
14
+ extra_fields.find_each do |extra_field|
15
+ extra_field.update(private_body: nil)
16
+ end
17
+
18
+ Lock.new(resource.organization).release!(resource)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -25,7 +25,7 @@ module Decidim
25
25
  cw_uploader: Decidim::Cw::DecidimAwesome::ImageUploader,
26
26
  as_attribute: "file",
27
27
  logger: @logger,
28
- routes_mappings: routes_mappings
28
+ routes_mappings:
29
29
  )
30
30
  end
31
31
 
@@ -34,11 +34,11 @@ module Decidim
34
34
  klass, id = mapping[:instance].split("#")
35
35
  next unless klass == "Decidim::DecidimAwesome::EditorImage"
36
36
 
37
- instance = Decidim::DecidimAwesome::EditorImage.find_by(id: id)
37
+ instance = Decidim::DecidimAwesome::EditorImage.find_by(id:)
38
38
 
39
39
  next if instance.blank?
40
40
 
41
- mapping.merge!(instance: instance)
41
+ mapping.merge!(instance:)
42
42
  end.compact
43
43
 
44
44
  editor_images_available_attributes.each do |model, attributes|
@@ -75,7 +75,8 @@ module Decidim
75
75
  "Decidim::Assembly" => %w(short_description description purpose_of_action composition internal_organisation announcement closing_date_reason special_features),
76
76
  "Decidim::Forms::Questionnaire" => %w(description tos),
77
77
  "Decidim::Forms::Question" => %w(description),
78
- "Decidim::Organization" => %w(welcome_notification_body admin_terms_of_use_body description highlighted_content_banner_short_description id_documents_explanation_text),
78
+ "Decidim::Organization" => %w(welcome_notification_body admin_terms_of_service_body description highlighted_content_banner_short_description
79
+ id_documents_explanation_text),
79
80
  "Decidim::StaticPage" => %w(content),
80
81
  "Decidim::ContextualHelpSection" => %w(content),
81
82
  "Decidim::Category" => %w(description),
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/OpenStructUse
4
3
  module Decidim
5
4
  module DecidimAwesome
6
5
  # A middleware that stores the current awesome context by parsing the request
@@ -101,7 +100,7 @@ module Decidim
101
100
  end
102
101
 
103
102
  def safe_get_route?
104
- return unless @request.get?
103
+ return false unless @request.get?
105
104
 
106
105
  case @request.path
107
106
  when "/"
@@ -116,7 +115,7 @@ module Decidim
116
115
  end
117
116
 
118
117
  def safe_post_route?
119
- return unless @request.post? || @request.put? || @request.patch?
118
+ return false unless @request.post? || @request.put? || @request.patch?
120
119
 
121
120
  case @request.path
122
121
  when %r{^/admin/admin_terms}
@@ -171,7 +170,7 @@ module Decidim
171
170
  next unless model
172
171
 
173
172
  settings["participatory_space_slug"] = model.find_by(slug: settings["participatory_space_slug"])&.id
174
- OpenStruct.new(settings: settings) if settings["participatory_space_slug"]
173
+ OpenStruct.new(settings:) if settings["participatory_space_slug"]
175
174
  end
176
175
  end
177
176
  # rubocop:enable Metrics/CyclomaticComplexity
@@ -183,4 +182,3 @@ module Decidim
183
182
  end
184
183
  end
185
184
  end
186
- # rubocop:enable Style/OpenStructUse
@@ -6,10 +6,31 @@ module Decidim
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- has_one :extra_fields, foreign_key: "decidim_proposal_id", class_name: "Decidim::DecidimAwesome::ProposalExtraField", dependent: :destroy
9
+ has_one :extra_fields, as: :proposal, foreign_key: "decidim_proposal_id", foreign_type: "decidim_proposal_type", class_name: "Decidim::DecidimAwesome::ProposalExtraField",
10
+ dependent: :destroy
11
+
12
+ after_save do |proposal|
13
+ if proposal.extra_fields && proposal.extra_fields.changed?
14
+ proposal.extra_fields.save
15
+ proposal.update_vote_weights
16
+ proposal.reload
17
+ end
18
+ end
19
+
20
+ delegate :private_body=, to: :safe_extra_fields
21
+
22
+ def private_body
23
+ extra_fields.private_body if extra_fields
24
+ end
25
+
26
+ def update_private_body!(private_body)
27
+ safe_extra_fields.private_body = private_body
28
+ safe_extra_fields.save!
29
+ self.extra_fields = safe_extra_fields
30
+ end
10
31
 
11
32
  def weight_count(weight)
12
- (extra_fields && extra_fields.vote_weight_totals[weight.to_s]) || 0
33
+ safe_extra_fields.vote_weight_totals[weight.to_s] || 0
13
34
  end
14
35
 
15
36
  def vote_weights
@@ -24,24 +45,32 @@ module Decidim
24
45
  @all_vote_weights ||= self.class.all_vote_weights_for(component)
25
46
  end
26
47
 
27
- def update_vote_weights!
28
- extra_fields ||= Decidim::DecidimAwesome::ProposalExtraField.find_or_initialize_by(proposal: self)
29
- extra_fields.vote_weight_totals = {}
48
+ def update_vote_weights
49
+ votes = Decidim::Proposals::ProposalVote.where(proposal: self)
50
+ safe_extra_fields.vote_weight_totals = {}
30
51
  votes.each do |vote|
31
- extra_fields.vote_weight_totals[vote.weight] ||= 0
32
- extra_fields.vote_weight_totals[vote.weight] += 1
52
+ safe_extra_fields.vote_weight_totals[vote.weight] ||= 0
53
+ safe_extra_fields.vote_weight_totals[vote.weight] += 1
33
54
  end
34
- extra_fields.save!
35
- self.extra_fields = extra_fields
36
55
  @vote_weights = nil
37
56
  @all_vote_weights = nil
38
57
  end
39
58
 
59
+ def update_vote_weights!
60
+ update_vote_weights
61
+ safe_extra_fields.save!
62
+ self.extra_fields = safe_extra_fields
63
+ end
64
+
65
+ def safe_extra_fields
66
+ @safe_extra_fields ||= (persisted? && reload.extra_fields) || build_extra_fields(vote_weight_totals: {})
67
+ end
68
+
40
69
  # collects all different weights stored along the different proposals in a different component
41
70
  def self.all_vote_weights_for(component)
42
71
  Decidim::DecidimAwesome::VoteWeight.where(
43
72
  proposal_vote_id: Decidim::Proposals::ProposalVote.where(
44
- proposal: Decidim::Proposals::Proposal.where(component: component)
73
+ proposal: Decidim::Proposals::Proposal.where(component:)
45
74
  )
46
75
  ).pluck(:weight)
47
76
  end
@@ -25,7 +25,7 @@ module Decidim
25
25
  end
26
26
 
27
27
  def self.for_organization(organization)
28
- where(organization: organization)
28
+ where(organization:)
29
29
  end
30
30
 
31
31
  # use this instead of "constraints" to evaluate dynamically added constants
@@ -12,7 +12,7 @@ module Decidim
12
12
  scope :space_role_actions, lambda { |organization|
13
13
  role_changes = where(item_type: PaperTrailVersion.safe_user_roles, event: "create")
14
14
  user_ids_from_object_changes = role_changes.pluck(:object_changes).map { |change| change.match(/decidim_user_id:\n- ?\n- (\d+)/)[1].to_i }
15
- relevant_user_ids = Decidim::User.select(:id).where(id: user_ids_from_object_changes, organization: organization).pluck(:id)
15
+ relevant_user_ids = Decidim::User.select(:id).where(id: user_ids_from_object_changes, organization:).pluck(:id)
16
16
  # add users that might have been completly destroyed in any organization
17
17
  relevant_user_ids += user_ids_from_object_changes - Decidim::User.select("id").where(id: user_ids_from_object_changes).pluck(:id)
18
18
 
@@ -39,9 +39,9 @@ module Decidim
39
39
 
40
40
  def present(html: true)
41
41
  @present ||= if item_type == "Decidim::UserBaseEntity"
42
- UserEntityPresenter.new(self, html: html)
42
+ UserEntityPresenter.new(self, html:)
43
43
  elsif item_type.in?(PaperTrailVersion.safe_user_roles)
44
- ParticipatorySpaceRolePresenter.new(self, html: html)
44
+ ParticipatorySpaceRolePresenter.new(self, html:)
45
45
  else
46
46
  self
47
47
  end