decidim-initiatives 0.30.2 → 0.31.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -9
  3. data/app/cells/decidim/initiatives/content_blocks/highlighted_initiatives_settings_form/show.erb +7 -2
  4. data/app/cells/decidim/initiatives/initiative_g_cell.rb +5 -1
  5. data/app/commands/decidim/initiatives/admin/publish_initiative.rb +1 -5
  6. data/app/commands/decidim/initiatives/admin/update_initiative.rb +1 -2
  7. data/app/commands/decidim/initiatives/create_initiative.rb +0 -1
  8. data/app/commands/decidim/initiatives/update_initiative.rb +1 -3
  9. data/app/commands/decidim/initiatives/vote_initiative.rb +1 -11
  10. data/app/controllers/concerns/decidim/initiatives/has_signature_workflow.rb +36 -0
  11. data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +1 -12
  12. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +2 -2
  13. data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +1 -1
  14. data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +2 -2
  15. data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +2 -2
  16. data/app/controllers/decidim/initiatives/committee_requests_controller.rb +10 -2
  17. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +84 -18
  18. data/app/controllers/decidim/initiatives/initiative_signatures_controller.rb +133 -42
  19. data/app/controllers/decidim/initiatives/initiative_votes_controller.rb +3 -2
  20. data/app/controllers/decidim/initiatives/initiatives_controller.rb +21 -2
  21. data/app/forms/decidim/initiatives/admin/initiative_form.rb +0 -1
  22. data/app/forms/decidim/initiatives/initiative_form.rb +0 -3
  23. data/app/helpers/decidim/initiatives/application_helper.rb +2 -0
  24. data/app/helpers/decidim/initiatives/initiatives_helper.rb +0 -1
  25. data/app/models/decidim/initiative.rb +7 -31
  26. data/app/models/decidim/initiatives_committee_member.rb +1 -1
  27. data/app/models/decidim/initiatives_type.rb +5 -2
  28. data/app/models/decidim/initiatives_vote.rb +2 -2
  29. data/app/packs/entrypoints/decidim_initiatives.js +1 -1
  30. data/app/packs/entrypoints/decidim_initiatives_admin.scss +1 -1
  31. data/app/packs/src/decidim/initiatives/admin/initiatives_types.js +2 -11
  32. data/app/packs/src/decidim/initiatives/admin/invite_users.js +1 -1
  33. data/app/packs/src/decidim/initiatives/application.js +1 -1
  34. data/app/packs/src/decidim/initiatives/check_code.js +114 -0
  35. data/app/packs/src/decidim/initiatives/initiative_creation_wizard.js +16 -0
  36. data/app/packs/src/decidim/initiatives/scoped_type.js +1 -1
  37. data/app/packs/stylesheets/initiatives.scss +16 -2
  38. data/app/permissions/decidim/initiatives/admin/permissions.rb +1 -4
  39. data/app/permissions/decidim/initiatives/permissions.rb +26 -16
  40. data/app/presenters/decidim/initiative_presenter.rb +12 -6
  41. data/app/presenters/decidim/initiatives/admin_log/initiative_presenter.rb +1 -2
  42. data/app/queries/decidim/initiatives/initiatives_stats_followers_count.rb +14 -0
  43. data/app/queries/decidim/initiatives/initiatives_stats_participants_count.rb +14 -0
  44. data/app/serializers/decidim/initiatives/open_data_initiative_serializer.rb +0 -1
  45. data/app/services/decidim/initiatives/data_encryptor.rb +1 -1
  46. data/app/services/decidim/initiatives/legacy_signature_handler.rb +25 -0
  47. data/app/services/decidim/initiatives/progress_notifier.rb +1 -7
  48. data/app/services/decidim/initiatives/signature_handler.rb +248 -0
  49. data/app/services/decidim/initiatives/status_change_notifier.rb +1 -7
  50. data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +29 -11
  51. data/app/views/decidim/initiatives/admin/exports/_dropdown.html.erb +17 -20
  52. data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +7 -13
  53. data/app/views/decidim/initiatives/admin/initiatives/_initiative_attachments.erb +2 -2
  54. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +76 -47
  55. data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +13 -21
  56. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +28 -12
  57. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +33 -15
  58. data/app/views/decidim/initiatives/create_initiative/_committee_member.html.erb +27 -0
  59. data/app/views/decidim/initiatives/create_initiative/_return_to_initiatives_button.html.erb +3 -0
  60. data/app/views/decidim/initiatives/create_initiative/_send_to_technical_validation_button.html.erb +10 -0
  61. data/app/views/decidim/initiatives/create_initiative/_share_committee_link.html.erb +5 -1
  62. data/app/views/decidim/initiatives/create_initiative/fill_data.html.erb +7 -11
  63. data/app/views/decidim/initiatives/create_initiative/finish.html.erb +16 -13
  64. data/app/views/decidim/initiatives/create_initiative/promotal_committee.html.erb +33 -6
  65. data/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb +40 -26
  66. data/app/views/decidim/initiatives/initiative_signatures/_sms_code_form.html.erb +22 -0
  67. data/app/views/decidim/initiatives/initiative_signatures/_sms_phone_number_form.html.erb +13 -0
  68. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +23 -22
  69. data/app/views/decidim/initiatives/initiative_signatures/finish.html.erb +17 -5
  70. data/app/views/decidim/initiatives/initiative_signatures/sms_code.html.erb +6 -8
  71. data/app/views/decidim/initiatives/initiative_signatures/sms_phone_number.html.erb +3 -8
  72. data/app/views/decidim/initiatives/initiative_signatures/update_buttons_and_counters.js.erb +3 -14
  73. data/app/views/decidim/initiatives/initiative_votes/update_buttons_and_counters.js.erb +3 -14
  74. data/app/views/decidim/initiatives/initiatives/_committee_members.html.erb +1 -1
  75. data/app/views/decidim/initiatives/initiatives/_form.html.erb +1 -3
  76. data/app/views/decidim/initiatives/initiatives/_new_initiative_button.html.erb +10 -3
  77. data/app/views/decidim/initiatives/initiatives/_pending_initiatives.html.erb +5 -0
  78. data/app/views/decidim/initiatives/initiatives/index.html.erb +8 -0
  79. data/app/views/decidim/initiatives/initiatives/show.html.erb +2 -2
  80. data/app/views/layouts/decidim/_initiative_signature_creation_header.html.erb +20 -2
  81. data/app/views/layouts/decidim/admin/_manage_initiatives.html.erb +1 -1
  82. data/app/views/layouts/decidim/initiative_signature_creation.html.erb +3 -1
  83. data/config/assets.rb +2 -2
  84. data/config/locales/ar.yml +0 -45
  85. data/config/locales/bg.yml +0 -54
  86. data/config/locales/ca-IT.yml +99 -51
  87. data/config/locales/ca.yml +99 -51
  88. data/config/locales/cs.yml +93 -54
  89. data/config/locales/de.yml +99 -51
  90. data/config/locales/el.yml +0 -45
  91. data/config/locales/en.yml +99 -51
  92. data/config/locales/es-MX.yml +99 -51
  93. data/config/locales/es-PY.yml +99 -51
  94. data/config/locales/es.yml +99 -51
  95. data/config/locales/eu.yml +99 -51
  96. data/config/locales/fi-plain.yml +99 -51
  97. data/config/locales/fi.yml +99 -51
  98. data/config/locales/fr-CA.yml +44 -51
  99. data/config/locales/fr.yml +44 -51
  100. data/config/locales/ga-IE.yml +0 -17
  101. data/config/locales/gl.yml +0 -41
  102. data/config/locales/hu.yml +0 -54
  103. data/config/locales/id-ID.yml +0 -40
  104. data/config/locales/is-IS.yml +0 -22
  105. data/config/locales/it.yml +0 -53
  106. data/config/locales/ja.yml +98 -49
  107. data/config/locales/lb.yml +0 -50
  108. data/config/locales/lt.yml +0 -56
  109. data/config/locales/lv.yml +0 -46
  110. data/config/locales/nl.yml +0 -47
  111. data/config/locales/no.yml +0 -53
  112. data/config/locales/pl.yml +0 -56
  113. data/config/locales/pt-BR.yml +0 -53
  114. data/config/locales/pt.yml +0 -53
  115. data/config/locales/ro-RO.yml +92 -50
  116. data/config/locales/ru.yml +0 -25
  117. data/config/locales/sk.yml +0 -43
  118. data/config/locales/sl.yml +0 -1
  119. data/config/locales/sv.yml +10 -53
  120. data/config/locales/tr-TR.yml +0 -53
  121. data/config/locales/uk.yml +0 -25
  122. data/config/locales/zh-CN.yml +0 -45
  123. data/config/locales/zh-TW.yml +0 -53
  124. data/db/migrate/20250605104500_remove_hashtag_column_initiatives.rb +7 -0
  125. data/lib/decidim/api/initiative_api_type.rb +3 -0
  126. data/lib/decidim/api/initiative_type.rb +23 -4
  127. data/lib/decidim/exporters/initiative_votes_pdf.rb +1 -1
  128. data/lib/decidim/initiatives/default_signature_authorizer.rb +17 -0
  129. data/lib/decidim/initiatives/engine.rb +17 -14
  130. data/lib/decidim/initiatives/participatory_space.rb +15 -1
  131. data/lib/decidim/initiatives/seeds.rb +1 -2
  132. data/lib/decidim/initiatives/signature_workflow_manifest.rb +176 -0
  133. data/lib/decidim/initiatives/signatures.rb +12 -0
  134. data/lib/decidim/initiatives/test/factories.rb +7 -7
  135. data/lib/decidim/initiatives/test/initiatives_signatures_test_helpers.rb +19 -0
  136. data/lib/decidim/initiatives/validatable_authorizations.rb +83 -0
  137. data/lib/decidim/initiatives/version.rb +1 -1
  138. data/lib/decidim/initiatives.rb +23 -12
  139. metadata +33 -21
  140. data/app/events/decidim/initiatives/endorse_initiative_event.rb +0 -13
  141. data/app/forms/decidim/initiatives/vote_form.rb +0 -208
  142. data/app/packs/src/decidim/initiatives/identity_selector_dialog.js +0 -14
  143. data/app/services/decidim/initiatives/pdf_signature_example.rb +0 -110
  144. data/app/views/decidim/initiatives/initiative_signatures/_wizard_steps.html.erb +0 -15
  145. data/app/views/decidim/initiatives/initiatives/_interactions.html.erb +0 -10
  146. data/app/views/layouts/decidim/_initiative_header.html.erb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cb52fb60378e9b9b8648ede4e9c2e5727e8bee9cc509d5a218c61527ab06961
4
- data.tar.gz: 6836093a060884c9b9a631ade772dffe4fbb156b83df1af48fe90b845914344c
3
+ metadata.gz: 938f0ef2756f0b21f9464216de3219c671e1183611534478f23f9f03893ff81c
4
+ data.tar.gz: 998542924f4e689283c8040bb93a7d61a56164f08505335a2ff48eb8be8b60d0
5
5
  SHA512:
6
- metadata.gz: 0a6aaf02913914db7a2e4a6aa725a269126d39b7d395f95410da3331fed900152bca8e9598bf845608b18f8b80ca694bb282404131691e3f3a863b5aa5805e8d
7
- data.tar.gz: 2825a455fa03e1902a7ddb82058326cc314510899470f0f28cbcf6dc2ecec0ded4f3f2ada3db21388cc6f10c6048aa69a2aff6db47c2f9aefec177440f2c084d
6
+ metadata.gz: 150394f29d155746875ea2d5c5de8ebb3deb8c42d9ce61cd3b53d20bca5ef452f924bbb2d3a8bf9d0ec11f1e1a10f9ab44b8a5990e32a6fe51d0d01be4b8eea1
7
+ data.tar.gz: 12350432841a97cc14267d54a7c65633c9eaa78547fece5971416a62fe1a42b5797e3b26cc8f17d53b280fe3ce3ed9145edf20562f8714f4b64c762484217c5b
data/README.md CHANGED
@@ -44,30 +44,67 @@ CREATE EXTENSION pg_trgm;
44
44
 
45
45
  ## Deactivating authorization requirement and other module settings
46
46
 
47
- Some of the settings of the module need to be set in the code of your app, for example in the file `config/initializers/decidim.rb`.
47
+ Some of the settings of the module need to be set in the code of your app using the [environment variables](https://docs.decidim.org/en/develop/configure/environment_variables)
48
48
 
49
49
  This is the case if you want to enable the creation of initiatives even when no authorization method is set.
50
50
 
51
- Just use the following line:
51
+ Just set the following environment variable:
52
52
 
53
- ```ruby
54
- Decidim::Initiatives.do_not_require_authorization = true
53
+ ```bash
54
+ export INITIATIVES_DO_NOT_REQUIRE_AUTHORIZATION=true
55
55
  ```
56
56
 
57
- All the settings and their default values which can be overridden can be found in the file [`lib/decidim/initiatives.rb`](https://github.com/decidim/decidim/blob/develop/decidim-initiatives/lib/decidim/initiatives.rb).
57
+ For example, you can also change the minimum number of required committee members to 1 (default is 2) by exporting the following variable:
58
+
59
+ ```bash
60
+ export INITIATIVES_MINIMUM_COMMITTEE_MEMBERS=1
61
+ ```
58
62
 
59
- For example, you can also change the minimum number of required committee members to 1 (default is 2) by adding this line:
63
+ Or change the number of days given to gather signatures to 365 (default is 120) with:
60
64
 
61
65
  ```ruby
62
- Decidim::Initiatives.minimum_committee_members = 1
66
+ export INITIATIVES_DEFAULT_SIGNATURE_TIME_PERIOD_LENGTH=365
63
67
  ```
64
68
 
65
- Or change the number of days given to gather signatures to 365 (default is 120) with:
69
+ ### Initiatives signatures
70
+
71
+ Different signature workflows can be registered in the code of your app and used in the signature workflow settings of signatures types. A signature workflow defines some options of the signature steps and the form objects and commands responsible for validating and managing the data provided by the users.
72
+
73
+ To define a signature workflow create an initializer in your application and register it. For example, in `config/initializers/decidim_initiatives.rb`:
66
74
 
67
75
  ```ruby
68
- Decidim::Initiatives.default_signature_time_period_length = 365
76
+ Decidim::Initiatives::Signatures.register_workflow(:dummy_signature_handler) do |workflow|
77
+ workflow.form = "DummySignatureHandler"
78
+ workflow.authorization_handler_form = "DummyAuthorizationHandler"
79
+ workflow.action_authorizer = "DummySignatureHandler::DummySignatureActionAuthorizer"
80
+ workflow.promote_authorization_validation_errors = true
81
+ workflow.sms_verification = true
82
+ workflow.sms_mobile_phone_validator = "DummySmsMobilePhoneValidator"
83
+ end
84
+
85
+ Decidim::Initiatives::Signatures.register_workflow(:ephemeral_dummy_signature_handler) do |workflow|
86
+ workflow.form = "DummySignatureHandler"
87
+ workflow.ephemeral = true
88
+ workflow.authorization_handler_form = "DummyAuthorizationHandler"
89
+ workflow.action_authorizer = "DummySignatureHandler::DummySignatureActionAuthorizer"
90
+ workflow.promote_authorization_validation_errors = true
91
+ workflow.sms_verification = false
92
+ end
93
+
94
+ Decidim::Initiatives::Signatures.register_workflow(:legacy_signature_handler) do |workflow|
95
+ workflow.form = "Decidim::Initiatives::LegacySignatureHandler"
96
+ workflow.authorization_handler_form = "DummyAuthorizationHandler"
97
+ workflow.save_authorizations = false
98
+ workflow.sms_verification = true
99
+ end
69
100
  ```
70
101
 
102
+ All the attributes of a workflow are optional except the registered name with which the workflow is registered. A flow without attributes uses default values that generate a direct signature process without steps.
103
+
104
+ Signature workflows can be defined as ephemeral, in which case users can sign initiatives without prior registration. For a workflow of this type to work correctly, an authorization handler form must be defined in `authorization_handler_form` and authorizations saving must not be disabled using the `save_authorizations` setting, in order to ensure that user verifications are saved based on the personal data they provide.
105
+
106
+ For more information about the definition of a signature workflow read the documentation of `Decidim::Initiatives::SignatureWorkflowManifest` and `Decidim::Initiatives::SignatureHandler`
107
+
71
108
  ## Rake tasks
72
109
 
73
110
  This engine comes with three rake tasks that should be executed on daily basis. The best
@@ -1,4 +1,9 @@
1
1
  <% form.fields_for :settings, form.object.settings do |settings_fields| %>
2
- <%= settings_fields.number_field :max_results, label: max_results_label %>
3
- <%= settings_fields.select :order, order_select, prompt: "", label: order_label %>
2
+ <div class="row column">
3
+ <%= settings_fields.number_field :max_results, label: max_results_label %>
4
+ </div>
5
+
6
+ <div class="row column">
7
+ <%= settings_fields.select :order, order_select, prompt: "", label: order_label %>
8
+ </div>
4
9
  <% end %>
@@ -8,7 +8,11 @@ module Decidim
8
8
  private
9
9
 
10
10
  def resource_path
11
- Decidim::Initiatives::Engine.routes.url_helpers.initiative_path(model)
11
+ if resource.state == "created" || resource.state == "validating"
12
+ Decidim::Initiatives::Engine.routes.url_helpers.load_initiative_draft_create_initiative_index_path(initiative_id: resource.id)
13
+ else
14
+ Decidim::Initiatives::Engine.routes.url_helpers.initiative_path(model)
15
+ end
12
16
  end
13
17
 
14
18
  def image
@@ -42,11 +42,7 @@ module Decidim
42
42
  attr_reader :initiative, :current_user
43
43
 
44
44
  def increment_score
45
- if initiative.user_group
46
- Decidim::Gamification.increment_score(initiative.user_group, :initiatives)
47
- else
48
- Decidim::Gamification.increment_score(initiative.author, :initiatives)
49
- end
45
+ Decidim::Gamification.increment_score(initiative.author, :initiatives)
50
46
  end
51
47
  end
52
48
  end
@@ -37,8 +37,7 @@ module Decidim
37
37
  def attributes
38
38
  attrs = {
39
39
  title: form.title,
40
- description: form.description,
41
- hashtag: form.hashtag
40
+ description: form.description
42
41
  }
43
42
 
44
43
  if form.signature_type_updatable?
@@ -91,7 +91,6 @@ module Decidim
91
91
  author: current_user,
92
92
  scoped_type:,
93
93
  signature_type: form.type.signature_type,
94
- decidim_user_group_id: form.decidim_user_group_id,
95
94
  decidim_area_id: form.area_id,
96
95
  state: "created"
97
96
  )
@@ -76,9 +76,7 @@ module Decidim
76
76
  def attributes
77
77
  attrs = {
78
78
  title: { current_locale => form.title },
79
- description: { current_locale => form.description },
80
- hashtag: form.hashtag,
81
- decidim_user_group_id: form.decidim_user_group_id
79
+ description: { current_locale => form.description }
82
80
  }
83
81
 
84
82
  if form.signature_type_updatable?
@@ -28,7 +28,6 @@ module Decidim
28
28
 
29
29
  percentage_after = initiative.reload.percentage
30
30
 
31
- send_notification
32
31
  notify_percentage_change(percentage_before, percentage_after)
33
32
  notify_support_threshold_reached(percentage_before, percentage_after)
34
33
 
@@ -46,7 +45,7 @@ module Decidim
46
45
  def create_votes
47
46
  @votes = form.authorized_scopes.map do |scope|
48
47
  initiative.votes.create!(
49
- author: form.signer,
48
+ author: form.user,
50
49
  encrypted_metadata: form.encrypted_metadata,
51
50
  timestamp:,
52
51
  hash_id: form.hash_id,
@@ -65,15 +64,6 @@ module Decidim
65
64
  @timestamp_service ||= Decidim.timestamp_service.to_s.safe_constantize
66
65
  end
67
66
 
68
- def send_notification
69
- Decidim::EventsManager.publish(
70
- event: "decidim.events.initiatives.initiative_endorsed",
71
- event_class: Decidim::Initiatives::EndorseInitiativeEvent,
72
- resource: initiative,
73
- followers: initiative.author.followers
74
- )
75
- end
76
-
77
67
  def notify_percentage_change(before, after)
78
68
  percentage = [25, 50, 75, 100].find do |milestone|
79
69
  before < milestone && after >= milestone
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Initiatives
7
+ # This concern is used to detect the form associated with the signature
8
+ # workflow. If the manifest cannot be found the base SignatureHandler is
9
+ # used.
10
+ module HasSignatureWorkflow
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ helper_method :signature_has_steps?, :ephemeral_signature_workflow?
15
+
16
+ delegate :signature_form_class, :sms_mobile_phone_form_class, :sms_mobile_phone_validator_class, :sms_code_validator_class, to: :signature_workflow_manifest
17
+
18
+ def ephemeral_signature_workflow?
19
+ signature_workflow_manifest.ephemeral
20
+ end
21
+
22
+ private
23
+
24
+ def signature_workflow_manifest
25
+ @signature_workflow_manifest ||= current_initiative.type.signature_workflow_manifest || Decidim::Initiatives::SignatureWorkflowManifest.new
26
+ end
27
+
28
+ def signature_has_steps?
29
+ return unless current_initiative
30
+
31
+ signature_workflow_manifest.sms_verification || signature_form_class.requires_extra_attributes?
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -23,7 +23,7 @@ module Decidim
23
23
  include NeedsOrganization
24
24
  include InitiativeSlug
25
25
 
26
- helper_method :current_initiative, :current_participatory_space, :signature_has_steps?
26
+ helper_method :current_initiative, :current_participatory_space
27
27
 
28
28
  # Public: Finds the current Initiative given this controller's
29
29
  # context.
@@ -35,17 +35,6 @@ module Decidim
35
35
 
36
36
  alias_method :current_participatory_space, :current_initiative
37
37
 
38
- # Public: Whether the current initiative belongs to an initiative type
39
- # which requires one or more step before creating a signature
40
- #
41
- # Returns nil if there is no current_initiative, true or false
42
- def signature_has_steps?
43
- return unless current_initiative
44
-
45
- initiative_type = current_initiative.scoped_type.type
46
- initiative_type.collect_user_extra_fields? || initiative_type.validate_sms_code_on_votes?
47
- end
48
-
49
38
  private
50
39
 
51
40
  def detect_initiative
@@ -56,7 +56,7 @@ module Decidim
56
56
 
57
57
  on(:invalid) do
58
58
  flash.now[:alert] = I18n.t("initiatives.update.error", scope: "decidim.initiatives.admin")
59
- render :edit, layout: "decidim/admin/initiative"
59
+ render :edit, layout: "decidim/admin/initiative", status: :unprocessable_entity
60
60
  end
61
61
  end
62
62
  end
@@ -172,7 +172,7 @@ module Decidim
172
172
 
173
173
  @votes = current_initiative.votes
174
174
 
175
- serializer = Decidim::Forms::UserAnswersSerializer
175
+ serializer = Decidim::Forms::UserResponsesSerializer
176
176
  pdf_export = Decidim::Exporters::InitiativeVotesPDF.new(@votes, current_initiative, serializer).export
177
177
 
178
178
  output = if pdf_signature_service
@@ -31,7 +31,7 @@ module Decidim
31
31
 
32
32
  on(:invalid) do
33
33
  flash.now[:alert] = I18n.t("initiatives_settings.update.error", scope: "decidim.admin")
34
- render :edit
34
+ render :edit, status: :unprocessable_entity
35
35
  end
36
36
  end
37
37
  end
@@ -32,7 +32,7 @@ module Decidim
32
32
 
33
33
  on(:invalid) do
34
34
  flash.now[:alert] = I18n.t("decidim.initiatives.admin.initiatives_type_scopes.create.error")
35
- render :new
35
+ render :new, status: :unprocessable_entity
36
36
  end
37
37
  end
38
38
  end
@@ -56,7 +56,7 @@ module Decidim
56
56
 
57
57
  on(:invalid) do
58
58
  flash.now[:alert] = I18n.t("decidim.initiatives.admin.initiatives_type_scopes.update.error")
59
- render :edit
59
+ render :edit, status: :unprocessable_entity
60
60
  end
61
61
  end
62
62
  end
@@ -40,7 +40,7 @@ module Decidim
40
40
 
41
41
  on(:invalid) do
42
42
  flash.now[:alert] = I18n.t("decidim.initiatives.admin.initiatives_types.create.error")
43
- render :new
43
+ render :new, status: :unprocessable_entity
44
44
  end
45
45
  end
46
46
  end
@@ -68,7 +68,7 @@ module Decidim
68
68
 
69
69
  on(:invalid) do
70
70
  flash.now[:alert] = I18n.t("decidim.initiatives.admin.initiatives_types.update.error")
71
- render :edit
71
+ render :edit, status: :unprocessable_entity
72
72
  end
73
73
  end
74
74
  end
@@ -46,7 +46,7 @@ module Decidim
46
46
 
47
47
  ApproveMembershipRequest.call(membership_request) do
48
48
  on(:ok) do
49
- redirect_to edit_initiative_path(current_initiative), flash: {
49
+ redirect_to redirect_page, flash: {
50
50
  notice: I18n.t("success", scope: "decidim.initiatives.committee_requests.approve")
51
51
  }
52
52
  end
@@ -59,7 +59,7 @@ module Decidim
59
59
 
60
60
  RevokeMembershipRequest.call(membership_request) do
61
61
  on(:ok) do
62
- redirect_to edit_initiative_path(current_initiative), flash: {
62
+ redirect_to redirect_page, flash: {
63
63
  notice: I18n.t("success", scope: "decidim.initiatives.committee_requests.revoke")
64
64
  }
65
65
  end
@@ -68,6 +68,14 @@ module Decidim
68
68
 
69
69
  private
70
70
 
71
+ def redirect_page
72
+ if request.referer&.include?("create_initiative")
73
+ promotal_committee_create_initiative_index_path
74
+ else
75
+ edit_initiative_path(current_initiative)
76
+ end
77
+ end
78
+
71
79
  def membership_request
72
80
  @membership_request ||= InitiativesCommitteeMember.where(initiative: current_participatory_space).find(params[:id])
73
81
  end
@@ -21,6 +21,8 @@ module Decidim
21
21
  helper_method :current_initiative
22
22
  helper_method :initiative_type
23
23
  helper_method :promotal_committee_required?
24
+ helper_method :minimum_committee_members
25
+ helper_method :promoters_committee_members
24
26
 
25
27
  before_action :authenticate_user!
26
28
  before_action :ensure_type_exists,
@@ -29,7 +31,20 @@ module Decidim
29
31
  only: [:fill_data, :store_data, :promotal_committee, :finish]
30
32
  before_action :ensure_initiative_exists, only: [:promotal_committee, :finish]
31
33
 
34
+ def load_initiative_draft
35
+ session[:initiative_id] = params[:initiative_id]
36
+
37
+ if current_initiative.validating?
38
+ redirect_to finish_create_initiative_index_path
39
+ elsif current_initiative.created?
40
+ redirect_to promotal_committee_create_initiative_index_path
41
+ else
42
+ redirect_to initiatives_path
43
+ end
44
+ end
45
+
32
46
  def select_initiative_type
47
+ session[:initiative_id] = nil
33
48
  @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).from_params(params)
34
49
 
35
50
  redirect_to fill_data_create_initiative_index_path if single_initiative_type?
@@ -56,34 +71,70 @@ module Decidim
56
71
  end
57
72
 
58
73
  def store_data
74
+ if current_initiative
75
+ store_data_update_initiative
76
+ else
77
+ store_data_create_initiative
78
+ end
79
+ end
80
+
81
+ def promotal_committee
82
+ redirect_to finish_create_initiative_index_path unless promotal_committee_required?
83
+ end
84
+
85
+ def finish
86
+ current_initiative.presence
87
+
88
+ if current_initiative.validating?
89
+ session[:type_id] = nil
90
+ session[:initiative_id] = nil
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def store_data_create_initiative
59
97
  @form = form(Decidim::Initiatives::InitiativeForm).from_params(params, { initiative_type: })
60
98
 
61
99
  CreateInitiative.call(@form) do
62
100
  on(:ok) do |initiative|
63
101
  session[:initiative_id] = initiative.id
64
102
 
65
- path = promotal_committee_required? ? "promotal_committee" : "finish"
66
-
67
- redirect_to send(:"#{path}_create_initiative_index_path")
103
+ redirect_to store_data_next_step
68
104
  end
69
105
 
70
106
  on(:invalid) do
71
- render :fill_data
107
+ render :fill_data, status: :unprocessable_entity
72
108
  end
73
109
  end
74
110
  end
75
111
 
76
- def promotal_committee
77
- redirect_to finish_create_initiative_index_path unless promotal_committee_required?
112
+ def store_data_update_initiative
113
+ @form = form(Decidim::Initiatives::InitiativeForm).from_params(params, initiative_type: current_initiative.type, initiative: current_initiative)
114
+
115
+ UpdateInitiative.call(current_initiative, @form) do
116
+ on(:ok) do
117
+ flash[:notice] = I18n.t("success", scope: "decidim.initiatives.update")
118
+ redirect_to store_data_next_step
119
+ end
120
+
121
+ on(:invalid) do
122
+ render :fill_data, status: :unprocessable_entity
123
+ end
124
+ end
78
125
  end
79
126
 
80
- def finish
81
- current_initiative.presence
82
- session[:type_id] = nil
83
- session[:initiative_id] = nil
127
+ def store_data_next_step
128
+ if promotal_committee_required?
129
+ promotal_committee_create_initiative_index_path
130
+ else
131
+ finish_create_initiative_index_path
132
+ end
84
133
  end
85
134
 
86
- private
135
+ def membership_request
136
+ @membership_request ||= current_initiative.committee_members.find(params[:committee_member_id])
137
+ end
87
138
 
88
139
  def ensure_user_can_create_initiative
89
140
  enforce_permission_to :create, :initiative, { initiative_type: }
@@ -119,20 +170,35 @@ module Decidim
119
170
  end
120
171
 
121
172
  def current_initiative
122
- @current_initiative ||= Initiative.where(organization: current_organization).find_by(id: session[:initiative_id] || nil)
173
+ @current_initiative ||= Initiative.where(organization: current_organization, author: current_user).find_by(id: session[:initiative_id] || nil)
174
+ end
175
+
176
+ def initiative_types
177
+ @initiative_types ||= InitiativesType.where(organization: current_organization)
123
178
  end
124
179
 
125
180
  def initiative_type
126
- @initiative_type ||= InitiativesType.where(organization: current_organization).find_by(id: initiative_type_id)
181
+ @initiative_type ||= initiative_types.find_by(id: initiative_type_id)
127
182
  end
128
183
 
129
184
  def promotal_committee_required?
130
- return false if initiative_type.blank?
131
- return false unless initiative_type.promoting_committee_enabled?
185
+ if initiative_type.present?
186
+ initiative_type.promoting_committee_enabled? && minimum_committee_members.positive?
187
+ else
188
+ initiative_types.all?(&:promoting_committee_enabled?)
189
+ end
190
+ end
191
+
192
+ def minimum_committee_members
193
+ @minimum_committee_members ||= if initiative_type.blank? || !initiative_type.promoting_committee_enabled?
194
+ 0
195
+ else
196
+ initiative_type.minimum_committee_members || Decidim::Initiatives.minimum_committee_members
197
+ end
198
+ end
132
199
 
133
- minimum_committee_members = initiative_type.minimum_committee_members ||
134
- Decidim::Initiatives.minimum_committee_members
135
- minimum_committee_members.present? && minimum_committee_members.positive?
200
+ def promoters_committee_members
201
+ @promoters_committee_members ||= current_initiative.committee_members.approved
136
202
  end
137
203
  end
138
204
  end