decidim-proposals 0.19.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) 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/admin/proposals.es6 +24 -11
  8. data/app/assets/javascripts/decidim/proposals/admin/proposals_form.js.es6 +0 -5
  9. data/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +35 -0
  10. data/app/cells/decidim/proposals/collaborative_draft_link_to_proposal_cell.rb +1 -1
  11. data/app/cells/decidim/proposals/collaborative_draft_m/footer.erb +1 -1
  12. data/app/cells/decidim/proposals/collaborative_draft_m_cell.rb +1 -1
  13. data/app/cells/decidim/proposals/cost_report/show.erb +35 -0
  14. data/app/cells/decidim/proposals/cost_report_cell.rb +42 -0
  15. data/app/cells/decidim/proposals/highlighted_proposals_for_component/show.erb +3 -3
  16. data/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb +1 -1
  17. data/app/cells/decidim/proposals/irreversible_action_modal/show.erb +2 -2
  18. data/app/cells/decidim/proposals/irreversible_action_modal_cell.rb +1 -1
  19. data/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb +1 -1
  20. data/app/cells/decidim/proposals/participatory_text_proposal_cell.rb +1 -1
  21. data/app/cells/decidim/proposals/proposal_m/footer.erb +4 -1
  22. data/app/cells/decidim/proposals/proposal_m_cell.rb +37 -9
  23. data/app/cells/decidim/proposals/proposal_tags/show.erb +18 -10
  24. data/app/cells/decidim/proposals/proposal_tags_cell.rb +5 -0
  25. data/app/cells/decidim/proposals/proposals_picker/proposals.erb +12 -0
  26. data/app/cells/decidim/proposals/proposals_picker/show.erb +14 -0
  27. data/app/cells/decidim/proposals/proposals_picker_cell.rb +72 -0
  28. data/app/commands/decidim/proposals/admin/answer_proposal.rb +24 -46
  29. data/app/commands/decidim/proposals/admin/assign_proposals_to_valuator.rb +61 -0
  30. data/app/commands/decidim/proposals/admin/create_proposal.rb +6 -1
  31. data/app/commands/decidim/proposals/admin/create_proposal_note.rb +15 -0
  32. data/app/commands/decidim/proposals/admin/notify_proposal_answer.rb +85 -0
  33. data/app/commands/decidim/proposals/admin/publish_answers.rb +67 -0
  34. data/app/commands/decidim/proposals/admin/unassign_proposals_from_valuator.rb +62 -0
  35. data/app/commands/decidim/proposals/admin/update_proposal.rb +1 -1
  36. data/app/commands/decidim/proposals/admin/update_proposal_scope.rb +75 -0
  37. data/app/commands/decidim/proposals/create_collaborative_draft.rb +1 -1
  38. data/app/commands/decidim/proposals/create_proposal.rb +1 -1
  39. data/app/commands/decidim/proposals/gallery_methods.rb +2 -51
  40. data/app/commands/decidim/proposals/update_proposal.rb +1 -1
  41. data/app/controllers/concerns/decidim/proposals/admin/filterable.rb +82 -0
  42. data/app/controllers/concerns/decidim/proposals/admin/picker.rb +21 -0
  43. data/app/controllers/concerns/decidim/proposals/orderable.rb +13 -2
  44. data/app/controllers/decidim/proposals/admin/proposal_answers_controller.rb +16 -6
  45. data/app/controllers/decidim/proposals/admin/proposal_notes_controller.rb +8 -9
  46. data/app/controllers/decidim/proposals/admin/proposals_controller.rb +105 -29
  47. data/app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb +58 -0
  48. data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +19 -3
  49. data/app/controllers/decidim/proposals/proposals_controller.rb +45 -11
  50. data/app/controllers/decidim/proposals/versions_controller.rb +9 -16
  51. data/app/events/decidim/proposals/admin/proposal_note_created_event.rb +27 -0
  52. data/app/events/decidim/proposals/admin/update_proposal_scope_event.rb +11 -0
  53. data/app/forms/decidim/proposals/admin/participatory_text_proposal_form.rb +13 -0
  54. data/app/forms/decidim/proposals/admin/preview_participatory_text_form.rb +2 -2
  55. data/app/forms/decidim/proposals/admin/proposal_answer_form.rb +27 -2
  56. data/app/forms/decidim/proposals/admin/proposal_base_form.rb +129 -0
  57. data/app/forms/decidim/proposals/admin/proposal_form.rb +2 -120
  58. data/app/forms/decidim/proposals/admin/valuation_assignment_form.rb +37 -0
  59. data/app/forms/decidim/proposals/proposal_form.rb +4 -0
  60. data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +13 -1
  61. data/app/helpers/decidim/proposals/admin/filterable_helper.rb +17 -0
  62. data/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb +35 -0
  63. data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +63 -0
  64. data/app/helpers/decidim/proposals/admin/proposals_helper.rb +122 -0
  65. data/app/helpers/decidim/proposals/admin/proposals_picker_helper.rb +30 -0
  66. data/app/helpers/decidim/proposals/application_helper.rb +51 -30
  67. data/app/helpers/decidim/proposals/collaborative_draft_helper.rb +9 -9
  68. data/app/helpers/decidim/proposals/control_version_helper.rb +1 -37
  69. data/app/helpers/decidim/proposals/proposal_cells_helper.rb +1 -1
  70. data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +0 -145
  71. data/app/helpers/decidim/proposals/proposal_votes_helper.rb +2 -2
  72. data/app/helpers/decidim/proposals/proposal_wizard_helper.rb +24 -7
  73. data/app/helpers/decidim/proposals/proposals_helper.rb +66 -0
  74. data/app/models/decidim/proposals/proposal.rb +167 -29
  75. data/app/models/decidim/proposals/valuation_assignment.rb +24 -0
  76. data/app/permissions/decidim/proposals/admin/permissions.rb +77 -11
  77. data/app/permissions/decidim/proposals/permissions.rb +1 -22
  78. data/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb +1 -1
  79. data/app/presenters/decidim/proposals/admin_log/valuation_assignment_presenter.rb +51 -0
  80. data/app/presenters/decidim/proposals/admin_log/value_types/valuator_role_user_presenter.rb +19 -0
  81. data/app/presenters/decidim/proposals/collaborative_draft_presenter.rb +2 -28
  82. data/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb +22 -0
  83. data/app/presenters/decidim/proposals/proposal_presenter.rb +41 -10
  84. data/app/queries/decidim/proposals/metrics/accepted_proposals_metric_manage.rb +1 -2
  85. data/app/queries/decidim/proposals/metrics/endorsements_metric_manage.rb +15 -12
  86. data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +5 -4
  87. data/app/queries/decidim/proposals/metrics/proposals_metric_manage.rb +2 -8
  88. data/app/queries/decidim/proposals/metrics/votes_metric_manage.rb +3 -9
  89. data/app/services/decidim/proposals/collaborative_draft_search.rb +18 -10
  90. data/app/services/decidim/proposals/diff_renderer.rb +2 -0
  91. data/app/services/decidim/proposals/proposal_builder.rb +1 -1
  92. data/app/services/decidim/proposals/proposal_search.rb +45 -47
  93. data/app/types/decidim/proposals/proposal_input_filter.rb +29 -0
  94. data/app/types/decidim/proposals/proposal_input_sort.rb +22 -0
  95. data/app/types/decidim/proposals/proposal_type.rb +32 -11
  96. data/app/types/decidim/proposals/proposals_type.rb +22 -15
  97. data/app/validators/proposal_length_validator.rb +38 -0
  98. data/app/views/decidim/proposals/admin/participatory_texts/index.html.erb +9 -1
  99. data/app/views/decidim/proposals/admin/proposal_answers/_form.html.erb +35 -0
  100. data/app/views/decidim/proposals/admin/proposal_notes/_form.html.erb +1 -1
  101. data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes.html.erb +3 -3
  102. data/app/views/decidim/proposals/admin/proposals/_bulk-actions.html.erb +8 -2
  103. data/app/views/decidim/proposals/admin/proposals/_form.html.erb +4 -24
  104. data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +25 -17
  105. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_assign_to_valuator.html.erb +15 -0
  106. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_dropdown.html.erb +21 -1
  107. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_publish_answers.html.erb +14 -0
  108. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_scope-change.html.erb +25 -0
  109. data/app/views/decidim/proposals/admin/proposals/bulk_actions/_unassign_from_valuator.html.erb +15 -0
  110. data/app/views/decidim/proposals/admin/proposals/index.html.erb +16 -7
  111. data/app/views/decidim/proposals/admin/proposals/publish_answers.js.erb +12 -0
  112. data/app/views/decidim/proposals/admin/proposals/show.html.erb +186 -0
  113. data/app/views/decidim/proposals/admin/proposals/update_category.js.erb +3 -2
  114. data/app/views/decidim/proposals/admin/proposals/update_scope.js.erb +27 -0
  115. data/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb +6 -4
  116. data/app/views/decidim/proposals/collaborative_drafts/_filters.html.erb +9 -7
  117. data/app/views/decidim/proposals/collaborative_drafts/_new_collaborative_draft_button.html.erb +4 -4
  118. data/app/views/decidim/proposals/collaborative_drafts/_reject_request_access_form.html.erb +1 -1
  119. data/app/views/decidim/proposals/collaborative_drafts/_wizard_aside.html.erb +4 -2
  120. data/app/views/decidim/proposals/collaborative_drafts/compare.html.erb +2 -0
  121. data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +2 -0
  122. data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +3 -1
  123. data/app/views/decidim/proposals/collaborative_drafts/index.html.erb +4 -2
  124. data/app/views/decidim/proposals/collaborative_drafts/new.html.erb +4 -0
  125. data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +29 -30
  126. data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +6 -4
  127. data/app/views/decidim/proposals/proposals/_endorsements_card_row.html.erb +0 -16
  128. data/app/views/decidim/proposals/proposals/_filters.html.erb +19 -17
  129. data/app/views/decidim/proposals/proposals/_proposal_badge.html.erb +1 -4
  130. data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +1 -11
  131. data/app/views/decidim/proposals/proposals/_proposal_similar.html.erb +2 -2
  132. data/app/views/decidim/proposals/proposals/_proposals.html.erb +14 -0
  133. data/app/views/decidim/proposals/proposals/_vote_button.html.erb +14 -7
  134. data/app/views/decidim/proposals/proposals/_wizard_aside.html.erb +4 -2
  135. data/app/views/decidim/proposals/proposals/_wizard_header.html.erb +4 -3
  136. data/app/views/decidim/proposals/proposals/compare.html.erb +2 -0
  137. data/app/views/decidim/proposals/proposals/complete.html.erb +2 -0
  138. data/app/views/decidim/proposals/proposals/edit.html.erb +3 -1
  139. data/app/views/decidim/proposals/proposals/edit_draft.html.erb +2 -0
  140. data/app/views/decidim/proposals/proposals/index.html.erb +7 -12
  141. data/app/views/decidim/proposals/proposals/new.html.erb +6 -2
  142. data/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb +1 -1
  143. data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_vote_button.html.erb +10 -3
  144. data/app/views/decidim/proposals/proposals/participatory_texts/_view_index.html.erb +1 -1
  145. data/app/views/decidim/proposals/proposals/preview.html.erb +7 -8
  146. data/app/views/decidim/proposals/proposals/show.html.erb +62 -71
  147. data/app/views/decidim/proposals/versions/index.html.erb +14 -32
  148. data/app/views/decidim/proposals/versions/show.html.erb +16 -34
  149. data/config/locales/ar.yml +74 -66
  150. data/config/locales/bg-BG.yml +237 -0
  151. data/config/locales/ca.yml +173 -65
  152. data/config/locales/cs.yml +187 -79
  153. data/config/locales/da-DK.yml +1 -0
  154. data/config/locales/de.yml +266 -162
  155. data/config/locales/el-GR.yml +1 -0
  156. data/config/locales/el.yml +876 -0
  157. data/config/locales/en.yml +179 -71
  158. data/config/locales/es-MX.yml +173 -63
  159. data/config/locales/es-PY.yml +173 -63
  160. data/config/locales/es.yml +173 -65
  161. data/config/locales/et-EE.yml +1 -0
  162. data/config/locales/eu.yml +43 -63
  163. data/config/locales/fi-plain.yml +173 -65
  164. data/config/locales/fi.yml +215 -107
  165. data/config/locales/fr-CA.yml +876 -0
  166. data/config/locales/fr.yml +151 -65
  167. data/config/locales/ga-IE.yml +1 -0
  168. data/config/locales/gl.yml +43 -63
  169. data/config/locales/hr-HR.yml +1 -0
  170. data/config/locales/hu.yml +153 -75
  171. data/config/locales/id-ID.yml +43 -62
  172. data/config/locales/is-IS.yml +274 -0
  173. data/config/locales/it.yml +172 -82
  174. data/config/locales/ja-JP.yml +886 -0
  175. data/config/locales/lt-LT.yml +1 -0
  176. data/config/locales/lv-LV.yml +858 -0
  177. data/config/locales/mt-MT.yml +1 -0
  178. data/config/locales/nl.yml +274 -188
  179. data/config/locales/no.yml +786 -0
  180. data/config/locales/pl.yml +194 -66
  181. data/config/locales/pt-BR.yml +44 -67
  182. data/config/locales/pt.yml +437 -331
  183. data/config/locales/ro-RO.yml +840 -0
  184. data/config/locales/ru.yml +14 -47
  185. data/config/locales/sk-SK.yml +896 -0
  186. data/config/locales/sk.yml +869 -0
  187. data/config/locales/sl.yml +26 -0
  188. data/config/locales/sr-CS.yml +126 -0
  189. data/config/locales/sv.yml +253 -162
  190. data/config/locales/tr-TR.yml +43 -63
  191. data/config/locales/uk.yml +14 -47
  192. data/db/migrate/20181003074440_fix_user_groups_ids_in_proposals_endorsements.rb +4 -0
  193. data/db/migrate/20191206154128_add_endorsements_counter_cache_to_proposals.rb +7 -0
  194. data/db/migrate/20200120215928_move_proposal_endorsements_to_core_endorsements.rb +52 -0
  195. data/db/migrate/20200203111239_add_proposal_valuation_assignments.rb +12 -0
  196. data/db/migrate/20200210135152_add_costs_to_proposals.rb +9 -0
  197. data/db/migrate/20200212120110_sync_proposals_state_with_amendments_state.rb +28 -0
  198. data/db/migrate/20200227175922_add_state_published_at_to_proposals.rb +7 -0
  199. data/db/migrate/20200306123652_publish_existing_proposals_state.rb +15 -0
  200. data/db/migrate/20200730131631_move_proposal_endorsed_event_notifications_to_resource_endorsed_event.rb +20 -0
  201. data/lib/decidim/proposals.rb +1 -0
  202. data/lib/decidim/proposals/admin_engine.rb +7 -3
  203. data/lib/decidim/proposals/component.rb +47 -23
  204. data/lib/decidim/proposals/engine.rb +2 -6
  205. data/lib/decidim/proposals/test/capybara_proposals_picker.rb +49 -0
  206. data/lib/decidim/proposals/test/factories.rb +56 -10
  207. data/lib/decidim/proposals/valuatable.rb +21 -0
  208. data/lib/decidim/proposals/version.rb +1 -1
  209. metadata +94 -53
  210. data/app/assets/javascripts/decidim/proposals/identity_selector_dialog.js.es6 +0 -56
  211. data/app/cells/decidim/proposals/endorsers_list/show.erb +0 -17
  212. data/app/cells/decidim/proposals/endorsers_list_cell.rb +0 -31
  213. data/app/commands/decidim/proposals/attachment_methods.rb +0 -43
  214. data/app/commands/decidim/proposals/endorse_proposal.rb +0 -59
  215. data/app/commands/decidim/proposals/unendorse_proposal.rb +0 -40
  216. data/app/controllers/decidim/proposals/proposal_endorsements_controller.rb +0 -60
  217. data/app/models/decidim/proposals/proposal_endorsement.rb +0 -37
  218. data/app/views/decidim/proposals/admin/proposal_answers/edit.html.erb +0 -22
  219. data/app/views/decidim/proposals/admin/proposal_notes/index.html.erb +0 -3
  220. data/app/views/decidim/proposals/admin/shared/_info_proposal.html.erb +0 -20
  221. data/app/views/decidim/proposals/proposal_endorsements/_identity.html.erb +0 -9
  222. data/app/views/decidim/proposals/proposal_endorsements/identities.html.erb +0 -12
  223. data/app/views/decidim/proposals/proposal_endorsements/update_buttons_and_counters.js.erb +0 -20
  224. data/app/views/decidim/proposals/proposal_widgets/show.html.erb +0 -4
  225. data/app/views/decidim/proposals/proposals/_endorsement_button.html.erb +0 -11
  226. data/app/views/decidim/proposals/proposals/_endorsement_identities_cabin.html.erb +0 -13
  227. data/app/views/decidim/proposals/versions/_version.html.erb +0 -20
@@ -0,0 +1,11 @@
1
+ # frozen-string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ class UpdateProposalScopeEvent < Decidim::Events::SimpleEvent
7
+ include Decidim::Events::AuthorEvent
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ # A form object to be used when admin users want to create a proposal
7
+ # through the participatory texts.
8
+ class ParticipatoryTextProposalForm < Admin::ProposalBaseForm
9
+ validates :title, length: { maximum: 150 }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -6,11 +6,11 @@ module Decidim
6
6
  # A form object to be used when admin users want to review a collection of proposals
7
7
  # from a participatory text.
8
8
  class PreviewParticipatoryTextForm < Decidim::Form
9
- attribute :proposals, Array[Decidim::Proposals::Admin::ProposalForm]
9
+ attribute :proposals, Array[Decidim::Proposals::Admin::ParticipatoryTextProposalForm]
10
10
 
11
11
  def from_models(proposals)
12
12
  self.proposals = proposals.collect do |proposal|
13
- ProposalForm.from_model(proposal)
13
+ Admin::ParticipatoryTextProposalForm.from_model(proposal)
14
14
  end
15
15
  end
16
16
 
@@ -9,10 +9,35 @@ module Decidim
9
9
  mimic :proposal_answer
10
10
 
11
11
  translatable_attribute :answer, String
12
- attribute :state, String
12
+ translatable_attribute :cost_report, String
13
+ translatable_attribute :execution_period, String
14
+ attribute :cost, Float
15
+ attribute :internal_state, String
13
16
 
14
- validates :state, presence: true, inclusion: { in: %w(accepted rejected evaluating) }
17
+ validates :internal_state, presence: true, inclusion: { in: %w(accepted rejected evaluating) }
15
18
  validates :answer, translatable_presence: true, if: ->(form) { form.state == "rejected" }
19
+
20
+ with_options if: :costs_required? do
21
+ validates :cost, numericality: true, presence: true
22
+ validates :cost_report, translatable_presence: true
23
+ validates :execution_period, translatable_presence: true
24
+ end
25
+
26
+ alias state internal_state
27
+
28
+ def costs_required?
29
+ costs_enabled? && state == "accepted"
30
+ end
31
+
32
+ def publish_answer?
33
+ current_component.current_settings.publish_answers_immediately?
34
+ end
35
+
36
+ private
37
+
38
+ def costs_enabled?
39
+ current_component.current_settings.answers_with_costs?
40
+ end
16
41
  end
17
42
  end
18
43
  end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ # A form object to be used when admin users want to create a proposal.
7
+ class ProposalBaseForm < Decidim::Form
8
+ include Decidim::ApplicationHelper
9
+ mimic :proposal
10
+
11
+ attribute :title, String
12
+ attribute :body, String
13
+ attribute :address, String
14
+ attribute :latitude, Float
15
+ attribute :longitude, Float
16
+ attribute :category_id, Integer
17
+ attribute :scope_id, Integer
18
+ attribute :attachment, AttachmentForm
19
+ attribute :position, Integer
20
+ attribute :created_in_meeting, Boolean
21
+ attribute :meeting_id, Integer
22
+ attribute :suggested_hashtags, Array[String]
23
+ attribute :photos, Array[String]
24
+ attribute :add_photos, Array
25
+
26
+ validates :title, :body, presence: true
27
+ validates :address, geocoding: true, if: -> { current_component.settings.geocoding_enabled? }
28
+ validates :category, presence: true, if: ->(form) { form.category_id.present? }
29
+ validates :scope, presence: true, if: ->(form) { form.scope_id.present? }
30
+ validates :meeting_as_author, presence: true, if: ->(form) { form.created_in_meeting? }
31
+
32
+ validate :scope_belongs_to_participatory_space_scope
33
+
34
+ validate :notify_missing_attachment_if_errored
35
+
36
+ delegate :categories, to: :current_component
37
+
38
+ def map_model(model)
39
+ return unless model.categorization
40
+
41
+ self.category_id = model.categorization.decidim_category_id
42
+ self.scope_id = model.decidim_scope_id
43
+
44
+ @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(model.body).extra_hashtags.map(&:name).map(&:downcase)
45
+ end
46
+
47
+ alias component current_component
48
+
49
+ # Finds the Category from the category_id.
50
+ #
51
+ # Returns a Decidim::Category
52
+ def category
53
+ @category ||= categories.find_by(id: category_id)
54
+ end
55
+
56
+ # Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
57
+ #
58
+ # Returns a Decidim::Scope
59
+ def scope
60
+ @scope ||= @scope_id ? current_participatory_space.scopes.find_by(id: @scope_id) : current_participatory_space.scope
61
+ end
62
+
63
+ # Scope identifier
64
+ #
65
+ # Returns the scope identifier related to the proposal
66
+ def scope_id
67
+ @scope_id || scope&.id
68
+ end
69
+
70
+ # Finds the Meetings of the current participatory space
71
+ def meetings
72
+ @meetings ||= Decidim.find_resource_manifest(:meetings).try(:resource_scope, current_component)
73
+ &.order(title: :asc)
74
+ end
75
+
76
+ # Return the meeting as author
77
+ def meeting_as_author
78
+ @meeting_as_author ||= meetings.find_by(id: meeting_id)
79
+ end
80
+
81
+ def author
82
+ return current_organization unless created_in_meeting?
83
+
84
+ meeting_as_author
85
+ end
86
+
87
+ def extra_hashtags
88
+ @extra_hashtags ||= (component_automatic_hashtags + suggested_hashtags).uniq
89
+ end
90
+
91
+ def suggested_hashtags
92
+ downcased_suggested_hashtags = Array(@suggested_hashtags&.map(&:downcase)).to_set
93
+ component_suggested_hashtags.select { |hashtag| downcased_suggested_hashtags.member?(hashtag.downcase) }
94
+ end
95
+
96
+ def suggested_hashtag_checked?(hashtag)
97
+ suggested_hashtags.member?(hashtag)
98
+ end
99
+
100
+ def component_automatic_hashtags
101
+ @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.automatic_hashtags)
102
+ end
103
+
104
+ def component_suggested_hashtags
105
+ @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.suggested_hashtags)
106
+ end
107
+
108
+ private
109
+
110
+ def scope_belongs_to_participatory_space_scope
111
+ errors.add(:scope_id, :invalid) if current_participatory_space.out_of_scope?(scope)
112
+ end
113
+
114
+ # This method will add an error to the `attachment` field only if there's
115
+ # any error in any other field. This is needed because when the form has
116
+ # an error, the attachment is lost, so we need a way to inform the user of
117
+ # this problem.
118
+ def notify_missing_attachment_if_errored
119
+ errors.add(:attachment, :needs_to_be_reattached) if errors.any? && attachment.present?
120
+ errors.add(:add_photos, :needs_to_be_reattached) if errors.any? && add_photos.present?
121
+ end
122
+
123
+ def ordered_hashtag_list(string)
124
+ string.to_s.split.reject(&:blank?).uniq.sort_by(&:parameterize)
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -4,126 +4,8 @@ module Decidim
4
4
  module Proposals
5
5
  module Admin
6
6
  # A form object to be used when admin users want to create a proposal.
7
- class ProposalForm < Decidim::Form
8
- include Decidim::ApplicationHelper
9
- mimic :proposal
10
-
11
- attribute :title, String
12
- attribute :body, String
13
- attribute :address, String
14
- attribute :latitude, Float
15
- attribute :longitude, Float
16
- attribute :category_id, Integer
17
- attribute :scope_id, Integer
18
- attribute :attachment, AttachmentForm
19
- attribute :position, Integer
20
- attribute :created_in_meeting, Boolean
21
- attribute :meeting_id, Integer
22
- attribute :suggested_hashtags, Array[String]
23
- attribute :photos, Array[String]
24
- attribute :add_photos, Array
25
-
26
- validates :title, :body, presence: true
27
- validates :title, length: { maximum: 150 }
28
- validates :address, geocoding: true, if: -> { current_component.settings.geocoding_enabled? }
29
- validates :category, presence: true, if: ->(form) { form.category_id.present? }
30
- validates :scope, presence: true, if: ->(form) { form.scope_id.present? }
31
- validates :meeting_as_author, presence: true, if: ->(form) { form.created_in_meeting? }
32
-
33
- validate :scope_belongs_to_participatory_space_scope
34
-
35
- validate :notify_missing_attachment_if_errored
36
-
37
- delegate :categories, to: :current_component
38
-
39
- def map_model(model)
40
- return unless model.categorization
41
-
42
- self.category_id = model.categorization.decidim_category_id
43
- self.scope_id = model.decidim_scope_id
44
-
45
- @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(model.body).extra_hashtags.map(&:name).map(&:downcase)
46
- end
47
-
48
- alias component current_component
49
-
50
- # Finds the Category from the category_id.
51
- #
52
- # Returns a Decidim::Category
53
- def category
54
- @category ||= categories.find_by(id: category_id)
55
- end
56
-
57
- # Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
58
- #
59
- # Returns a Decidim::Scope
60
- def scope
61
- @scope ||= @scope_id ? current_participatory_space.scopes.find_by(id: @scope_id) : current_participatory_space.scope
62
- end
63
-
64
- # Scope identifier
65
- #
66
- # Returns the scope identifier related to the proposal
67
- def scope_id
68
- @scope_id || scope&.id
69
- end
70
-
71
- # Finds the Meetings of the current participatory space
72
- def meetings
73
- @meetings ||= Decidim.find_resource_manifest(:meetings).try(:resource_scope, current_component)
74
- &.order(title: :asc)
75
- end
76
-
77
- # Return the meeting as author
78
- def meeting_as_author
79
- @meeting_as_author ||= meetings.find_by(id: meeting_id)
80
- end
81
-
82
- def author
83
- return current_organization unless created_in_meeting?
84
-
85
- meeting_as_author
86
- end
87
-
88
- def extra_hashtags
89
- @extra_hashtags ||= (component_automatic_hashtags + suggested_hashtags).uniq
90
- end
91
-
92
- def suggested_hashtags
93
- downcased_suggested_hashtags = Array(@suggested_hashtags&.map(&:downcase)).to_set
94
- component_suggested_hashtags.select { |hashtag| downcased_suggested_hashtags.member?(hashtag.downcase) }
95
- end
96
-
97
- def suggested_hashtag_checked?(hashtag)
98
- suggested_hashtags.member?(hashtag)
99
- end
100
-
101
- def component_automatic_hashtags
102
- @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.automatic_hashtags)
103
- end
104
-
105
- def component_suggested_hashtags
106
- @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.suggested_hashtags)
107
- end
108
-
109
- private
110
-
111
- def scope_belongs_to_participatory_space_scope
112
- errors.add(:scope_id, :invalid) if current_participatory_space.out_of_scope?(scope)
113
- end
114
-
115
- # This method will add an error to the `attachment` field only if there's
116
- # any error in any other field. This is needed because when the form has
117
- # an error, the attachment is lost, so we need a way to inform the user of
118
- # this problem.
119
- def notify_missing_attachment_if_errored
120
- errors.add(:attachment, :needs_to_be_reattached) if errors.any? && attachment.present?
121
- errors.add(:add_photos, :needs_to_be_reattached) if errors.any? && add_photos.present?
122
- end
123
-
124
- def ordered_hashtag_list(string)
125
- string.to_s.split.reject(&:blank?).uniq.sort_by(&:parameterize)
126
- end
7
+ class ProposalForm < Admin::ProposalBaseForm
8
+ validates :title, length: { in: 15..150 }
127
9
  end
128
10
  end
129
11
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ class ValuationAssignmentForm < Decidim::Form
7
+ mimic :valuator_role
8
+
9
+ attribute :id, Integer
10
+ attribute :proposal_ids, Array
11
+
12
+ validates :valuator_role, :proposals, :current_component, presence: true
13
+ validate :same_participatory_space
14
+
15
+ def proposals
16
+ @proposals ||= Decidim::Proposals::Proposal.where(component: current_component, id: proposal_ids).uniq
17
+ end
18
+
19
+ def valuator_role
20
+ @valuator_role ||= current_component.participatory_space.user_roles(:valuator).find_by(id: id)
21
+ end
22
+
23
+ def valuator_user
24
+ return unless valuator_role
25
+
26
+ @valuator_user ||= valuator_role.user
27
+ end
28
+
29
+ def same_participatory_space
30
+ return if !valuator_role || !current_component
31
+
32
+ errors.add(:id, :invalid) if current_component.participatory_space != valuator_role.participatory_space
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -30,6 +30,10 @@ module Decidim
30
30
  super
31
31
 
32
32
  @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(model.body).extra_hashtags.map(&:name).map(&:downcase)
33
+
34
+ # The scope attribute is with different key (decidim_scope_id), so it
35
+ # has to be manually mapped.
36
+ self.scope_id = model.scope.id if model.scope
33
37
  end
34
38
 
35
39
  # Finds the Category from the category_id.
@@ -8,12 +8,18 @@ module Decidim
8
8
 
9
9
  attribute :title, String
10
10
  attribute :body, String
11
+ attribute :body_template, String
11
12
  attribute :user_group_id, Integer
12
13
 
13
14
  validates :title, :body, presence: true, etiquette: true
14
- validates :title, length: { maximum: 150 }
15
+ validates :title, length: { in: 15..150 }
16
+ validates :body, proposal_length: {
17
+ minimum: 15,
18
+ maximum: ->(record) { record.component.settings.proposal_length }
19
+ }
15
20
 
16
21
  validate :proposal_length
22
+ validate :body_is_not_bare_template
17
23
 
18
24
  alias component current_component
19
25
 
@@ -32,6 +38,12 @@ module Decidim
32
38
  length = current_component.settings.proposal_length
33
39
  errors.add(:body, :too_long, count: length) if body.length > length
34
40
  end
41
+
42
+ def body_is_not_bare_template
43
+ return if body_template.blank?
44
+
45
+ errors.add(:body, :cant_be_equal_to_template) if body.presence == body_template.presence
46
+ end
35
47
  end
36
48
  end
37
49
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ module FilterableHelper
7
+ def extra_dropdown_submenu_options_items(filter, i18n_scope)
8
+ options = case filter
9
+ when :state_eq
10
+ content_tag(:li, filter_link_value(:state_null, true, i18n_scope))
11
+ end
12
+ [options].compact
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module Admin
6
+ module ProposalBulkActionsHelper
7
+ # Public: Generates a select field with the valuators of the given participatory space.
8
+ #
9
+ # participatory_space - A participatory space instance.
10
+ # prompt - An i18n string to show as prompt
11
+ #
12
+ # Returns a String.
13
+ def bulk_valuators_select(participatory_space, prompt)
14
+ options_for_select = find_valuators_for_select(participatory_space)
15
+ select(:valuator_role, :id, options_for_select, prompt: prompt)
16
+ end
17
+
18
+ # Internal: A method to cache to queries to find the valuators for the
19
+ # current space.
20
+ def find_valuators_for_select(participatory_space)
21
+ return @valuators_for_select if @valuators_for_select
22
+
23
+ valuator_roles = participatory_space.user_roles(:valuator)
24
+ valuators = Decidim::User.where(id: valuator_roles.pluck(:decidim_user_id)).to_a
25
+
26
+ @valuators_for_select = valuator_roles.map do |role|
27
+ valuator = valuators.find { |user| user.id == role.decidim_user_id }
28
+
29
+ [valuator.name, role.id]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end