decidim-initiatives 0.28.5 → 0.29.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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/cells/decidim/initiatives/initiative_g_cell.rb +6 -4
  4. data/app/cells/decidim/initiatives_votes/vote_cell.rb +1 -3
  5. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +9 -58
  6. data/app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb +5 -43
  7. data/app/commands/decidim/initiatives/admin/update_initiative.rb +25 -42
  8. data/app/commands/decidim/initiatives/admin/update_initiative_answer.rb +3 -4
  9. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +11 -61
  10. data/app/commands/decidim/initiatives/admin/update_initiative_type_scope.rb +2 -33
  11. data/app/commands/decidim/initiatives/admin/update_initiatives_settings.rb +2 -35
  12. data/app/commands/decidim/initiatives/approve_membership_request.rb +1 -1
  13. data/app/commands/decidim/initiatives/create_initiative.rb +6 -7
  14. data/app/commands/decidim/initiatives/revoke_membership_request.rb +1 -1
  15. data/app/commands/decidim/initiatives/spawn_committee_request.rb +4 -5
  16. data/app/commands/decidim/initiatives/update_initiative.rb +3 -3
  17. data/app/commands/decidim/initiatives/validate_sms_code.rb +3 -3
  18. data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +1 -1
  19. data/app/controllers/decidim/initiatives/admin/answers_controller.rb +1 -1
  20. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +7 -6
  21. data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +1 -1
  22. data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +2 -2
  23. data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +2 -2
  24. data/app/controllers/decidim/initiatives/application_controller.rb +5 -2
  25. data/app/controllers/decidim/initiatives/committee_requests_controller.rb +1 -2
  26. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +1 -1
  27. data/app/controllers/decidim/initiatives/initiatives_controller.rb +2 -2
  28. data/app/events/decidim/initiatives/approve_membership_request_event.rb +9 -29
  29. data/app/events/decidim/initiatives/create_initiative_event.rb +17 -36
  30. data/app/events/decidim/initiatives/revoke_membership_request_event.rb +10 -33
  31. data/app/events/decidim/initiatives/spawn_committee_request_event.rb +10 -33
  32. data/app/forms/decidim/initiatives/admin/initiative_answer_form.rb +1 -1
  33. data/app/forms/decidim/initiatives/admin/initiative_form.rb +3 -3
  34. data/app/forms/decidim/initiatives/admin/initiative_type_form.rb +2 -2
  35. data/app/forms/decidim/initiatives/initiative_form.rb +11 -1
  36. data/app/forms/decidim/initiatives/vote_form.rb +2 -2
  37. data/app/helpers/decidim/initiatives/initiative_helper.rb +0 -74
  38. data/app/helpers/decidim/initiatives/initiatives_helper.rb +0 -7
  39. data/app/models/decidim/initiative.rb +1 -1
  40. data/app/packs/entrypoints/decidim_initiatives_admin.js +0 -2
  41. data/app/packs/src/decidim/initiatives/admin/invite_users.js +1 -1
  42. data/app/permissions/decidim/initiatives/admin/permissions.rb +2 -2
  43. data/app/permissions/decidim/initiatives/permissions.rb +0 -14
  44. data/app/serializers/decidim/initiatives/initiative_serializer.rb +1 -1
  45. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
  46. data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +1 -2
  47. data/app/views/decidim/initiatives/admin/exports/_dropdown.html.erb +6 -6
  48. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +65 -59
  49. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/_form.html.erb +1 -1
  50. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +1 -1
  51. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +1 -1
  52. data/app/views/decidim/initiatives/committee_requests/new.html.erb +3 -4
  53. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +1 -1
  54. data/app/views/decidim/initiatives/initiatives/_interactions.html.erb +1 -1
  55. data/app/views/decidim/initiatives/initiatives/_new_initiative_button.html.erb +1 -1
  56. data/app/views/decidim/initiatives/initiatives/_vote_button.html.erb +1 -1
  57. data/app/views/decidim/initiatives/initiatives/print.html.erb +2 -2
  58. data/app/views/decidim/initiatives/initiatives/show.html.erb +2 -3
  59. data/app/views/layouts/decidim/_initiative_header.html.erb +6 -6
  60. data/app/views/layouts/decidim/initiative.html.erb +2 -2
  61. data/app/views/layouts/decidim/initiative_head.html.erb +1 -1
  62. data/config/initializers/wicked_pdf.rb +6 -4
  63. data/config/locales/ar.yml +0 -7
  64. data/config/locales/bg.yml +1 -3
  65. data/config/locales/ca.yml +7 -14
  66. data/config/locales/cs.yml +5 -13
  67. data/config/locales/de.yml +7 -14
  68. data/config/locales/el.yml +0 -4
  69. data/config/locales/en.yml +6 -13
  70. data/config/locales/es-MX.yml +7 -14
  71. data/config/locales/es-PY.yml +7 -14
  72. data/config/locales/es.yml +6 -13
  73. data/config/locales/eu.yml +51 -58
  74. data/config/locales/fi-plain.yml +6 -13
  75. data/config/locales/fi.yml +21 -28
  76. data/config/locales/fr-CA.yml +3 -5
  77. data/config/locales/fr.yml +2 -4
  78. data/config/locales/ga-IE.yml +0 -1
  79. data/config/locales/gl.yml +0 -4
  80. data/config/locales/he-IL.yml +0 -6
  81. data/config/locales/hu.yml +1 -4
  82. data/config/locales/id-ID.yml +0 -4
  83. data/config/locales/is-IS.yml +0 -8
  84. data/config/locales/it.yml +1 -3
  85. data/config/locales/ja.yml +8 -15
  86. data/config/locales/lb.yml +1 -1
  87. data/config/locales/lt.yml +0 -3
  88. data/config/locales/lv.yml +0 -4
  89. data/config/locales/nl.yml +0 -4
  90. data/config/locales/no.yml +0 -2
  91. data/config/locales/pl.yml +5 -2
  92. data/config/locales/pt-BR.yml +1 -17
  93. data/config/locales/pt.yml +0 -2
  94. data/config/locales/ro-RO.yml +0 -12
  95. data/config/locales/ru.yml +0 -9
  96. data/config/locales/sk.yml +0 -4
  97. data/config/locales/sv.yml +69 -194
  98. data/config/locales/tr-TR.yml +1 -3
  99. data/config/locales/uk.yml +0 -9
  100. data/config/locales/zh-CN.yml +0 -3
  101. data/config/locales/zh-TW.yml +0 -3
  102. data/decidim-initiatives.gemspec +3 -2
  103. data/lib/decidim/api/initiative_api_type.rb +2 -2
  104. data/lib/decidim/initiatives/engine.rb +1 -0
  105. data/lib/decidim/initiatives/menu.rb +12 -1
  106. data/lib/decidim/initiatives/seeds.rb +89 -64
  107. data/lib/decidim/initiatives/version.rb +1 -1
  108. data/lib/decidim/initiatives.rb +0 -12
  109. data/lib/tasks/decidim_initiatives.rake +3 -3
  110. data/lib/tasks/initiatives/upgrade/decidim_initiatives_upgrade_tasks.rake +9 -11
  111. metadata +33 -25
  112. data/app/forms/decidim/initiatives/previous_form.rb +0 -24
  113. data/app/packs/entrypoints/decidim_initiatives_admin.scss +0 -1
  114. data/app/packs/stylesheets/decidim/initiatives/admin/initiatives.scss +0 -13
  115. data/app/queries/decidim/initiatives/similar_initiatives.rb +0 -54
  116. data/config/locales/bn-BD.yml +0 -1
  117. data/config/locales/bs-BA.yml +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 385f59fc013f222a12e84ea61d1d07e2b89e35ddd948e9c2c296fca9d451a94e
4
- data.tar.gz: 18a6a641473cb761c30337e9fe87c9995fd55e94b6db0d7127dac6021ae8da4a
3
+ metadata.gz: cd08d9cd4c6c2cb8076f7c9b161dbbd6c2ed330e8cd2a5a76d5f111ebe64b51a
4
+ data.tar.gz: 42b081ca2e2c766cec299f9f8c23035a250c3a4313602572e60ec85ade2ef707
5
5
  SHA512:
6
- metadata.gz: cc8356303d54a4f5ba5d8b48a388a1cd56ffdf337cbac9f8e577e79b6b676b9edaf0d9862f5deb3c0e8f0aeb4ba87a8dfbae75104df9eaaf6573f3783e2db600
7
- data.tar.gz: 86dc4362c15cd2e458c19cf11f36d2a56e00346a30360ef7bab24ddc980400da4f1cf248345714d27ee95fc3306017522a9f8d5a88ccba80a4a4ee7dc4171948
6
+ metadata.gz: 79b0beb868ad7316b8d28e15172f4c7326f3b7793614bcc4be2a807c8bbd1d88776e9dc19fff7e73d556c68a82222972706d6911fb55441080c7ba2f9b0704de
7
+ data.tar.gz: '09312dad53e48a78893d965e23bb2dc4415667c765c1a77e39907756d4e3827202e3b9ee6c16a749633a7d907e1fda46aa1f5f3172bd46c524c41461468093c8'
data/README.md CHANGED
@@ -54,7 +54,7 @@ Just use the following line:
54
54
  Decidim::Initiatives.do_not_require_authorization = true
55
55
  ```
56
56
 
57
- All the settings and their default values which can be overriden can be found in the file [`lib/decidim/initiatives.rb`](https://github.com/decidim/decidim/blob/develop/decidim-initiatives/lib/decidim/initiatives.rb).
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).
58
58
 
59
59
  For example, you can also change the minimum number of required committee members to 1 (default is 2) by adding this line:
60
60
 
@@ -125,7 +125,7 @@ In order to populate the database with example data proceed as usual in rails:
125
125
  bundle exec rails db:seed
126
126
  ```
127
127
 
128
- ## Aditional considerations
128
+ ## Additional considerations
129
129
 
130
130
  ### Cookies
131
131
 
@@ -11,14 +11,16 @@ module Decidim
11
11
  Decidim::Initiatives::Engine.routes.url_helpers.initiative_path(model)
12
12
  end
13
13
 
14
+ def has_image?
15
+ image.present?
16
+ end
17
+
14
18
  def image
15
19
  @image ||= model.attachments.find(&:image?)
16
20
  end
17
21
 
18
- def resource_image_url
19
- return if image.blank?
20
-
21
- image.url
22
+ def resource_image_path
23
+ image.url if has_image?
22
24
  end
23
25
 
24
26
  def metadata_cell
@@ -3,8 +3,6 @@
3
3
  module Decidim
4
4
  module InitiativesVotes
5
5
  class VoteCell < Decidim::ViewModel
6
- include Decidim::SanitizeHelper
7
-
8
6
  delegate :timestamp, :hash_id, to: :model
9
7
 
10
8
  def show
@@ -16,7 +14,7 @@ module Decidim
16
14
  end
17
15
 
18
16
  def initiative_title
19
- decidim_sanitize(translated_attribute(model.initiative.title))
17
+ decidim_sanitize_translated(model.initiative.title)
20
18
  end
21
19
 
22
20
  def name_and_surname
@@ -4,67 +4,18 @@ module Decidim
4
4
  module Initiatives
5
5
  module Admin
6
6
  # A command with all the business logic that creates a new initiative type
7
- class CreateInitiativeType < Decidim::Command
8
- # Public: Initializes the command.
9
- #
10
- # form - A form object with the params.
11
- def initialize(form, user)
12
- @form = form
13
- @user = user
14
- end
7
+ class CreateInitiativeType < Decidim::Commands::CreateResource
8
+ fetch_file_attributes :banner_image
15
9
 
16
- # Executes the command. Broadcasts these events:
17
- #
18
- # - :ok when everything is valid.
19
- # - :invalid if the form was not valid and we could not proceed.
20
- #
21
- # Returns nothing.
22
- def call
23
- return broadcast(:invalid) if form.invalid?
10
+ fetch_form_attributes :title, :description, :signature_type, :comments_enabled, :attachments_enabled,
11
+ :undo_online_signatures_enabled, :custom_signature_end_date_enabled, :area_enabled,
12
+ :promoting_committee_enabled, :minimum_committee_members, :collect_user_extra_fields,
13
+ :extra_fields_legal_information, :validate_sms_code_on_votes, :document_number_authorization_handler,
14
+ :child_scope_threshold_enabled, :only_global_scope_enabled, :organization
24
15
 
25
- initiative_type = create_initiative_type
16
+ protected
26
17
 
27
- if initiative_type.persisted?
28
- broadcast(:ok, initiative_type)
29
- else
30
- form.errors.add(:banner_image, initiative_type.errors[:banner_image]) if initiative_type.errors.include? :banner_image
31
- broadcast(:invalid)
32
- end
33
- end
34
-
35
- private
36
-
37
- attr_reader :form
38
-
39
- def create_initiative_type
40
- initiative_type = Decidim.traceability.create!(
41
- InitiativesType,
42
- @user,
43
- organization: form.current_organization,
44
- title: form.title,
45
- description: form.description,
46
- signature_type: form.signature_type,
47
- comments_enabled: form.comments_enabled,
48
- attachments_enabled: form.attachments_enabled,
49
- undo_online_signatures_enabled: form.undo_online_signatures_enabled,
50
- custom_signature_end_date_enabled: form.custom_signature_end_date_enabled,
51
- area_enabled: form.area_enabled,
52
- promoting_committee_enabled: form.promoting_committee_enabled,
53
- minimum_committee_members: form.minimum_committee_members,
54
- banner_image: form.banner_image,
55
- collect_user_extra_fields: form.collect_user_extra_fields,
56
- extra_fields_legal_information: form.extra_fields_legal_information,
57
- validate_sms_code_on_votes: form.validate_sms_code_on_votes,
58
- document_number_authorization_handler: form.document_number_authorization_handler,
59
- child_scope_threshold_enabled: form.child_scope_threshold_enabled,
60
- only_global_scope_enabled: form.only_global_scope_enabled
61
- )
62
-
63
- return initiative_type unless initiative_type.valid?
64
-
65
- initiative_type.save
66
- initiative_type
67
- end
18
+ def resource_class = Decidim::InitiativesType
68
19
  end
69
20
  end
70
21
  end
@@ -4,52 +4,14 @@ module Decidim
4
4
  module Initiatives
5
5
  module Admin
6
6
  # A command with all the business logic that creates a new initiative type scope
7
- class CreateInitiativeTypeScope < Decidim::Command
8
- # Public: Initializes the command.
9
- #
10
- # form - A form object with the params.
11
- def initialize(form)
12
- @form = form
13
- end
7
+ class CreateInitiativeTypeScope < Decidim::Commands::CreateResource
8
+ protected
14
9
 
15
- # Executes the command. Broadcasts these events:
16
- #
17
- # - :ok when everything is valid.
18
- # - :invalid if the form was not valid and we could not proceed.
19
- #
20
- # Returns nothing.
21
- def call
22
- return broadcast(:invalid) if form.invalid?
10
+ fetch_form_attributes :supports_required, :decidim_scopes_id
23
11
 
24
- initiative_type_scope = create_initiative_type_scope
12
+ def attributes = super.merge(decidim_initiatives_types_id: form.context.type_id)
25
13
 
26
- if initiative_type_scope.persisted?
27
- broadcast(:ok, initiative_type_scope)
28
- else
29
- initiative_type_scope.errors.each do |error|
30
- form.errors.add(error.attribute, error.message)
31
- end
32
-
33
- broadcast(:invalid)
34
- end
35
- end
36
-
37
- private
38
-
39
- attr_reader :form
40
-
41
- def create_initiative_type_scope
42
- initiative_type = InitiativesTypeScope.new(
43
- supports_required: form.supports_required,
44
- decidim_scopes_id: form.decidim_scopes_id,
45
- decidim_initiatives_types_id: form.context.type_id
46
- )
47
-
48
- return initiative_type unless initiative_type.valid?
49
-
50
- initiative_type.save
51
- initiative_type
52
- end
14
+ def resource_class = Decidim::InitiativesTypeScope
53
15
  end
54
16
  end
55
17
  end
@@ -5,51 +5,34 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic that updates an
7
7
  # existing initiative.
8
- class UpdateInitiative < Decidim::Command
8
+ class UpdateInitiative < Decidim::Commands::UpdateResource
9
9
  include Decidim::Initiatives::AttachmentMethods
10
10
 
11
- # Public: Initializes the command.
12
- #
13
- # initiative - Decidim::Initiative
14
- # form - A form object with the params.
15
- def initialize(initiative, form, current_user)
16
- @form = form
17
- @initiative = initiative
18
- @current_user = current_user
19
- @attached_to = initiative
20
- end
21
-
22
- # Executes the command. Broadcasts these events:
23
- #
24
- # - :ok when everything is valid.
25
- # - :invalid if the form was not valid and we could not proceed.
26
- #
27
- # Returns nothing.
28
- def call
29
- return broadcast(:invalid) if form.invalid?
11
+ protected
30
12
 
31
- if process_attachments?
32
- @initiative.attachments.destroy_all
13
+ attr_reader :attachment
33
14
 
34
- build_attachment
35
- return broadcast(:invalid) if attachment_invalid?
36
- end
15
+ def update_resource
16
+ super
17
+ rescue ActiveRecord::RecordInvalid
18
+ raise Decidim::Commands::HookError
19
+ end
37
20
 
38
- @initiative = Decidim.traceability.update!(
39
- initiative,
40
- current_user,
41
- attributes
42
- )
21
+ def run_after_hooks
43
22
  create_attachment if process_attachments?
44
23
  notify_initiative_is_extended if @notify_extended
45
- broadcast(:ok, initiative)
46
- rescue ActiveRecord::RecordInvalid
47
- broadcast(:invalid, initiative)
48
24
  end
49
25
 
50
- private
26
+ def run_before_hooks
27
+ return unless process_attachments?
28
+
29
+ resource.attachments.destroy_all
51
30
 
52
- attr_reader :form, :initiative, :current_user, :attachment
31
+ @attached_to = resource
32
+
33
+ build_attachment
34
+ raise Decidim::Commands::HookError if attachment_invalid?
35
+ end
53
36
 
54
37
  def attributes
55
38
  attrs = {
@@ -65,9 +48,9 @@ module Decidim
65
48
 
66
49
  if current_user.admin?
67
50
  add_admin_accessible_attrs(attrs)
68
- elsif initiative.created?
69
- attrs[:signature_end_date] = form.signature_end_date if initiative.custom_signature_end_date_enabled?
70
- attrs[:decidim_area_id] = form.area_id if initiative.area_enabled?
51
+ elsif resource.created?
52
+ attrs[:signature_end_date] = form.signature_end_date if resource.custom_signature_end_date_enabled?
53
+ attrs[:decidim_area_id] = form.area_id if resource.area_enabled?
71
54
  end
72
55
 
73
56
  attrs
@@ -80,8 +63,8 @@ module Decidim
80
63
  attrs[:state] = form.state if form.state
81
64
  attrs[:decidim_area_id] = form.area_id
82
65
 
83
- if initiative.published? && form.signature_end_date != initiative.signature_end_date &&
84
- form.signature_end_date > initiative.signature_end_date
66
+ if resource.published? && form.signature_end_date != resource.signature_end_date &&
67
+ form.signature_end_date > resource.signature_end_date
85
68
  @notify_extended = true
86
69
  end
87
70
  end
@@ -90,8 +73,8 @@ module Decidim
90
73
  Decidim::EventsManager.publish(
91
74
  event: "decidim.events.initiatives.initiative_extended",
92
75
  event_class: Decidim::Initiatives::ExtendInitiativeEvent,
93
- resource: initiative,
94
- followers: initiative.followers - [initiative.author]
76
+ resource:,
77
+ followers: resource.followers - [resource.author]
95
78
  )
96
79
  end
97
80
  end
@@ -6,15 +6,14 @@ module Decidim
6
6
  # A command with all the business logic to answer
7
7
  # initiatives.
8
8
  class UpdateInitiativeAnswer < Decidim::Command
9
+ delegate :current_user, to: :form
9
10
  # Public: Initializes the command.
10
11
  #
11
12
  # initiative - Decidim::Initiative
12
13
  # form - A form object with the params.
13
- # current_user - Decidim::User
14
- def initialize(initiative, form, current_user)
14
+ def initialize(initiative, form)
15
15
  @form = form
16
16
  @initiative = initiative
17
- @current_user = current_user
18
17
  end
19
18
 
20
19
  # Executes the command. Broadcasts these events:
@@ -39,7 +38,7 @@ module Decidim
39
38
 
40
39
  private
41
40
 
42
- attr_reader :form, :initiative, :current_user
41
+ attr_reader :form, :initiative
43
42
 
44
43
  def attributes
45
44
  attrs = {
@@ -5,70 +5,20 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic that updates an
7
7
  # existing initiative type.
8
- class UpdateInitiativeType < Decidim::Command
9
- include ::Decidim::AttachmentAttributesMethods
8
+ class UpdateInitiativeType < Decidim::Commands::UpdateResource
9
+ fetch_file_attributes :banner_image
10
10
 
11
- # Public: Initializes the command.
12
- #
13
- # initiative_type: Decidim::InitiativesType
14
- # form - A form object with the params.
15
- def initialize(initiative_type, form, user)
16
- @form = form
17
- @initiative_type = initiative_type
18
- @user = user
19
- end
20
-
21
- # Executes the command. Broadcasts these events:
22
- #
23
- # - :ok when everything is valid.
24
- # - :invalid if the form was not valid and we could not proceed.
25
- #
26
- # Returns nothing.
27
- def call
28
- return broadcast(:invalid) if form.invalid?
29
-
30
- Decidim.traceability.perform_action!("update", initiative_type, @user) do
31
- initiative_type.update(attributes)
11
+ fetch_form_attributes :title, :description, :signature_type, :attachments_enabled, :comments_enabled,
12
+ :undo_online_signatures_enabled, :custom_signature_end_date_enabled, :area_enabled,
13
+ :promoting_committee_enabled, :minimum_committee_members, :collect_user_extra_fields,
14
+ :extra_fields_legal_information, :validate_sms_code_on_votes, :document_number_authorization_handler,
15
+ :child_scope_threshold_enabled, :only_global_scope_enabled
32
16
 
33
- if initiative_type.valid?
34
- update_initiatives_signature_type
35
- broadcast(:ok, initiative_type)
36
- else
37
- broadcast(:invalid)
38
- end
39
- end
40
- end
41
-
42
- private
43
-
44
- attr_reader :form, :initiative_type
45
-
46
- def attributes
47
- {
48
- title: form.title,
49
- description: form.description,
50
- signature_type: form.signature_type,
51
- attachments_enabled: form.attachments_enabled,
52
- comments_enabled: form.comments_enabled,
53
- undo_online_signatures_enabled: form.undo_online_signatures_enabled,
54
- custom_signature_end_date_enabled: form.custom_signature_end_date_enabled,
55
- area_enabled: form.area_enabled,
56
- promoting_committee_enabled: form.promoting_committee_enabled,
57
- minimum_committee_members: form.minimum_committee_members,
58
- collect_user_extra_fields: form.collect_user_extra_fields,
59
- extra_fields_legal_information: form.extra_fields_legal_information,
60
- validate_sms_code_on_votes: form.validate_sms_code_on_votes,
61
- document_number_authorization_handler: form.document_number_authorization_handler,
62
- child_scope_threshold_enabled: form.child_scope_threshold_enabled,
63
- only_global_scope_enabled: form.only_global_scope_enabled
64
- }.merge(
65
- attachment_attributes(:banner_image)
66
- )
67
- end
17
+ protected
68
18
 
69
- def update_initiatives_signature_type
70
- initiative_type.initiatives.signature_type_updatable.each do |initiative|
71
- initiative.update!(signature_type: initiative_type.signature_type)
19
+ def run_after_hooks
20
+ resource.initiatives.signature_type_updatable.each do |initiative|
21
+ initiative.update!(signature_type: resource.signature_type)
72
22
  end
73
23
  end
74
24
  end
@@ -5,39 +5,8 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic that updates an
7
7
  # existing initiative type scope.
8
- class UpdateInitiativeTypeScope < Decidim::Command
9
- # Public: Initializes the command.
10
- #
11
- # initiative_type: Decidim::InitiativesTypeScope
12
- # form - A form object with the params.
13
- def initialize(initiative_type_scope, form)
14
- @form = form
15
- @initiative_type_scope = initiative_type_scope
16
- end
17
-
18
- # Executes the command. Broadcasts these events:
19
- #
20
- # - :ok when everything is valid.
21
- # - :invalid if the form was not valid and we could not proceed.
22
- #
23
- # Returns nothing.
24
- def call
25
- return broadcast(:invalid) if form.invalid?
26
-
27
- initiative_type_scope.update(attributes)
28
- broadcast(:ok, initiative_type_scope)
29
- end
30
-
31
- private
32
-
33
- attr_reader :form, :initiative_type_scope
34
-
35
- def attributes
36
- {
37
- supports_required: form.supports_required,
38
- decidim_scopes_id: form.decidim_scopes_id
39
- }
40
- end
8
+ class UpdateInitiativeTypeScope < Decidim::Commands::UpdateResource
9
+ fetch_form_attributes :supports_required, :decidim_scopes_id
41
10
  end
42
11
  end
43
12
  end
@@ -5,41 +5,8 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic when updating initiatives
7
7
  # settings in admin area.
8
- class UpdateInitiativesSettings < Decidim::Command
9
- # Public: Initializes the command.
10
- #
11
- # initiatives_settings - A initiatives settings object to update.
12
- # form - A form object with the params.
13
- def initialize(initiatives_settings, form)
14
- @initiatives_settings = initiatives_settings
15
- @form = form
16
- end
17
-
18
- # Executes the command. Broadcasts these events:
19
- #
20
- # - :ok when everything is valid.
21
- # - :invalid if the form or initiatives_settings is not valid and we could not proceed.
22
- #
23
- # Returns nothing.
24
- def call
25
- return broadcast(:invalid) if form.invalid? || initiatives_settings.invalid?
26
-
27
- update_initiatives_settings!
28
-
29
- broadcast(:ok)
30
- end
31
-
32
- private
33
-
34
- attr_reader :form, :initiatives_settings
35
-
36
- def update_initiatives_settings!
37
- Decidim.traceability.update!(
38
- @initiatives_settings,
39
- form.current_user,
40
- initiatives_order: form.initiatives_order
41
- )
42
- end
8
+ class UpdateInitiativesSettings < Decidim::Commands::UpdateResource
9
+ fetch_form_attributes :initiatives_order
43
10
  end
44
11
  end
45
12
  end
@@ -32,7 +32,7 @@ module Decidim
32
32
  resource: @membership_request.initiative,
33
33
  affected_users: [@membership_request.user],
34
34
  force_send: true,
35
- extra: { author: { id: @membership_request.initiative.author&.id } }
35
+ extra: { author: @membership_request.initiative.author }
36
36
  )
37
37
  end
38
38
  end
@@ -10,13 +10,12 @@ module Decidim
10
10
  include ::Decidim::MultipleAttachmentsMethods
11
11
  include ::Decidim::GalleryMethods
12
12
 
13
+ delegate :current_user, to: :form
13
14
  # Public: Initializes the command.
14
15
  #
15
16
  # form - A form object with the params.
16
- # current_user - Current user.
17
- def initialize(form, current_user)
17
+ def initialize(form)
18
18
  @form = form
19
- @current_user = current_user
20
19
  end
21
20
 
22
21
  # Executes the command. Broadcasts these events:
@@ -49,7 +48,7 @@ module Decidim
49
48
 
50
49
  private
51
50
 
52
- attr_reader :form, :current_user, :attachment
51
+ attr_reader :form, :attachment
53
52
 
54
53
  # Creates the initiative and all default components
55
54
  def create_initiative
@@ -87,7 +86,7 @@ module Decidim
87
86
  end
88
87
 
89
88
  def scoped_type
90
- InitiativesTypeScope.order(:id).find_by(type: form.type, scope: form.scope)
89
+ InitiativesTypeScope.order(:id).find_by(type: form.type)
91
90
  end
92
91
 
93
92
  def signature_end_date
@@ -138,7 +137,7 @@ module Decidim
138
137
  current_user:
139
138
  )
140
139
 
141
- Decidim::CreateFollow.new(form, current_user).call
140
+ Decidim::CreateFollow.new(form).call
142
141
  end
143
142
 
144
143
  def add_author_as_committee_member(initiative)
@@ -149,7 +148,7 @@ module Decidim
149
148
  current_user:
150
149
  )
151
150
 
152
- Decidim::Initiatives::SpawnCommitteeRequest.new(form, current_user).call
151
+ Decidim::Initiatives::SpawnCommitteeRequest.new(form).call
153
152
  end
154
153
  end
155
154
  end
@@ -32,7 +32,7 @@ module Decidim
32
32
  resource: @membership_request.initiative,
33
33
  affected_users: [@membership_request.user],
34
34
  force_send: true,
35
- extra: { author: { id: @membership_request.initiative.author&.id } }
35
+ extra: { author: @membership_request.initiative.author }
36
36
  )
37
37
  end
38
38
  end
@@ -5,13 +5,12 @@ module Decidim
5
5
  # A command with all the business logic that creates a new membership
6
6
  # request for the committee of an initiative.
7
7
  class SpawnCommitteeRequest < Decidim::Command
8
+ delegate :current_user, to: :form
8
9
  # Public: Initializes the command.
9
10
  #
10
11
  # form - Decidim::Initiative::CommitteeMemberForm
11
- # current_user - Decidim::User
12
- def initialize(form, current_user)
12
+ def initialize(form)
13
13
  @form = form
14
- @current_user = current_user
15
14
  end
16
15
 
17
16
  # Executes the command. Broadcasts these events:
@@ -35,7 +34,7 @@ module Decidim
35
34
 
36
35
  private
37
36
 
38
- attr_reader :form, :current_user
37
+ attr_reader :form
39
38
 
40
39
  def create_request
41
40
  request = InitiativesCommitteeMember.new(
@@ -58,7 +57,7 @@ module Decidim
58
57
  resource: initiative,
59
58
  affected_users: [initiative.author],
60
59
  force_send: true,
61
- extra: { applicant: { id: current_user&.id } }
60
+ extra: { applicant: current_user }
62
61
  )
63
62
  end
64
63
 
@@ -8,15 +8,15 @@ module Decidim
8
8
  include ::Decidim::MultipleAttachmentsMethods
9
9
  include ::Decidim::GalleryMethods
10
10
  include CurrentLocale
11
+ delegate :current_user, to: :form
11
12
 
12
13
  # Public: Initializes the command.
13
14
  #
14
15
  # initiative - Decidim::Initiative
15
16
  # form - A form object with the params.
16
- def initialize(initiative, form, current_user)
17
+ def initialize(initiative, form)
17
18
  @form = form
18
19
  @initiative = initiative
19
- @current_user = current_user
20
20
  @attached_to = initiative
21
21
  end
22
22
 
@@ -57,7 +57,7 @@ module Decidim
57
57
 
58
58
  private
59
59
 
60
- attr_reader :form, :initiative, :current_user
60
+ attr_reader :form, :initiative
61
61
 
62
62
  def attributes
63
63
  attrs = {
@@ -15,7 +15,7 @@ module Decidim
15
15
 
16
16
  # Executes the command. Broadcasts these events:
17
17
  #
18
- # - :ok when everithing is valid.
18
+ # - :ok when everything is valid.
19
19
  # - :invalid if verification_metadata is not present or the form code is
20
20
  # invalid.
21
21
  #
@@ -29,11 +29,11 @@ module Decidim
29
29
  private
30
30
 
31
31
  def verification_metadata_valid?
32
- @verification_metadata && @verification_metadata["verification_code"].present?
32
+ @verification_metadata && @verification_metadata[:verification_code].present?
33
33
  end
34
34
 
35
35
  def valid_code?
36
- @verification_metadata["verification_code"] == @form.verification_code
36
+ @verification_metadata[:verification_code] == @form.verification_code
37
37
  end
38
38
  end
39
39
  end
@@ -35,7 +35,7 @@ module Decidim
35
35
 
36
36
  alias_method :current_participatory_space, :current_initiative
37
37
 
38
- # Public: Wether the current initiative belongs to an initiative type
38
+ # Public: Whether the current initiative belongs to an initiative type
39
39
  # which requires one or more step before creating a signature
40
40
  #
41
41
  # Returns nil if there is no current_initiative, true or false