decidim-proposals 0.20.1 → 0.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/admin/decidim_proposals_manifest.js +1 -0
  3. data/app/assets/images/decidim/gamification/badges/accepted_proposals.svg +1 -234
  4. data/app/assets/images/decidim/gamification/badges/proposal_votes.svg +1 -95
  5. data/app/assets/images/decidim/gamification/badges/proposals.svg +1 -229
  6. data/app/assets/images/decidim/proposals/icon.svg +1 -3
  7. data/app/assets/javascripts/decidim/proposals/add_proposal.js.es6 +6 -0
  8. data/app/assets/javascripts/decidim/proposals/admin/proposals.es6 +24 -11
  9. data/app/assets/javascripts/decidim/proposals/admin/proposals_form.js.es6 +3 -5
  10. data/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +35 -0
  11. data/app/cells/decidim/proposals/collaborative_draft_cell.rb +1 -1
  12. data/app/cells/decidim/proposals/collaborative_draft_link_to_proposal_cell.rb +1 -1
  13. data/app/cells/decidim/proposals/collaborative_draft_m/footer.erb +1 -1
  14. data/app/cells/decidim/proposals/collaborative_draft_m_cell.rb +1 -1
  15. data/app/cells/decidim/proposals/cost_report/show.erb +35 -0
  16. data/app/cells/decidim/proposals/cost_report_cell.rb +42 -0
  17. data/app/cells/decidim/proposals/highlighted_proposals_for_component/show.erb +3 -3
  18. data/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb +1 -1
  19. data/app/cells/decidim/proposals/irreversible_action_modal/show.erb +2 -2
  20. data/app/cells/decidim/proposals/irreversible_action_modal_cell.rb +1 -1
  21. data/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb +3 -3
  22. data/app/cells/decidim/proposals/participatory_text_proposal_cell.rb +2 -2
  23. data/app/cells/decidim/proposals/proposal_cell.rb +1 -1
  24. data/app/cells/decidim/proposals/proposal_m/footer.erb +4 -1
  25. data/app/cells/decidim/proposals/proposal_m_cell.rb +37 -9
  26. data/app/cells/decidim/proposals/proposal_tags/show.erb +18 -10
  27. data/app/cells/decidim/proposals/proposal_tags_cell.rb +5 -0
  28. data/app/cells/decidim/proposals/proposals_picker/proposals.erb +12 -0
  29. data/app/cells/decidim/proposals/proposals_picker/show.erb +14 -0
  30. data/app/cells/decidim/proposals/proposals_picker_cell.rb +72 -0
  31. data/app/commands/decidim/proposals/admin/answer_proposal.rb +24 -46
  32. data/app/commands/decidim/proposals/admin/assign_proposals_to_valuator.rb +61 -0
  33. data/app/commands/decidim/proposals/admin/create_proposal.rb +10 -3
  34. data/app/commands/decidim/proposals/admin/create_proposal_note.rb +15 -0
  35. data/app/commands/decidim/proposals/admin/notify_proposal_answer.rb +85 -0
  36. data/app/commands/decidim/proposals/admin/publish_answers.rb +67 -0
  37. data/app/commands/decidim/proposals/admin/publish_participatory_text.rb +6 -1
  38. data/app/commands/decidim/proposals/admin/unassign_proposals_from_valuator.rb +62 -0
  39. data/app/commands/decidim/proposals/admin/update_participatory_text.rb +10 -2
  40. data/app/commands/decidim/proposals/admin/update_proposal.rb +5 -3
  41. data/app/commands/decidim/proposals/admin/update_proposal_scope.rb +75 -0
  42. data/app/commands/decidim/proposals/create_collaborative_draft.rb +1 -1
  43. data/app/commands/decidim/proposals/create_proposal.rb +7 -3
  44. data/app/commands/decidim/proposals/gallery_methods.rb +2 -51
  45. data/app/commands/decidim/proposals/publish_collaborative_draft.rb +2 -2
  46. data/app/commands/decidim/proposals/update_proposal.rb +25 -9
  47. data/app/controllers/concerns/decidim/proposals/admin/filterable.rb +82 -0
  48. data/app/controllers/concerns/decidim/proposals/admin/picker.rb +21 -0
  49. data/app/controllers/concerns/decidim/proposals/orderable.rb +1 -1
  50. data/app/controllers/decidim/proposals/admin/proposal_answers_controller.rb +16 -6
  51. data/app/controllers/decidim/proposals/admin/proposal_notes_controller.rb +8 -9
  52. data/app/controllers/decidim/proposals/admin/proposals_controller.rb +107 -31
  53. data/app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb +58 -0
  54. data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +10 -3
  55. data/app/controllers/decidim/proposals/proposals_controller.rb +30 -10
  56. data/app/controllers/decidim/proposals/versions_controller.rb +9 -16
  57. data/app/controllers/decidim/proposals/{proposal_widgets_controller.rb → widgets_controller.rb} +2 -2
  58. data/app/events/decidim/proposals/admin/proposal_note_created_event.rb +27 -0
  59. data/app/events/decidim/proposals/admin/update_proposal_scope_event.rb +11 -0
  60. data/app/forms/decidim/proposals/admin/import_participatory_text_form.rb +3 -1
  61. data/app/forms/decidim/proposals/admin/participatory_text_proposal_form.rb +20 -0
  62. data/app/forms/decidim/proposals/admin/preview_participatory_text_form.rb +2 -2
  63. data/app/forms/decidim/proposals/admin/proposal_answer_form.rb +27 -2
  64. data/app/forms/decidim/proposals/admin/proposal_base_form.rb +136 -0
  65. data/app/forms/decidim/proposals/admin/proposal_form.rb +6 -117
  66. data/app/forms/decidim/proposals/admin/valuation_assignment_form.rb +37 -0
  67. data/app/forms/decidim/proposals/proposal_form.rb +25 -12
  68. data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +13 -1
  69. data/app/helpers/decidim/proposals/admin/filterable_helper.rb +17 -0
  70. data/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb +35 -0
  71. data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +63 -0
  72. data/app/helpers/decidim/proposals/admin/proposals_helper.rb +124 -0
  73. data/app/helpers/decidim/proposals/admin/proposals_picker_helper.rb +30 -0
  74. data/app/helpers/decidim/proposals/application_helper.rb +54 -38
  75. data/app/helpers/decidim/proposals/collaborative_draft_helper.rb +9 -9
  76. data/app/helpers/decidim/proposals/control_version_helper.rb +1 -37
  77. data/app/helpers/decidim/proposals/proposal_cells_helper.rb +1 -1
  78. data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +0 -145
  79. data/app/helpers/decidim/proposals/proposal_votes_helper.rb +2 -2
  80. data/app/helpers/decidim/proposals/proposal_wizard_helper.rb +24 -7
  81. data/app/helpers/decidim/proposals/proposals_helper.rb +24 -0
  82. data/app/models/decidim/proposals/collaborative_draft.rb +2 -2
  83. data/app/models/decidim/proposals/participatory_text.rb +3 -0
  84. data/app/models/decidim/proposals/proposal.rb +152 -42
  85. data/app/models/decidim/proposals/valuation_assignment.rb +24 -0
  86. data/app/permissions/decidim/proposals/admin/permissions.rb +77 -11
  87. data/app/permissions/decidim/proposals/permissions.rb +1 -22
  88. data/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb +1 -1
  89. data/app/presenters/decidim/proposals/admin_log/valuation_assignment_presenter.rb +51 -0
  90. data/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb +6 -1
  91. data/app/presenters/decidim/proposals/admin_log/value_types/valuator_role_user_presenter.rb +19 -0
  92. data/app/presenters/decidim/proposals/collaborative_draft_presenter.rb +2 -28
  93. data/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb +22 -0
  94. data/app/presenters/decidim/proposals/official_author_presenter.rb +1 -29
  95. data/app/presenters/decidim/proposals/proposal_presenter.rb +79 -5
  96. data/app/queries/decidim/proposals/metrics/accepted_proposals_metric_manage.rb +1 -2
  97. data/app/queries/decidim/proposals/metrics/endorsements_metric_manage.rb +15 -12
  98. data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +5 -4
  99. data/app/queries/decidim/proposals/metrics/proposals_metric_manage.rb +2 -8
  100. data/app/queries/decidim/proposals/metrics/votes_metric_manage.rb +3 -9
  101. data/app/queries/decidim/proposals/similar_proposals.rb +4 -4
  102. data/app/services/decidim/proposals/collaborative_draft_search.rb +8 -10
  103. data/app/services/decidim/proposals/diff_renderer.rb +17 -5
  104. data/app/services/decidim/proposals/proposal_builder.rb +9 -3
  105. data/app/services/decidim/proposals/proposal_search.rb +11 -69
  106. data/app/types/decidim/proposals/proposal_input_filter.rb +29 -0
  107. data/app/types/decidim/proposals/proposal_input_sort.rb +22 -0
  108. data/app/types/decidim/proposals/proposal_type.rb +34 -13
  109. data/app/types/decidim/proposals/proposals_type.rb +22 -15
  110. data/app/validators/proposal_length_validator.rb +38 -0
  111. data/app/views/decidim/proposals/admin/participatory_texts/index.html.erb +9 -1
  112. data/app/views/decidim/proposals/admin/proposal_answers/_form.html.erb +35 -0
  113. data/app/views/decidim/proposals/admin/proposal_notes/_form.html.erb +1 -1
  114. data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes.html.erb +3 -3
  115. data/app/views/decidim/proposals/admin/proposals/_bulk-actions.html.erb +8 -2
  116. data/app/views/decidim/proposals/admin/proposals/_form.html.erb +8 -28
  117. data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +26 -27
  118. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_assign_to_valuator.html.erb +15 -0
  119. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_dropdown.html.erb +21 -1
  120. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_publish_answers.html.erb +14 -0
  121. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_scope-change.html.erb +25 -0
  122. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_unassign_from_valuator.html.erb +15 -0
  123. data/app/views/decidim/proposals/admin/proposals/index.html.erb +18 -9
  124. data/app/views/decidim/proposals/admin/proposals/publish_answers.js.erb +12 -0
  125. data/app/views/decidim/proposals/admin/proposals/show.html.erb +186 -0
  126. data/app/views/decidim/proposals/admin/proposals/update_category.js.erb +3 -2
  127. data/app/views/decidim/proposals/admin/proposals/update_scope.js.erb +27 -0
  128. data/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb +11 -9
  129. data/app/views/decidim/proposals/collaborative_drafts/_filters.html.erb +10 -8
  130. data/app/views/decidim/proposals/collaborative_drafts/_new_collaborative_draft_button.html.erb +4 -4
  131. data/app/views/decidim/proposals/collaborative_drafts/_reject_request_access_form.html.erb +1 -1
  132. data/app/views/decidim/proposals/collaborative_drafts/_wizard_aside.html.erb +4 -2
  133. data/app/views/decidim/proposals/collaborative_drafts/compare.html.erb +2 -0
  134. data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +2 -0
  135. data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +3 -1
  136. data/app/views/decidim/proposals/collaborative_drafts/index.html.erb +4 -2
  137. data/app/views/decidim/proposals/collaborative_drafts/new.html.erb +4 -0
  138. data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +29 -30
  139. data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +52 -22
  140. data/app/views/decidim/proposals/proposals/_endorsements_card_row.html.erb +0 -16
  141. data/app/views/decidim/proposals/proposals/_filters.html.erb +18 -16
  142. data/app/views/decidim/proposals/proposals/_proposal_badge.html.erb +1 -4
  143. data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +1 -11
  144. data/app/views/decidim/proposals/proposals/_proposal_similar.html.erb +2 -2
  145. data/app/views/decidim/proposals/proposals/_proposals.html.erb +14 -0
  146. data/app/views/decidim/proposals/proposals/_vote_button.html.erb +14 -7
  147. data/app/views/decidim/proposals/proposals/_wizard_aside.html.erb +4 -2
  148. data/app/views/decidim/proposals/proposals/_wizard_header.html.erb +4 -3
  149. data/app/views/decidim/proposals/proposals/compare.html.erb +2 -0
  150. data/app/views/decidim/proposals/proposals/complete.html.erb +2 -0
  151. data/app/views/decidim/proposals/proposals/edit.html.erb +3 -1
  152. data/app/views/decidim/proposals/proposals/edit_draft.html.erb +2 -0
  153. data/app/views/decidim/proposals/proposals/index.html.erb +6 -13
  154. data/app/views/decidim/proposals/proposals/new.html.erb +6 -2
  155. data/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb +1 -1
  156. data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_vote_button.html.erb +10 -3
  157. data/app/views/decidim/proposals/proposals/participatory_texts/_view_index.html.erb +1 -1
  158. data/app/views/decidim/proposals/proposals/preview.html.erb +7 -8
  159. data/app/views/decidim/proposals/proposals/show.html.erb +62 -50
  160. data/app/views/decidim/proposals/versions/index.html.erb +14 -32
  161. data/app/views/decidim/proposals/versions/show.html.erb +16 -34
  162. data/config/locales/am-ET.yml +1 -0
  163. data/config/locales/ar.yml +62 -66
  164. data/config/locales/bg-BG.yml +237 -0
  165. data/config/locales/bg.yml +237 -0
  166. data/config/locales/ca.yml +176 -66
  167. data/config/locales/cs.yml +188 -78
  168. data/config/locales/da-DK.yml +1 -0
  169. data/config/locales/da.yml +1 -0
  170. data/config/locales/de.yml +169 -62
  171. data/config/locales/el.yml +876 -0
  172. data/config/locales/en.yml +179 -69
  173. data/config/locales/eo.yml +1 -0
  174. data/config/locales/es-MX.yml +173 -63
  175. data/config/locales/es-PY.yml +173 -63
  176. data/config/locales/es.yml +179 -69
  177. data/config/locales/et-EE.yml +1 -0
  178. data/config/locales/et.yml +1 -0
  179. data/config/locales/eu.yml +28 -61
  180. data/config/locales/fi-plain.yml +174 -64
  181. data/config/locales/fi.yml +210 -100
  182. data/config/locales/fr-CA.yml +906 -0
  183. data/config/locales/fr.yml +184 -66
  184. data/config/locales/ga-IE.yml +1 -0
  185. data/config/locales/gl.yml +28 -61
  186. data/config/locales/hr-HR.yml +1 -0
  187. data/config/locales/hr.yml +1 -0
  188. data/config/locales/hu.yml +135 -63
  189. data/config/locales/id-ID.yml +28 -60
  190. data/config/locales/is-IS.yml +14 -30
  191. data/config/locales/is.yml +274 -0
  192. data/config/locales/it.yml +166 -80
  193. data/config/locales/ja-JP.yml +865 -0
  194. data/config/locales/ja.yml +889 -0
  195. data/config/locales/ko-KR.yml +1 -0
  196. data/config/locales/ko.yml +1 -0
  197. data/config/locales/lt-LT.yml +1 -0
  198. data/config/locales/lt.yml +1 -0
  199. data/config/locales/lv.yml +858 -0
  200. data/config/locales/mt-MT.yml +1 -0
  201. data/config/locales/mt.yml +1 -0
  202. data/config/locales/nl.yml +151 -63
  203. data/config/locales/no.yml +62 -67
  204. data/config/locales/om-ET.yml +1 -0
  205. data/config/locales/pl.yml +525 -392
  206. data/config/locales/pt-BR.yml +30 -66
  207. data/config/locales/pt.yml +439 -330
  208. data/config/locales/ro-RO.yml +841 -0
  209. data/config/locales/ru.yml +14 -45
  210. data/config/locales/sk-SK.yml +896 -0
  211. data/config/locales/sk.yml +869 -0
  212. data/config/locales/sl.yml +26 -0
  213. data/config/locales/so-SO.yml +1 -0
  214. data/config/locales/sr-CS.yml +126 -0
  215. data/config/locales/sv.yml +285 -169
  216. data/config/locales/ti-ER.yml +1 -0
  217. data/config/locales/tr-TR.yml +28 -61
  218. data/config/locales/uk.yml +14 -45
  219. data/config/locales/vi-VN.yml +1 -0
  220. data/config/locales/vi.yml +1 -0
  221. data/config/locales/zh-CN.yml +885 -0
  222. data/config/locales/zh-TW.yml +1 -0
  223. data/db/migrate/20181003074440_fix_user_groups_ids_in_proposals_endorsements.rb +4 -0
  224. data/db/migrate/20191206154128_add_endorsements_counter_cache_to_proposals.rb +7 -0
  225. data/db/migrate/20200120215928_move_proposal_endorsements_to_core_endorsements.rb +54 -0
  226. data/db/migrate/20200120230130_drop_proposal_endorsements.rb +8 -0
  227. data/db/migrate/20200203111239_add_proposal_valuation_assignments.rb +12 -0
  228. data/db/migrate/20200210135152_add_costs_to_proposals.rb +9 -0
  229. data/db/migrate/20200212120110_sync_proposals_state_with_amendments_state.rb +28 -0
  230. data/db/migrate/20200227175922_add_state_published_at_to_proposals.rb +7 -0
  231. data/db/migrate/20200306123652_publish_existing_proposals_state.rb +15 -0
  232. data/db/migrate/20200708091228_move_proposals_fields_to_i18n.rb +86 -0
  233. data/db/migrate/20200730131631_move_proposal_endorsed_event_notifications_to_resource_endorsed_event.rb +20 -0
  234. data/db/migrate/20200827154156_add_commentable_counter_cache_to_proposals.rb +12 -0
  235. data/db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb +37 -0
  236. data/db/migrate/20201002085508_fix_proposals_data.rb +37 -0
  237. data/lib/decidim/content_renderers/proposal_renderer.rb +3 -1
  238. data/lib/decidim/proposals.rb +1 -0
  239. data/lib/decidim/proposals/admin_engine.rb +7 -3
  240. data/lib/decidim/proposals/component.rb +55 -28
  241. data/lib/decidim/proposals/engine.rb +3 -7
  242. data/lib/decidim/proposals/markdown_to_proposals.rb +2 -2
  243. data/lib/decidim/proposals/proposal_serializer.rb +3 -3
  244. data/lib/decidim/proposals/test/capybara_proposals_picker.rb +49 -0
  245. data/lib/decidim/proposals/test/factories.rb +100 -28
  246. data/lib/decidim/proposals/valuatable.rb +21 -0
  247. data/lib/decidim/proposals/version.rb +1 -1
  248. metadata +117 -55
  249. data/app/assets/javascripts/decidim/proposals/identity_selector_dialog.js.es6 +0 -56
  250. data/app/cells/decidim/proposals/endorsers_list/show.erb +0 -17
  251. data/app/cells/decidim/proposals/endorsers_list_cell.rb +0 -31
  252. data/app/commands/decidim/proposals/attachment_methods.rb +0 -43
  253. data/app/commands/decidim/proposals/endorse_proposal.rb +0 -59
  254. data/app/commands/decidim/proposals/unendorse_proposal.rb +0 -40
  255. data/app/controllers/decidim/proposals/proposal_endorsements_controller.rb +0 -60
  256. data/app/models/decidim/proposals/proposal_endorsement.rb +0 -37
  257. data/app/views/decidim/proposals/admin/proposal_answers/edit.html.erb +0 -22
  258. data/app/views/decidim/proposals/admin/proposal_notes/index.html.erb +0 -3
  259. data/app/views/decidim/proposals/admin/shared/_info_proposal.html.erb +0 -20
  260. data/app/views/decidim/proposals/proposal_endorsements/_identity.html.erb +0 -9
  261. data/app/views/decidim/proposals/proposal_endorsements/identities.html.erb +0 -12
  262. data/app/views/decidim/proposals/proposal_endorsements/update_buttons_and_counters.js.erb +0 -20
  263. data/app/views/decidim/proposals/proposal_widgets/show.html.erb +0 -4
  264. data/app/views/decidim/proposals/proposals/_endorsement_button.html.erb +0 -11
  265. data/app/views/decidim/proposals/proposals/_endorsement_identities_cabin.html.erb +0 -13
  266. data/app/views/decidim/proposals/versions/_version.html.erb +0 -20
@@ -31,10 +31,6 @@ module Decidim
31
31
  can_edit_proposal?
32
32
  when :withdraw
33
33
  can_withdraw_proposal?
34
- when :endorse
35
- can_endorse_proposal?
36
- when :unendorse
37
- can_unendorse_proposal?
38
34
  when :amend
39
35
  can_create_amendment?
40
36
  when :vote
@@ -47,7 +43,7 @@ module Decidim
47
43
  end
48
44
 
49
45
  def proposal
50
- @proposal ||= context.fetch(:proposal, nil)
46
+ @proposal ||= context.fetch(:proposal, nil) || context.fetch(:resource, nil)
51
47
  end
52
48
 
53
49
  def voting_enabled?
@@ -82,23 +78,6 @@ module Decidim
82
78
  toggle_allow(proposal && proposal.authored_by?(user))
83
79
  end
84
80
 
85
- def can_endorse_proposal?
86
- is_allowed = proposal &&
87
- authorized?(:endorse, resource: proposal) &&
88
- current_settings&.endorsements_enabled? &&
89
- !current_settings&.endorsements_blocked?
90
-
91
- toggle_allow(is_allowed)
92
- end
93
-
94
- def can_unendorse_proposal?
95
- is_allowed = proposal &&
96
- authorized?(:endorse, resource: proposal) &&
97
- current_settings&.endorsements_enabled?
98
-
99
- toggle_allow(is_allowed)
100
- end
101
-
102
81
  def can_create_amendment?
103
82
  is_allowed = proposal &&
104
83
  authorized?(:amend, resource: proposal) &&
@@ -31,7 +31,7 @@ module Decidim
31
31
 
32
32
  def action_string
33
33
  case action
34
- when "answer", "create", "update"
34
+ when "answer", "create", "update", "publish_answer"
35
35
  "decidim.proposals.admin_log.proposal.#{action}"
36
36
  else
37
37
  super
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module AdminLog
6
+ # This class holds the logic to present a `Decidim::Proposals::ValuationAssignment`
7
+ # for the `AdminLog` log.
8
+ #
9
+ # Usage should be automatic and you shouldn't need to call this class
10
+ # directly, but here's an example:
11
+ #
12
+ # action_log = Decidim::ActionLog.last
13
+ # view_helpers # => this comes from the views
14
+ # ValuationAssignmentPresenter.new(action_log, view_helpers).present
15
+ class ValuationAssignmentPresenter < Decidim::Log::BasePresenter
16
+ private
17
+
18
+ def resource_presenter
19
+ @resource_presenter ||= Decidim::Proposals::Log::ValuationAssignmentPresenter.new(action_log.resource, h, action_log.extra["resource"])
20
+ end
21
+
22
+ def diff_fields_mapping
23
+ {
24
+ valuator_role_id: "Decidim::Proposals::AdminLog::ValueTypes::ValuatorRoleUserPresenter"
25
+ }
26
+ end
27
+
28
+ def action_string
29
+ case action
30
+ when "create", "delete"
31
+ "decidim.proposals.admin_log.valuation_assignment.#{action}"
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def i18n_labels_scope
38
+ "activemodel.attributes.valuation_assignment.admin_log"
39
+ end
40
+
41
+ def has_diff?
42
+ %w(create delete).include?(action) || super
43
+ end
44
+
45
+ def i18n_params
46
+ super.merge(proposal_title: h.translated_attribute(action_log.extra["proposal_title"]))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -5,10 +5,15 @@ module Decidim
5
5
  module AdminLog
6
6
  module ValueTypes
7
7
  class ProposalTitleBodyPresenter < Decidim::Log::ValueTypes::DefaultPresenter
8
+ include Decidim::TranslatableAttributes
9
+
8
10
  def present
9
11
  return unless value
10
12
 
11
- renderer = Decidim::ContentRenderers::HashtagRenderer.new(value)
13
+ translated_value = translated_attribute(value)
14
+ return if translated_value.blank?
15
+
16
+ renderer = Decidim::ContentRenderers::HashtagRenderer.new(translated_value)
12
17
  renderer.render(links: false).html_safe
13
18
  end
14
19
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module AdminLog
6
+ module ValueTypes
7
+ class ValuatorRoleUserPresenter < Decidim::Log::ValueTypes::DefaultPresenter
8
+ def present
9
+ return unless value
10
+
11
+ role = Decidim::Proposals::ValuationAssignment.find_by(valuator_role_id: value).valuator_role
12
+ user = role.user
13
+ user.try(:name)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,12 +5,7 @@ module Decidim
5
5
  #
6
6
  # Decorator for collaborative drafts
7
7
  #
8
- class CollaborativeDraftPresenter < SimpleDelegator
9
- include Rails.application.routes.mounted_helpers
10
- include ActionView::Helpers::UrlHelper
11
- include ActionView::Helpers::SanitizeHelper
12
- include Decidim::SanitizeHelper
13
-
8
+ class CollaborativeDraftPresenter < ProposalPresenter
14
9
  def author
15
10
  coauthorship = __getobj__.coauthorships.first
16
11
  @author ||= if coauthorship.user_group
@@ -20,32 +15,11 @@ module Decidim
20
15
  end
21
16
  end
22
17
 
23
- def collaborative_draft
24
- __getobj__
25
- end
18
+ alias collaborative_draft proposal
26
19
 
27
20
  def collaborative_draft_path
28
21
  Decidim::ResourceLocatorPresenter.new(collaborative_draft).path
29
22
  end
30
-
31
- def title(links: false, extras: true, html_escape: false)
32
- text = collaborative_draft.title
33
- text = decidim_html_escape(text) if html_escape
34
-
35
- renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
36
- renderer.render(links: links, extras: extras).html_safe
37
- end
38
-
39
- def body(links: false, extras: true, strip_tags: false)
40
- text = collaborative_draft.body
41
- text = strip_tags(text) if strip_tags
42
-
43
- renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
44
- text = renderer.render(links: links, extras: extras).html_safe
45
-
46
- text = Decidim::ContentRenderers::LinkRenderer.new(text).render if links
47
- text
48
- end
49
23
  end
50
24
  end
51
25
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Log
6
+ class ValuationAssignmentPresenter < Decidim::Log::ResourcePresenter
7
+ private
8
+
9
+ # Private: Presents resource name.
10
+ #
11
+ # Returns an HTML-safe String.
12
+ def present_resource_name
13
+ if resource.present?
14
+ Decidim::Proposals::ProposalPresenter.new(resource.proposal).title
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,38 +5,10 @@ module Decidim
5
5
  #
6
6
  # A dummy presenter to abstract out the author of an official proposal.
7
7
  #
8
- class OfficialAuthorPresenter
8
+ class OfficialAuthorPresenter < Decidim::OfficialAuthorPresenter
9
9
  def name
10
10
  I18n.t("decidim.proposals.models.proposal.fields.official_proposal")
11
11
  end
12
-
13
- def nickname
14
- ""
15
- end
16
-
17
- def badge
18
- ""
19
- end
20
-
21
- def profile_path
22
- ""
23
- end
24
-
25
- def avatar_url
26
- ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
27
- end
28
-
29
- def deleted?
30
- false
31
- end
32
-
33
- def can_be_contacted?
34
- false
35
- end
36
-
37
- def has_tooltip?
38
- false
39
- end
40
12
  end
41
13
  end
42
14
  end
@@ -8,14 +8,14 @@ module Decidim
8
8
  class ProposalPresenter < SimpleDelegator
9
9
  include Rails.application.routes.mounted_helpers
10
10
  include ActionView::Helpers::UrlHelper
11
- include ActionView::Helpers::SanitizeHelper
12
11
  include Decidim::SanitizeHelper
12
+ include Decidim::TranslatableAttributes
13
13
 
14
14
  def author
15
15
  @author ||= if official?
16
16
  Decidim::Proposals::OfficialAuthorPresenter.new
17
17
  else
18
- coauthorship = coauthorships.first
18
+ coauthorship = coauthorships.includes(:author, :user_group).first
19
19
  coauthorship.user_group&.presenter || coauthorship.author.presenter
20
20
  end
21
21
  end
@@ -39,16 +39,21 @@ module Decidim
39
39
  #
40
40
  # Returns a String.
41
41
  def title(links: false, extras: true, html_escape: false)
42
- text = proposal.title
42
+ text = translated_attribute(proposal.title)
43
43
  text = decidim_html_escape(text) if html_escape
44
44
 
45
45
  renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
46
46
  renderer.render(links: links, extras: extras).html_safe
47
47
  end
48
48
 
49
+ def id_and_title(links: false, extras: true, html_escape: false)
50
+ "##{proposal.id} - #{title(links: links, extras: extras, html_escape: html_escape)}"
51
+ end
52
+
49
53
  def body(links: false, extras: true, strip_tags: false)
50
- text = proposal.body
51
- text = strip_tags(text) if strip_tags
54
+ text = translated_attribute(proposal.body)
55
+
56
+ text = strip_tags(sanitize_text(text)) if strip_tags
52
57
 
53
58
  renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
54
59
  text = renderer.render(links: links, extras: extras).html_safe
@@ -56,6 +61,75 @@ module Decidim
56
61
  text = Decidim::ContentRenderers::LinkRenderer.new(text).render if links
57
62
  text
58
63
  end
64
+
65
+ # Returns the proposal versions, hiding not published answers
66
+ #
67
+ # Returns an Array.
68
+ def versions
69
+ version_state_published = false
70
+ pending_state_change = nil
71
+
72
+ proposal.versions.map do |version|
73
+ state_published_change = version.changeset["state_published_at"]
74
+ version_state_published = state_published_change.last.present? if state_published_change
75
+
76
+ if version_state_published
77
+ version.changeset["state"] = pending_state_change if pending_state_change
78
+ pending_state_change = nil
79
+ elsif version.changeset["state"]
80
+ pending_state_change = version.changeset.delete("state")
81
+ end
82
+
83
+ next if version.event == "update" && Decidim::Proposals::DiffRenderer.new(version).diff.empty?
84
+
85
+ version
86
+ end.compact
87
+ end
88
+
89
+ delegate :count, to: :versions, prefix: true
90
+
91
+ def resource_manifest
92
+ proposal.class.resource_manifest
93
+ end
94
+
95
+ private
96
+
97
+ def sanitize_unordered_lists(text)
98
+ text.gsub(%r{(?=.*<\/ul>)(?!.*?<li>.*?<\/ol>.*?<\/ul>)<li>}) { |li| li + "• " }
99
+ end
100
+
101
+ def sanitize_ordered_lists(text)
102
+ i = 0
103
+
104
+ text.gsub(%r{(?=.*<\/ol>)(?!.*?<li>.*?<\/ul>.*?<\/ol>)<li>}) do |li|
105
+ i += 1
106
+
107
+ li + "#{i}. "
108
+ end
109
+ end
110
+
111
+ def add_line_feeds_to_paragraphs(text)
112
+ text.gsub("</p>") { |p| p + "\n\n" }
113
+ end
114
+
115
+ def add_line_feeds_to_list_items(text)
116
+ text.gsub("</li>") { |li| li + "\n" }
117
+ end
118
+
119
+ # Adds line feeds after the paragraph and list item closing tags.
120
+ #
121
+ # Returns a String.
122
+ def add_line_feeds(text)
123
+ add_line_feeds_to_paragraphs(add_line_feeds_to_list_items(text))
124
+ end
125
+
126
+ # Maintains the paragraphs and lists separations with their bullet points and
127
+ # list numberings where appropriate.
128
+ #
129
+ # Returns a String.
130
+ def sanitize_text(text)
131
+ add_line_feeds(sanitize_ordered_lists(sanitize_unordered_lists(text)))
132
+ end
59
133
  end
60
134
  end
61
135
  end
@@ -16,8 +16,7 @@ module Decidim
16
16
  spaces = Decidim.participatory_space_manifests.flat_map do |manifest|
17
17
  manifest.participatory_spaces.call(@organization).public_spaces
18
18
  end
19
- components = Decidim::Component.where(participatory_space: spaces).published
20
- @query = Decidim::Proposals::Proposal.where(component: components).joins(:component)
19
+ @query = Decidim::Proposals::Proposal.where(component: visible_component_ids_from_spaces(spaces)).joins(:component)
21
20
  .left_outer_joins(:category)
22
21
  @query = @query.where("decidim_proposals_proposals.created_at <= ?", end_time).accepted
23
22
  @query = @query.group("decidim_categorizations.id", :participatory_space_type, :participatory_space_id)
@@ -9,9 +9,6 @@ module Decidim
9
9
  end
10
10
 
11
11
  def save
12
- return @registry if @registry
13
-
14
- @registry = []
15
12
  cumulative.each do |key, cumulative_value|
16
13
  next if cumulative_value.zero?
17
14
 
@@ -22,10 +19,8 @@ module Decidim
22
19
  participatory_space_type: space_type, participatory_space_id: space_id,
23
20
  related_object_type: "Decidim::Proposals::Proposal", related_object_id: proposal_id)
24
21
  record.assign_attributes(cumulative: cumulative_value, quantity: quantity_value)
25
- @registry << record
22
+ record.save!
26
23
  end
27
- @registry.each(&:save!)
28
- @registry
29
24
  end
30
25
 
31
26
  private
@@ -35,19 +30,27 @@ module Decidim
35
30
 
36
31
  components = Decidim::Component.where(participatory_space: retrieve_participatory_spaces).published
37
32
  proposals = Decidim::Proposals::Proposal.where(component: components).except_withdrawn
38
- @query = Decidim::Proposals::ProposalEndorsement.joins(proposal: :component)
39
- .left_outer_joins(proposal: :category)
40
- .where(proposal: proposals)
41
- @query = @query.where("decidim_proposals_proposal_endorsements.created_at <= ?", end_time)
33
+ join_components = "INNER JOIN decidim_components ON decidim_components.manifest_name = 'proposals' AND proposals.decidim_component_id = decidim_components.id"
34
+ join_categories = <<~EOJOINCATS
35
+ LEFT OUTER JOIN decidim_categorizations
36
+ ON (proposals.id = decidim_categorizations.categorizable_id
37
+ AND decidim_categorizations.categorizable_type = 'Decidim::Proposals::Proposal')
38
+ EOJOINCATS
39
+ @query = Decidim::Endorsement.joins("INNER JOIN decidim_proposals_proposals proposals ON resource_id = proposals.id")
40
+ .joins(join_components)
41
+ .joins(join_categories)
42
+ .where(resource_id: proposals.pluck(:id))
43
+ .where(resource_type: Decidim::Proposals::Proposal.name)
44
+ @query = @query.where("decidim_endorsements.created_at <= ?", end_time)
42
45
  @query = @query.group("decidim_categorizations.id",
43
46
  :participatory_space_type,
44
47
  :participatory_space_id,
45
- :decidim_proposal_id)
48
+ :resource_id)
46
49
  @query
47
50
  end
48
51
 
49
52
  def quantity
50
- @quantity ||= query.where("decidim_proposals_proposal_endorsements.created_at >= ?", start_time).count
53
+ @quantity ||= query.where("decidim_endorsements.created_at >= ?", start_time).count
51
54
  end
52
55
  end
53
56
  end
@@ -59,11 +59,12 @@ module Decidim
59
59
  end
60
60
 
61
61
  def retrieve_endorsements(from_start = false)
62
- @endorsements ||= Decidim::Proposals::ProposalEndorsement.joins(:proposal).where(proposal: retrieve_proposals)
63
- .where("decidim_proposals_proposal_endorsements.created_at <= ?", end_time)
64
- .where(decidim_author_type: "Decidim::UserBaseEntity")
62
+ @endorsements ||= Decidim::Endorsement.joins("INNER JOIN decidim_proposals_proposals proposals ON resource_id = proposals.id")
63
+ .where(resource: retrieve_proposals)
64
+ .where("decidim_endorsements.created_at <= ?", end_time)
65
+ .where(decidim_author_type: "Decidim::UserBaseEntity")
65
66
 
66
- return @endorsements.where("decidim_proposals_proposal_endorsements.created_at >= ?", start_time) if from_start
67
+ return @endorsements.where("decidim_endorsements.created_at >= ?", start_time) if from_start
67
68
 
68
69
  @endorsements
69
70
  end