decidim-initiatives 0.27.5 → 0.28.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -3
  3. data/app/cells/decidim/initiatives/content_blocks/highlighted_initiatives_cell.rb +17 -18
  4. data/app/cells/decidim/initiatives/initiative_cell.rb +6 -1
  5. data/app/cells/decidim/initiatives/initiative_dropdown_metadata_cell.rb +19 -0
  6. data/app/cells/decidim/initiatives/initiative_g_cell.rb +31 -0
  7. data/app/cells/decidim/initiatives/initiative_metadata_g_cell.rb +62 -0
  8. data/app/cells/decidim/initiatives/initiative_s_cell.rb +15 -0
  9. data/app/cells/decidim/initiatives_votes/vote/show.erb +25 -19
  10. data/app/cells/decidim/initiatives_votes/vote_cell.rb +3 -1
  11. data/app/commands/decidim/initiatives/admin/accept_initiative.rb +40 -0
  12. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +1 -1
  13. data/app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb +1 -1
  14. data/app/commands/decidim/initiatives/admin/discard_initiative.rb +40 -0
  15. data/app/commands/decidim/initiatives/admin/publish_initiative.rb +1 -1
  16. data/app/commands/decidim/initiatives/admin/reject_initiative.rb +40 -0
  17. data/app/commands/decidim/initiatives/admin/send_initiative_to_technical_validation.rb +2 -2
  18. data/app/commands/decidim/initiatives/admin/unpublish_initiative.rb +1 -1
  19. data/app/commands/decidim/initiatives/admin/update_initiative.rb +1 -1
  20. data/app/commands/decidim/initiatives/admin/update_initiative_answer.rb +1 -1
  21. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +1 -1
  22. data/app/commands/decidim/initiatives/admin/update_initiative_type_scope.rb +1 -1
  23. data/app/commands/decidim/initiatives/admin/update_initiatives_settings.rb +1 -1
  24. data/app/commands/decidim/initiatives/attachment_methods.rb +2 -24
  25. data/app/commands/decidim/initiatives/create_initiative.rb +19 -14
  26. data/app/commands/decidim/initiatives/send_initiative_to_technical_validation.rb +2 -2
  27. data/app/commands/decidim/initiatives/spawn_committee_request.rb +1 -1
  28. data/app/commands/decidim/initiatives/unvote_initiative.rb +1 -1
  29. data/app/commands/decidim/initiatives/update_initiative.rb +9 -2
  30. data/app/commands/decidim/initiatives/validate_mobile_phone.rb +2 -2
  31. data/app/commands/decidim/initiatives/vote_initiative.rb +5 -5
  32. data/app/constraints/decidim/initiatives/current_initiative.rb +1 -1
  33. data/app/controllers/concerns/decidim/initiatives/admin/filterable.rb +2 -2
  34. data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +1 -1
  35. data/app/controllers/decidim/initiatives/admin/answers_controller.rb +3 -0
  36. data/app/controllers/decidim/initiatives/admin/committee_requests_controller.rb +2 -0
  37. data/app/controllers/decidim/initiatives/admin/components_controller.rb +3 -0
  38. data/app/controllers/decidim/initiatives/admin/initiative_attachments_controller.rb +2 -0
  39. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +17 -6
  40. data/app/controllers/decidim/initiatives/admin/initiatives_permissions_controller.rb +3 -0
  41. data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +2 -0
  42. data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +30 -0
  43. data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +14 -0
  44. data/app/controllers/decidim/initiatives/admin/initiatives_types_permissions_controller.rb +21 -0
  45. data/app/controllers/decidim/initiatives/admin/moderations/reports_controller.rb +2 -2
  46. data/app/controllers/decidim/initiatives/admin/moderations_controller.rb +4 -2
  47. data/app/controllers/decidim/initiatives/application_controller.rb +0 -1
  48. data/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb +25 -0
  49. data/app/controllers/decidim/initiatives/authorization_sign_modals_controller.rb +2 -2
  50. data/app/controllers/decidim/initiatives/committee_requests_controller.rb +0 -2
  51. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +62 -115
  52. data/app/controllers/decidim/initiatives/initiative_signatures_controller.rb +113 -81
  53. data/app/controllers/decidim/initiatives/initiative_types_controller.rb +7 -0
  54. data/app/controllers/decidim/initiatives/initiatives_controller.rb +37 -17
  55. data/app/controllers/decidim/initiatives/versions_controller.rb +0 -1
  56. data/app/events/decidim/initiatives/admin/initiative_sent_to_technical_validation_event.rb +1 -1
  57. data/app/events/decidim/initiatives/admin/support_threshold_reached_event.rb +1 -1
  58. data/app/events/decidim/initiatives/approve_membership_request_event.rb +12 -12
  59. data/app/events/decidim/initiatives/create_initiative_event.rb +6 -6
  60. data/app/events/decidim/initiatives/endorse_initiative_event.rb +1 -1
  61. data/app/events/decidim/initiatives/extend_initiative_event.rb +1 -1
  62. data/app/events/decidim/initiatives/initiative_sent_to_technical_validation_event.rb +1 -1
  63. data/app/events/decidim/initiatives/milestone_completed_event.rb +1 -1
  64. data/app/events/decidim/initiatives/revoke_membership_request_event.rb +12 -12
  65. data/app/events/decidim/initiatives/spawn_committee_request_event.rb +12 -12
  66. data/app/forms/decidim/initiatives/admin/initiative_form.rb +1 -1
  67. data/app/forms/decidim/initiatives/initiative_form.rb +22 -31
  68. data/app/forms/decidim/initiatives/previous_form.rb +4 -0
  69. data/app/forms/decidim/initiatives/vote_form.rb +11 -11
  70. data/app/helpers/decidim/initiatives/admin/initiatives_helper.rb +1 -1
  71. data/app/helpers/decidim/initiatives/application_helper.rb +4 -61
  72. data/app/helpers/decidim/initiatives/initiative_helper.rb +48 -5
  73. data/app/helpers/decidim/initiatives/initiatives_helper.rb +33 -12
  74. data/app/jobs/decidim/initiatives/export_initiatives_job.rb +1 -1
  75. data/app/models/decidim/initiative.rb +16 -14
  76. data/app/models/decidim/initiatives_vote.rb +1 -1
  77. data/app/packs/entrypoints/decidim_initiatives.js +3 -0
  78. data/app/packs/images/decidim/gamification/badges/decidim_gamification_badges_initiatives.svg +42 -1
  79. data/app/packs/src/decidim/initiatives/application.js +0 -1
  80. data/app/packs/src/decidim/initiatives/scoped_type.js +1 -1
  81. data/app/packs/stylesheets/decidim/initiatives/initiatives-votes.scss +21 -21
  82. data/app/packs/stylesheets/decidim/initiatives/print-initiative.scss +47 -35
  83. data/app/packs/stylesheets/initiatives.scss +171 -0
  84. data/app/permissions/decidim/initiatives/permissions.rb +3 -3
  85. data/app/presenters/decidim/initiatives/admin_log/initiative_presenter.rb +2 -2
  86. data/app/presenters/decidim/initiatives/admin_log/initiatives_settings_presenter.rb +2 -2
  87. data/app/presenters/decidim/initiatives/admin_log/initiatives_type_presenter.rb +2 -2
  88. data/app/queries/decidim/initiatives/organization_prioritized_initiatives.rb +1 -1
  89. data/app/queries/decidim/initiatives/similar_initiatives.rb +2 -2
  90. data/app/queries/decidim/initiatives/support_period_finished_initiatives.rb +1 -1
  91. data/app/queries/decidim/initiatives/user_authorizations.rb +1 -1
  92. data/app/services/decidim/initiatives/pdf_signature_example.rb +44 -52
  93. data/app/views/decidim/initiatives/_modal.html.erb +15 -0
  94. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +21 -19
  95. data/app/views/decidim/initiatives/admin/answers/edit.html.erb +41 -27
  96. data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +41 -48
  97. data/app/views/decidim/initiatives/admin/exports/_dropdown.html.erb +8 -7
  98. data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +111 -95
  99. data/app/views/decidim/initiatives/admin/initiatives/_initiative_attachments.erb +7 -7
  100. data/app/views/decidim/initiatives/admin/initiatives/_signatures.html.erb +87 -0
  101. data/app/views/decidim/initiatives/admin/initiatives/edit.html.erb +72 -60
  102. data/app/views/decidim/initiatives/admin/initiatives/export_pdf_signatures.html.erb +8 -0
  103. data/app/views/decidim/initiatives/admin/initiatives/export_pdf_signatures.pdf.erb +5 -78
  104. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +76 -75
  105. data/app/views/decidim/initiatives/admin/initiatives_settings/_form.html.erb +7 -8
  106. data/app/views/decidim/initiatives/admin/initiatives_settings/edit.html.erb +17 -5
  107. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/_form.html.erb +11 -6
  108. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/edit.html.erb +16 -22
  109. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/new.html.erb +17 -15
  110. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +93 -76
  111. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +35 -33
  112. data/app/views/decidim/initiatives/admin/initiatives_types/edit.html.erb +16 -12
  113. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +39 -48
  114. data/app/views/decidim/initiatives/admin/initiatives_types/new.html.erb +16 -9
  115. data/app/views/decidim/initiatives/committee_requests/new.html.erb +21 -19
  116. data/app/views/decidim/initiatives/create_initiative/_share_committee_link.html.erb +15 -20
  117. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +62 -100
  118. data/app/views/decidim/initiatives/create_initiative/finish.html.erb +24 -28
  119. data/app/views/decidim/initiatives/create_initiative/promotal_committee.html.erb +15 -17
  120. data/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb +32 -46
  121. data/app/views/decidim/initiatives/initiative_signatures/_wizard_steps.html.erb +15 -19
  122. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +25 -36
  123. data/app/views/decidim/initiatives/initiative_signatures/finish.html.erb +5 -16
  124. data/app/views/decidim/initiatives/initiative_signatures/sms_code.html.erb +8 -19
  125. data/app/views/decidim/initiatives/initiative_signatures/sms_phone_number.html.erb +8 -20
  126. data/app/views/decidim/initiatives/initiatives/_committee_members.html.erb +48 -66
  127. data/app/views/decidim/initiatives/initiatives/_form.html.erb +49 -95
  128. data/app/views/decidim/initiatives/initiatives/_initiative_badge.html.erb +3 -5
  129. data/app/views/decidim/initiatives/initiatives/_initiative_hero.html.erb +13 -0
  130. data/app/views/decidim/initiatives/initiatives/_initiatives.html.erb +6 -15
  131. data/app/views/decidim/initiatives/initiatives/_interactions.html.erb +1 -1
  132. data/app/views/decidim/initiatives/initiatives/_new_initiative_button.html.erb +28 -0
  133. data/app/views/decidim/initiatives/initiatives/_progress_bar.html.erb +2 -6
  134. data/app/views/decidim/initiatives/initiatives/_result.html.erb +15 -21
  135. data/app/views/decidim/initiatives/initiatives/_send_to_technical_validation.html.erb +3 -3
  136. data/app/views/decidim/initiatives/initiatives/_tags_type.html.erb +1 -0
  137. data/app/views/decidim/initiatives/initiatives/_vote_button.html.erb +9 -9
  138. data/app/views/decidim/initiatives/initiatives/_vote_cabin.html.erb +7 -7
  139. data/app/views/decidim/initiatives/initiatives/edit.html.erb +63 -68
  140. data/app/views/decidim/initiatives/initiatives/index.html.erb +17 -18
  141. data/app/views/decidim/initiatives/initiatives/index.js.erb +0 -5
  142. data/app/views/decidim/initiatives/initiatives/print.html.erb +123 -120
  143. data/app/views/decidim/initiatives/initiatives/show.html.erb +188 -70
  144. data/app/views/decidim/initiatives/initiatives_mailer/notify_creation.html.erb +2 -2
  145. data/app/views/decidim/initiatives/initiatives_type_scopes/search.html.erb +2 -1
  146. data/app/views/decidim/initiatives/versions/show.html.erb +14 -5
  147. data/app/views/layouts/decidim/_initiative_creation_header.html.erb +17 -28
  148. data/app/views/layouts/decidim/_initiative_header.html.erb +3 -23
  149. data/app/views/layouts/decidim/_initiative_header_steps.html.erb +4 -12
  150. data/app/views/layouts/decidim/_initiative_signature_creation_header.html.erb +5 -26
  151. data/app/views/layouts/decidim/admin/initiative.html.erb +12 -13
  152. data/app/views/layouts/decidim/admin/initiatives.html.erb +40 -11
  153. data/app/views/layouts/decidim/initiative.html.erb +16 -11
  154. data/app/views/layouts/decidim/initiative_creation.html.erb +7 -18
  155. data/app/views/layouts/decidim/initiative_head.html.erb +15 -0
  156. data/app/views/layouts/decidim/initiative_signature_creation.html.erb +3 -11
  157. data/config/assets.rb +0 -1
  158. data/config/initializers/wicked_pdf.rb +1 -1
  159. data/config/locales/ar.yml +1 -93
  160. data/config/locales/ca.yml +65 -104
  161. data/config/locales/cs.yml +70 -109
  162. data/config/locales/de.yml +72 -111
  163. data/config/locales/el.yml +1 -98
  164. data/config/locales/en.yml +69 -108
  165. data/config/locales/es-MX.yml +65 -104
  166. data/config/locales/es-PY.yml +65 -104
  167. data/config/locales/es.yml +65 -104
  168. data/config/locales/eu.yml +66 -105
  169. data/config/locales/fi-plain.yml +67 -106
  170. data/config/locales/fi.yml +67 -106
  171. data/config/locales/fr-CA.yml +69 -108
  172. data/config/locales/fr.yml +67 -106
  173. data/config/locales/ga-IE.yml +0 -35
  174. data/config/locales/gl.yml +1 -89
  175. data/config/locales/hu.yml +25 -105
  176. data/config/locales/id-ID.yml +1 -89
  177. data/config/locales/is-IS.yml +1 -60
  178. data/config/locales/it.yml +6 -111
  179. data/config/locales/ja.yml +62 -106
  180. data/config/locales/lb.yml +6 -86
  181. data/config/locales/lt.yml +52 -103
  182. data/config/locales/lv.yml +1 -99
  183. data/config/locales/nl.yml +6 -104
  184. data/config/locales/no.yml +6 -114
  185. data/config/locales/pl.yml +6 -119
  186. data/config/locales/pt-BR.yml +21 -119
  187. data/config/locales/pt.yml +6 -111
  188. data/config/locales/ro-RO.yml +13 -108
  189. data/config/locales/ru.yml +1 -68
  190. data/config/locales/sk.yml +1 -85
  191. data/config/locales/sl.yml +3 -5
  192. data/config/locales/sv.yml +16 -107
  193. data/config/locales/tr-TR.yml +9 -110
  194. data/config/locales/uk.yml +1 -68
  195. data/config/locales/zh-CN.yml +6 -102
  196. data/config/locales/zh-TW.yml +31 -95
  197. data/db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb +1 -1
  198. data/db/migrate/20171017095143_update_initiative_scoped_type.rb +1 -1
  199. data/db/migrate/20191002082220_move_signature_type_to_initative_type.rb +1 -1
  200. data/lib/decidim/api/initiative_committee_member_type.rb +2 -2
  201. data/lib/decidim/initiatives/admin_engine.rb +13 -93
  202. data/lib/decidim/initiatives/content_blocks/registry_manager.rb +22 -0
  203. data/lib/decidim/initiatives/engine.rb +45 -23
  204. data/lib/decidim/initiatives/menu.rb +150 -0
  205. data/lib/decidim/initiatives/participatory_space.rb +6 -91
  206. data/lib/decidim/initiatives/query_extensions.rb +5 -5
  207. data/lib/decidim/initiatives/seeds.rb +95 -0
  208. data/lib/decidim/initiatives/test/factories.rb +25 -7
  209. data/lib/decidim/initiatives/version.rb +1 -1
  210. data/lib/decidim/initiatives.rb +1 -1
  211. data/lib/tasks/decidim_initiatives.rake +2 -2
  212. data/lib/tasks/initiatives/upgrade/decidim_initiatives_upgrade_tasks.rake +1 -1
  213. metadata +47 -76
  214. data/app/cells/decidim/initiatives/content_blocks/highlighted_initiatives/show.erb +0 -28
  215. data/app/cells/decidim/initiatives/initiative_m/author.erb +0 -10
  216. data/app/cells/decidim/initiatives/initiative_m/footer.erb +0 -28
  217. data/app/cells/decidim/initiatives/initiative_m/tags.erb +0 -9
  218. data/app/cells/decidim/initiatives/initiative_m_cell.rb +0 -77
  219. data/app/controllers/decidim/initiatives/widgets_controller.rb +0 -30
  220. data/app/packs/stylesheets/decidim/initiatives/admin.scss +0 -33
  221. data/app/packs/stylesheets/decidim/initiatives/initiatives.scss +0 -64
  222. data/app/packs/stylesheets/decidim/initiatives/popularity_item.scss +0 -76
  223. data/app/packs/stylesheets/decidim/initiatives/statistics.scss +0 -15
  224. data/app/views/decidim/initiatives/create_initiative/_finish_help.html.erb +0 -2
  225. data/app/views/decidim/initiatives/create_initiative/previous_form.html.erb +0 -40
  226. data/app/views/decidim/initiatives/create_initiative/show_similar_initiatives.html.erb +0 -23
  227. data/app/views/decidim/initiatives/initiatives/_author.html.erb +0 -35
  228. data/app/views/decidim/initiatives/initiatives/_count.html.erb +0 -1
  229. data/app/views/decidim/initiatives/initiatives/_filters.html.erb +0 -33
  230. data/app/views/decidim/initiatives/initiatives/_filters_small_view.html.erb +0 -18
  231. data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +0 -44
  232. data/app/views/decidim/initiatives/initiatives/_tags.html.erb +0 -7
  233. data/app/views/decidim/initiatives/versions/index.html.erb +0 -8
  234. data/config/environment.rb +0 -3
  235. data/db/seeds/city.jpeg +0 -0
  236. data/db/seeds/city2.jpeg +0 -0
  237. data/lib/decidim/initiatives/initiatives_filter_form_builder.rb +0 -56
  238. data/lib/gem_overrides/origami/date.rb +0 -47
@@ -2,13 +2,10 @@
2
2
 
3
3
  module Decidim
4
4
  module Initiatives
5
- require "wicked"
6
-
7
5
  # Controller in charge of managing the create initiative wizard.
8
6
  class CreateInitiativeController < Decidim::Initiatives::ApplicationController
9
7
  layout "layouts/decidim/initiative_creation"
10
8
 
11
- include Wicked::Wizard
12
9
  include Decidim::FormFactory
13
10
  include InitiativeHelper
14
11
  include TypeSelectorOptions
@@ -18,7 +15,6 @@ module Decidim
18
15
  helper InitiativeHelper
19
16
  helper SignatureTypeOptionsHelper
20
17
 
21
- helper_method :similar_initiatives
22
18
  helper_method :scopes
23
19
  helper_method :areas
24
20
  helper_method :current_initiative
@@ -26,136 +22,95 @@ module Decidim
26
22
  helper_method :promotal_committee_required?
27
23
 
28
24
  before_action :authenticate_user!
25
+ before_action :ensure_type_exists,
26
+ only: [:store_initiative_type, :fill_data, :store_data, :promotal_committee, :finish]
27
+ before_action :ensure_user_can_create_initiative,
28
+ only: [:fill_data, :store_data, :promotal_committee, :finish]
29
+ before_action :ensure_initiative_exists, only: [:promotal_committee, :finish]
30
+
31
+ def select_initiative_type
32
+ @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).from_params(params)
29
33
 
30
- steps :select_initiative_type,
31
- :previous_form,
32
- :show_similar_initiatives,
33
- :fill_data,
34
- :promotal_committee,
35
- :finish
34
+ redirect_to fill_data_create_initiative_index_path if single_initiative_type?
35
+ end
36
36
 
37
- before_action :ensure_type_exists, only: :show
37
+ def store_initiative_type
38
+ @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).from_params(params)
38
39
 
39
- def show
40
- enforce_permission_to :create, :initiative
41
- send("#{step}_step", initiative: session_initiative)
40
+ if @form.valid?
41
+ session[:type_id] = @form.type_id
42
+ redirect_to fill_data_create_initiative_index_path
43
+ else
44
+ render :select_initiative_type
45
+ end
42
46
  end
43
47
 
44
- def update
45
- enforce_permission_to :create, :initiative
46
- send("#{step}_step", params)
48
+ def fill_data
49
+ @form = if session[:initiative_id].present?
50
+ form(Decidim::Initiatives::InitiativeForm).from_model(current_initiative, { initiative_type: })
51
+ else
52
+ extras = { type_id: initiative_type_id, signature_type: initiative_type.signature_type }
53
+ form(Decidim::Initiatives::InitiativeForm).from_params(params.merge(extras), { initiative_type: })
54
+ end
47
55
  end
48
56
 
49
- private
57
+ def store_data
58
+ @form = form(Decidim::Initiatives::InitiativeForm).from_params(params, { initiative_type: })
50
59
 
51
- def ensure_type_exists
52
- destination_step = single_initiative_type? ? :previous_form : :select_initiative_type
60
+ CreateInitiative.call(@form, current_user) do
61
+ on(:ok) do |initiative|
62
+ session[:initiative_id] = initiative.id
53
63
 
54
- return if step == destination_step
55
- return if initiative_type_id.present? && initiative_type.present?
64
+ path = promotal_committee_required? ? "promotal_committee" : "finish"
56
65
 
57
- redirect_to wizard_path(destination_step)
58
- end
59
-
60
- def select_initiative_type_step(_parameters)
61
- @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).instance
62
- session[:initiative] = {}
66
+ redirect_to send("#{path}_create_initiative_index_path".to_sym)
67
+ end
63
68
 
64
- if single_initiative_type?
65
- redirect_to next_wizard_path
66
- return
69
+ on(:invalid) do
70
+ render :fill_data
71
+ end
67
72
  end
68
-
69
- @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).instance
70
- render_wizard unless performed?
71
73
  end
72
74
 
73
- def previous_form_step(parameters)
74
- @form = build_form(Decidim::Initiatives::PreviousForm, parameters)
75
- render_wizard
75
+ def promotal_committee
76
+ redirect_to finish_create_initiative_index_path unless promotal_committee_required?
76
77
  end
77
78
 
78
- def show_similar_initiatives_step(parameters)
79
- @form = build_form(Decidim::Initiatives::PreviousForm, parameters)
80
- unless @form.valid?
81
- redirect_to previous_wizard_path(validate_form: true)
82
- return
83
- end
84
-
85
- if similar_initiatives.empty?
86
- @form = build_form(Decidim::Initiatives::InitiativeForm, parameters)
87
- redirect_to wizard_path(:fill_data)
88
- end
89
-
90
- render_wizard unless performed?
79
+ def finish
80
+ current_initiative.presence
81
+ session[:type_id] = nil
82
+ session[:initiative_id] = nil
91
83
  end
92
84
 
93
- def fill_data_step(parameters)
94
- @form = build_form(Decidim::Initiatives::InitiativeForm, parameters)
95
- @form.attachment = form(AttachmentForm).from_params({})
85
+ private
96
86
 
97
- render_wizard
87
+ def ensure_user_can_create_initiative
88
+ enforce_permission_to :create, :initiative, { initiative_type: }
98
89
  end
99
90
 
100
- def promotal_committee_step(parameters)
101
- @form = build_form(Decidim::Initiatives::InitiativeForm, parameters)
102
- unless @form.valid?
103
- redirect_to previous_wizard_path(validate_form: true)
104
- return
105
- end
106
-
107
- skip_step unless promotal_committee_required?
108
-
109
- if session_initiative.has_key?(:id)
110
- render_wizard
111
- return
112
- end
113
-
114
- CreateInitiative.call(@form, current_user) do
115
- on(:ok) do |initiative|
116
- session[:initiative][:id] = initiative.id
117
- if current_initiative.created_by_individual?
118
- render_wizard
119
- else
120
- redirect_to wizard_path(:finish)
121
- end
122
- end
123
-
124
- on(:invalid) do |initiative|
125
- logger.fatal "Failed creating initiative: #{initiative.errors.full_messages.join(", ")}" if initiative
126
- redirect_to previous_wizard_path(validate_form: true)
127
- end
128
- end
91
+ def initiative_type_id
92
+ @initiative_type_id ||= fetch_initiative_type_id
129
93
  end
130
94
 
131
- def finish_step(_parameters)
132
- render_wizard
133
- end
95
+ def fetch_initiative_type_id
96
+ return current_organization_initiatives_type.first.id if single_initiative_type?
97
+ return params.dig(:initiative, :type_id) if params.dig(:initiative, :type_id).present?
98
+ return current_initiative&.type&.id if session[:initiative_id].present?
134
99
 
135
- def similar_initiatives
136
- @similar_initiatives ||= Decidim::Initiatives::SimilarInitiatives
137
- .for(current_organization, @form)
138
- .all
100
+ session[:type_id]
139
101
  end
140
102
 
141
- def build_form(klass, parameters)
142
- @form = if single_initiative_type?
143
- form(klass).from_params(parameters.except(:id).merge(type_id: current_organization_initiatives_type.first.id), extra_context)
144
- else
145
- form(klass).from_params(parameters.except(:id), extra_context)
146
- end
147
-
148
- attributes = @form.attributes_with_values
149
- session[:initiative] = session_initiative.merge(attributes)
150
- @form.valid? if params[:validate_form]
151
-
152
- @form
103
+ def ensure_initiative_exists
104
+ redirect_to fill_data_create_initiative_index_path if session[:initiative_id].blank?
153
105
  end
154
106
 
155
- def extra_context
156
- return {} unless initiative_type_id
107
+ def ensure_type_exists
108
+ destination_step = single_initiative_type? ? "fill_data" : "select_initiative_type"
109
+
110
+ return if action_name == destination_step
111
+ return if initiative_type_id.present? && initiative_type.present?
157
112
 
158
- { initiative_type: initiative_type }
113
+ redirect_to send("#{destination_step}_create_initiative_index_path".to_sym)
159
114
  end
160
115
 
161
116
  def scopes
@@ -163,23 +118,15 @@ module Decidim
163
118
  end
164
119
 
165
120
  def current_initiative
166
- Initiative.where(organization: current_organization).find_by(id: session_initiative[:id]) if session_initiative.has_key?(:id)
121
+ @current_initiative ||= Initiative.where(organization: current_organization).find_by(id: session[:initiative_id] || nil)
167
122
  end
168
123
 
169
124
  def initiative_type
170
125
  @initiative_type ||= InitiativesType.where(organization: current_organization).find_by(id: initiative_type_id)
171
126
  end
172
127
 
173
- def initiative_type_id
174
- session_initiative[:type_id] || @form&.type_id
175
- end
176
-
177
- def session_initiative
178
- session[:initiative] ||= {}
179
- session[:initiative].with_indifferent_access
180
- end
181
-
182
128
  def promotal_committee_required?
129
+ return false if initiative_type.blank?
183
130
  return false unless initiative_type.promoting_committee_enabled?
184
131
 
185
132
  minimum_committee_members = initiative_type.minimum_committee_members ||
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # i18n-tasks-use t('layouts.decidim.initiative_signature_creation_header.fill_personal_data')
4
+ # i18n-tasks-use t('layouts.decidim.initiative_signature_creation_header.finish')
5
+ # i18n-tasks-use t('layouts.decidim.initiative_signature_creation_header.sms_code')
6
+ # i18n-tasks-use t('layouts.decidim.initiative_signature_creation_header.sms_phone_number')
7
+ # i18n-tasks-use t('layouts.decidim.initiative_signature_creation_header.finish')
3
8
  module Decidim
4
9
  module Initiatives
5
- require "wicked"
6
-
7
10
  class InitiativeSignaturesController < Decidim::Initiatives::ApplicationController
8
11
  layout "layouts/decidim/initiative_signature_creation"
9
-
10
- include Wicked::Wizard
11
12
  include Decidim::Initiatives::NeedsInitiative
12
13
  include Decidim::FormFactory
13
14
 
14
15
  prepend_before_action :set_wizard_steps
15
16
  before_action :authenticate_user!
17
+ before_action :authorize_wizard_step, only: [
18
+ :fill_personal_data,
19
+ :store_personal_data,
20
+ :sms_phone_number,
21
+ :store_sms_phone_number,
22
+ :sms_code,
23
+ :store_sms_code,
24
+ :finish
25
+ ]
16
26
 
17
27
  helper InitiativeHelper
18
28
 
19
- helper_method :initiative_type, :extra_data_legal_information
20
-
21
- # GET /initiatives/:initiative_id/initiative_signatures/:step
22
- def show
23
- enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, signature_has_steps: signature_has_steps?
24
- send("#{step}_step", initiative_vote_form: session[:initiative_vote_form])
25
- end
29
+ helper_method :initiative_type, :extra_data_legal_information, :sms_step?, :fill_personal_data_step?
26
30
 
27
- # PUT /initiatives/:initiative_id/initiative_signatures/:step
28
- def update
29
- enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, signature_has_steps: signature_has_steps?
30
- send("#{step}_step", params)
31
+ def index
32
+ redirect_to send(fill_personal_data_step? ? :fill_personal_data_path : :sms_phone_number_path)
31
33
  end
32
34
 
33
35
  # POST /initiatives/:initiative_id/initiative_signatures
@@ -52,76 +54,86 @@ module Decidim
52
54
  end
53
55
  end
54
56
 
55
- private
57
+ def fill_personal_data
58
+ redirect_to(sms_phone_number_path) && return unless fill_personal_data_step?
56
59
 
57
- def fill_personal_data_step(_unused)
58
60
  @form = form(Decidim::Initiatives::VoteForm)
59
61
  .from_params(
60
62
  initiative: current_initiative,
61
63
  signer: current_user
62
64
  )
63
-
64
- session[:initiative_vote_form] = {}
65
- skip_step unless initiative_type.collect_user_extra_fields
66
- render_wizard
67
65
  end
68
66
 
69
- def sms_phone_number_step(parameters)
70
- if parameters.has_key?(:initiatives_vote) || !fill_personal_data_step?
71
- build_vote_form(parameters)
72
- else
73
- check_session_personal_data
74
- end
75
- clear_session_sms_code
67
+ def store_personal_data
68
+ redirect_to(sms_phone_number_path) && return unless fill_personal_data_step?
69
+
70
+ build_vote_form(params)
76
71
 
77
72
  if @vote_form.invalid?
78
73
  flash[:alert] = I18n.t("personal_data.invalid", scope: "decidim.initiatives.initiative_votes")
79
- jump_to(previous_step)
74
+ @form = @vote_form
75
+
76
+ render :fill_personal_data
77
+ else
78
+ redirect_to sms_phone_number_path
80
79
  end
80
+ end
81
+
82
+ def sms_phone_number
83
+ redirect_to(finish_path) && return unless sms_step?
81
84
 
82
85
  @form = Decidim::Verifications::Sms::MobilePhoneForm.new
83
- render_wizard
84
86
  end
85
87
 
86
- def sms_code_step(parameters)
87
- check_session_personal_data if fill_personal_data_step?
88
- @phone_form = Decidim::Verifications::Sms::MobilePhoneForm.from_params(parameters.merge(user: current_user))
89
- @form = Decidim::Verifications::Sms::ConfirmationForm.new
90
- render_wizard && return if session_sms_code.present?
88
+ def store_sms_phone_number
89
+ redirect_to(finish_path) && return unless sms_step?
91
90
 
92
- ValidateMobilePhone.call(@phone_form, current_user) do
91
+ @form = Decidim::Verifications::Sms::MobilePhoneForm.from_params(params.merge(user: current_user))
92
+
93
+ ValidateMobilePhone.call(@form, current_user) do
93
94
  on(:ok) do |metadata|
94
95
  store_session_sms_code(metadata)
95
- render_wizard
96
+ redirect_to sms_code_path
96
97
  end
97
98
 
98
99
  on(:invalid) do
99
100
  flash[:alert] = I18n.t("sms_phone.invalid", scope: "decidim.initiatives.initiative_votes")
100
- redirect_to wizard_path(:sms_phone_number)
101
+ render :sms_phone_number
101
102
  end
102
103
  end
103
104
  end
104
105
 
105
- def finish_step(parameters)
106
- if parameters.has_key?(:initiatives_vote) || !fill_personal_data_step?
107
- build_vote_form(parameters)
108
- else
109
- check_session_personal_data
110
- end
106
+ def sms_code
107
+ redirect_to(finish_path) && return unless sms_step?
108
+
109
+ redirect_to sms_phone_number_path && return if session_sms_code.blank?
111
110
 
112
- if sms_step?
113
- @confirmation_code_form = Decidim::Verifications::Sms::ConfirmationForm.from_params(parameters)
111
+ @form = Decidim::Verifications::Sms::ConfirmationForm.new
112
+ end
113
+
114
+ def store_sms_code
115
+ redirect_to(finish_path) && return unless sms_step?
114
116
 
115
- ValidateSmsCode.call(@confirmation_code_form, session_sms_code) do
116
- on(:ok) { clear_session_sms_code }
117
+ @form = Decidim::Verifications::Sms::ConfirmationForm.from_params(params)
118
+ ValidateSmsCode.call(@form, session_sms_code) do
119
+ on(:ok) do
120
+ clear_session_sms_code
121
+ redirect_to finish_path
122
+ end
117
123
 
118
- on(:invalid) do
119
- flash[:alert] = I18n.t("sms_code.invalid", scope: "decidim.initiatives.initiative_votes")
120
- jump_to :sms_code
121
- render_wizard && return
122
- end
124
+ on(:invalid) do
125
+ flash[:alert] = I18n.t("sms_code.invalid", scope: "decidim.initiatives.initiative_votes")
126
+ render :sms_code
123
127
  end
124
128
  end
129
+ end
130
+
131
+ def finish
132
+ if params.has_key?(:initiatives_vote) || !fill_personal_data_step?
133
+ build_vote_form(params)
134
+ else
135
+ check_session_personal_data
136
+ end
125
137
 
126
138
  VoteInitiative.call(@vote_form) do
127
139
  on(:ok) do
@@ -131,11 +143,29 @@ module Decidim
131
143
  on(:invalid) do |vote|
132
144
  logger.fatal "Failed creating signature: #{vote.errors.full_messages.join(", ")}" if vote
133
145
  flash[:alert] = I18n.t("create.invalid", scope: "decidim.initiatives.initiative_votes")
134
- jump_to previous_step
146
+ send(sms_step? ? :sms_code_path : :fill_personal_data_path)
135
147
  end
136
148
  end
149
+ end
150
+
151
+ private
152
+
153
+ attr_reader :wizard_steps
154
+
155
+ def fill_personal_data_path
156
+ fill_personal_data_initiative_signatures_path(current_initiative)
157
+ end
137
158
 
138
- render_wizard
159
+ def sms_code_path
160
+ sms_code_initiative_signatures_path(current_initiative)
161
+ end
162
+
163
+ def finish_path
164
+ finish_initiative_signatures_path(current_initiative)
165
+ end
166
+
167
+ def sms_phone_number_path
168
+ sms_phone_number_initiative_signatures_path(current_initiative)
139
169
  end
140
170
 
141
171
  def build_vote_form(parameters)
@@ -148,53 +178,55 @@ module Decidim
148
178
  session[:initiative_vote_form] = session[:initiative_vote_form].merge(@vote_form.attributes_with_values.except(:initiative, :signer))
149
179
  end
150
180
 
151
- def session_vote_form
152
- attributes = session[:initiative_vote_form].merge(initiative: current_initiative, signer: current_user)
181
+ def initiative_type
182
+ @initiative_type ||= current_initiative&.scoped_type&.type
183
+ end
153
184
 
154
- @vote_form = form(Decidim::Initiatives::VoteForm).from_params(attributes)
185
+ def sms_step?
186
+ current_initiative.validate_sms_code_on_votes?
155
187
  end
156
188
 
157
- def initiative_type
158
- @initiative_type ||= current_initiative&.scoped_type&.type
189
+ def fill_personal_data_step?
190
+ initiative_type.collect_user_extra_fields?
191
+ end
192
+
193
+ def authorize_wizard_step
194
+ enforce_permission_to :sign_initiative, :initiative, initiative: current_initiative, signature_has_steps: signature_has_steps?
195
+ end
196
+
197
+ def set_wizard_steps
198
+ @wizard_steps = [:finish]
199
+ @wizard_steps.unshift(:sms_phone_number, :sms_code) if sms_step?
200
+ @wizard_steps.unshift(:fill_personal_data) if fill_personal_data_step?
159
201
  end
160
202
 
161
203
  def extra_data_legal_information
162
204
  @extra_data_legal_information ||= initiative_type.extra_fields_legal_information
163
205
  end
164
206
 
165
- def check_session_personal_data
166
- return if session[:initiative_vote_form].present? && session_vote_form&.valid?
207
+ def session_vote_form
208
+ attributes = session[:initiative_vote_form].merge(initiative: current_initiative, signer: current_user)
167
209
 
168
- flash[:alert] = I18n.t("create.error", scope: "decidim.initiatives.initiative_votes")
169
- jump_to(:fill_personal_data)
210
+ @vote_form = form(Decidim::Initiatives::VoteForm).from_params(attributes)
170
211
  end
171
212
 
172
- def store_session_sms_code(metadata)
173
- session[:initiative_sms_code] = metadata
174
- end
213
+ def check_session_personal_data
214
+ return if session[:initiative_vote_form].present? && session_vote_form&.valid?
175
215
 
176
- def session_sms_code
177
- session[:initiative_sms_code]
216
+ flash[:alert] = I18n.t("create.error", scope: "decidim.initiatives.initiative_votes")
217
+ redirect_to fill_personal_data_path
178
218
  end
179
219
 
180
220
  def clear_session_sms_code
181
221
  session[:initiative_sms_code] = {}
182
222
  end
183
223
 
184
- def sms_step?
185
- current_initiative.validate_sms_code_on_votes?
186
- end
187
-
188
- def fill_personal_data_step?
189
- initiative_type.collect_user_extra_fields?
224
+ def store_session_sms_code(metadata)
225
+ session[:initiative_sms_code] = metadata
190
226
  end
191
227
 
192
- def set_wizard_steps
193
- initial_wizard_steps = [:finish]
194
- initial_wizard_steps.unshift(:sms_phone_number, :sms_code) if sms_step?
195
- initial_wizard_steps.unshift(:fill_personal_data) if fill_personal_data_step?
196
-
197
- self.steps = initial_wizard_steps
228
+ def session_sms_code
229
+ session[:initiative_sms_code]
198
230
  end
199
231
  end
200
232
  end
@@ -1,5 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.accepted')
4
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.created')
5
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.discarded')
6
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.published')
7
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.rejected')
8
+ # i18n-tasks-use t('decidim.initiatives.show.badge_name.validating')
9
+ #
3
10
  module Decidim
4
11
  module Initiatives
5
12
  # Exposes the initiative type text search so users can choose a type writing its name.
@@ -5,9 +5,7 @@ module Decidim
5
5
  # This controller contains the logic regarding participants initiatives
6
6
  class InitiativesController < Decidim::Initiatives::ApplicationController
7
7
  include ParticipatorySpaceContext
8
- participatory_space_layout only: [:show]
9
8
 
10
- helper Decidim::WidgetUrlsHelper
11
9
  helper Decidim::AttachmentsHelper
12
10
  helper Decidim::FiltersHelper
13
11
  helper Decidim::OrdersHelper
@@ -28,9 +26,12 @@ module Decidim
28
26
  include TypeSelectorOptions
29
27
  include NeedsInitiative
30
28
  include SingleInitiativeType
29
+ include Decidim::IconHelper
31
30
 
32
- helper_method :collection, :initiatives, :filter, :stats
33
- helper_method :initiative_type
31
+ helper_method :collection, :initiatives, :filter, :stats, :tabs, :panels
32
+ helper_method :initiative_type, :available_initiative_types
33
+
34
+ before_action :authorize_participatory_space, only: [:show]
34
35
 
35
36
  # GET /initiatives
36
37
  def index
@@ -51,6 +52,8 @@ module Decidim
51
52
  # GET /initiatives/:id
52
53
  def show
53
54
  enforce_permission_to :read, :initiative, initiative: current_initiative
55
+
56
+ render layout: "decidim/initiative_head"
54
57
  end
55
58
 
56
59
  # GET /initiatives/:id/send_to_technical_validation
@@ -79,8 +82,6 @@ module Decidim
79
82
  initiative: current_initiative
80
83
  )
81
84
  @form.attachment = form_attachment_model
82
-
83
- render layout: "decidim/initiative"
84
85
  end
85
86
 
86
87
  # PUT /initiatives/:id
@@ -114,6 +115,8 @@ module Decidim
114
115
  alias current_initiative current_participatory_space
115
116
 
116
117
  def current_participatory_space
118
+ return unless params["slug"]
119
+
117
120
  @current_participatory_space ||= Initiative.find(id_from_slug(params[:slug]))
118
121
  end
119
122
 
@@ -140,27 +143,44 @@ module Decidim
140
143
  {
141
144
  search_text_cont: "",
142
145
  with_any_state: %w(open),
143
- with_any_type: default_filter_type_params,
146
+ with_any_type: nil,
144
147
  author: "any",
145
- with_any_scope: default_filter_scope_params,
146
- with_any_area: default_filter_area_params
148
+ with_any_scope: nil,
149
+ with_any_area: nil
147
150
  }
148
151
  end
149
152
 
150
- def default_filter_type_params
151
- %w(all) + Decidim::InitiativesType.where(organization: current_organization).pluck(:id).map(&:to_s)
153
+ def stats
154
+ @stats ||= InitiativeStatsPresenter.new(initiative: current_initiative)
152
155
  end
153
156
 
154
- def default_filter_scope_params
155
- %w(all global) + current_organization.scopes.pluck(:id).map(&:to_s)
157
+ def tabs
158
+ @tabs ||= items.map { |item| item.slice(:id, :text, :icon) }
156
159
  end
157
160
 
158
- def default_filter_area_params
159
- %w(all) + current_organization.areas.pluck(:id).map(&:to_s)
161
+ def panels
162
+ @panels ||= items.map { |item| item.slice(:id, :method, :args) }
160
163
  end
161
164
 
162
- def stats
163
- @stats ||= InitiativeStatsPresenter.new(initiative: current_initiative)
165
+ def items
166
+ @items ||= [
167
+ {
168
+ enabled: @current_initiative.photos.present?,
169
+ id: "images",
170
+ text: t("decidim.application.photos.photos"),
171
+ icon: resource_type_icon_key("images"),
172
+ method: :cell,
173
+ args: ["decidim/images_panel", @current_initiative]
174
+ },
175
+ {
176
+ enabled: @current_initiative.documents.present?,
177
+ id: "documents",
178
+ text: t("decidim.application.documents.documents"),
179
+ icon: resource_type_icon_key("documents"),
180
+ method: :cell,
181
+ args: ["decidim/documents_panel", @current_initiative]
182
+ }
183
+ ].select { |item| item[:enabled] }
164
184
  end
165
185
  end
166
186
  end
@@ -6,7 +6,6 @@ module Decidim
6
6
  # has been updated through time.
7
7
  class VersionsController < Decidim::Initiatives::ApplicationController
8
8
  include ParticipatorySpaceContext
9
- participatory_space_layout
10
9
  helper InitiativeHelper
11
10
 
12
11
  include NeedsInitiative
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Initiatives
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Initiatives