decidim-initiatives 0.28.2 → 0.29.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/cells/decidim/initiatives_votes/vote_cell.rb +1 -3
  4. data/app/commands/decidim/initiatives/admin/create_initiative_type.rb +9 -58
  5. data/app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb +5 -43
  6. data/app/commands/decidim/initiatives/admin/update_initiative.rb +25 -42
  7. data/app/commands/decidim/initiatives/admin/update_initiative_answer.rb +3 -4
  8. data/app/commands/decidim/initiatives/admin/update_initiative_type.rb +11 -61
  9. data/app/commands/decidim/initiatives/admin/update_initiative_type_scope.rb +2 -33
  10. data/app/commands/decidim/initiatives/admin/update_initiatives_settings.rb +2 -35
  11. data/app/commands/decidim/initiatives/create_initiative.rb +5 -6
  12. data/app/commands/decidim/initiatives/spawn_committee_request.rb +3 -4
  13. data/app/commands/decidim/initiatives/update_initiative.rb +3 -3
  14. data/app/commands/decidim/initiatives/validate_sms_code.rb +3 -3
  15. data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +1 -1
  16. data/app/controllers/decidim/initiatives/admin/answers_controller.rb +1 -1
  17. data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +7 -1
  18. data/app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb +1 -1
  19. data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +2 -2
  20. data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +2 -2
  21. data/app/controllers/decidim/initiatives/application_controller.rb +5 -2
  22. data/app/controllers/decidim/initiatives/committee_requests_controller.rb +1 -1
  23. data/app/controllers/decidim/initiatives/create_initiative_controller.rb +1 -1
  24. data/app/controllers/decidim/initiatives/initiatives_controller.rb +1 -1
  25. data/app/events/decidim/initiatives/approve_membership_request_event.rb +9 -29
  26. data/app/events/decidim/initiatives/create_initiative_event.rb +17 -36
  27. data/app/events/decidim/initiatives/revoke_membership_request_event.rb +10 -33
  28. data/app/events/decidim/initiatives/spawn_committee_request_event.rb +10 -33
  29. data/app/forms/decidim/initiatives/admin/initiative_form.rb +2 -2
  30. data/app/forms/decidim/initiatives/initiative_form.rb +11 -1
  31. data/app/forms/decidim/initiatives/vote_form.rb +2 -2
  32. data/app/helpers/decidim/initiatives/initiative_helper.rb +0 -74
  33. data/app/helpers/decidim/initiatives/initiatives_helper.rb +0 -7
  34. data/app/models/decidim/initiative.rb +1 -1
  35. data/app/packs/src/decidim/initiatives/admin/invite_users.js +1 -1
  36. data/app/serializers/decidim/initiatives/initiative_serializer.rb +1 -1
  37. data/app/views/decidim/initiatives/admin/answers/_info_initiative.html.erb +1 -1
  38. data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +1 -1
  39. data/app/views/decidim/initiatives/admin/exports/_dropdown.html.erb +1 -1
  40. data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +74 -68
  41. data/app/views/decidim/initiatives/admin/initiatives_type_scopes/_form.html.erb +1 -1
  42. data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +1 -1
  43. data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +1 -1
  44. data/app/views/decidim/initiatives/committee_requests/new.html.erb +1 -2
  45. data/app/views/decidim/initiatives/initiative_signatures/fill_personal_data.html.erb +1 -1
  46. data/app/views/decidim/initiatives/initiatives/_interactions.html.erb +1 -1
  47. data/app/views/decidim/initiatives/initiatives/_new_initiative_button.html.erb +1 -1
  48. data/app/views/decidim/initiatives/initiatives/_vote_button.html.erb +1 -1
  49. data/app/views/decidim/initiatives/initiatives/print.html.erb +2 -2
  50. data/app/views/decidim/initiatives/initiatives/show.html.erb +1 -2
  51. data/app/views/layouts/decidim/_initiative_header.html.erb +5 -5
  52. data/app/views/layouts/decidim/initiative.html.erb +1 -1
  53. data/config/initializers/wicked_pdf.rb +5 -5
  54. data/config/locales/ar.yml +0 -1
  55. data/config/locales/bg.yml +1 -3
  56. data/config/locales/ca.yml +5 -2
  57. data/config/locales/cs.yml +4 -2
  58. data/config/locales/de.yml +6 -3
  59. data/config/locales/el.yml +0 -1
  60. data/config/locales/en.yml +6 -3
  61. data/config/locales/es-MX.yml +5 -2
  62. data/config/locales/es-PY.yml +5 -2
  63. data/config/locales/es.yml +5 -2
  64. data/config/locales/eu.yml +6 -3
  65. data/config/locales/fi-plain.yml +5 -2
  66. data/config/locales/fi.yml +5 -2
  67. data/config/locales/fr-CA.yml +1 -3
  68. data/config/locales/fr.yml +1 -3
  69. data/config/locales/gl.yml +0 -1
  70. data/config/locales/he-IL.yml +0 -6
  71. data/config/locales/hu.yml +0 -3
  72. data/config/locales/id-ID.yml +0 -1
  73. data/config/locales/it.yml +0 -1
  74. data/config/locales/ja.yml +6 -3
  75. data/config/locales/lt.yml +0 -3
  76. data/config/locales/lv.yml +0 -1
  77. data/config/locales/nl.yml +0 -1
  78. data/config/locales/no.yml +0 -1
  79. data/config/locales/pl.yml +5 -2
  80. data/config/locales/pt-BR.yml +0 -2
  81. data/config/locales/pt.yml +0 -1
  82. data/config/locales/ro-RO.yml +0 -1
  83. data/config/locales/ru.yml +0 -1
  84. data/config/locales/sk.yml +0 -1
  85. data/config/locales/sv.yml +0 -1
  86. data/config/locales/tr-TR.yml +0 -1
  87. data/config/locales/uk.yml +0 -1
  88. data/config/locales/zh-CN.yml +0 -1
  89. data/config/locales/zh-TW.yml +0 -3
  90. data/decidim-initiatives.gemspec +1 -1
  91. data/lib/decidim/api/initiative_api_type.rb +1 -1
  92. data/lib/decidim/initiatives/engine.rb +1 -0
  93. data/lib/decidim/initiatives/menu.rb +12 -1
  94. data/lib/decidim/initiatives/seeds.rb +89 -64
  95. data/lib/decidim/initiatives/version.rb +1 -1
  96. data/lib/decidim/initiatives.rb +0 -12
  97. data/lib/tasks/decidim_initiatives.rake +3 -3
  98. data/lib/tasks/initiatives/upgrade/decidim_initiatives_upgrade_tasks.rake +9 -11
  99. metadata +17 -19
  100. data/app/forms/decidim/initiatives/previous_form.rb +0 -24
  101. data/app/queries/decidim/initiatives/similar_initiatives.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee9402e2ccd3d11cecca9129ce2f63a68547640abb7699b2e98f23bc47a7b44b
4
- data.tar.gz: 841ab41667a8e6391c9dc779028408d38a3bf0dcace1bf31b5bb1999d1b04c00
3
+ metadata.gz: cd08d9cd4c6c2cb8076f7c9b161dbbd6c2ed330e8cd2a5a76d5f111ebe64b51a
4
+ data.tar.gz: 42b081ca2e2c766cec299f9f8c23035a250c3a4313602572e60ec85ade2ef707
5
5
  SHA512:
6
- metadata.gz: fb1bc518c0f6be5a2a1f2a1063c726a4f46d5f502ad6a1f6a420140de228db5b367bd1d0e9c61585c90c8acef7594e6d98ae54a4ea634e7af54d2a839e5b455a
7
- data.tar.gz: 682efa73c8d37f54e0b2959a4cfff03b542e984cd8cfb2a57c53938e7b524bd302d81982a21e8272f9d9c754824a66fb93bc9c4f6fca9ec9c50d538b4ab6585c
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
 
@@ -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
@@ -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
@@ -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
@@ -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(
@@ -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
@@ -30,7 +30,7 @@ module Decidim
30
30
  @form = form(Decidim::Initiatives::Admin::InitiativeAnswerForm)
31
31
  .from_params(params, initiative: current_initiative)
32
32
 
33
- UpdateInitiativeAnswer.call(current_initiative, @form, current_user) do
33
+ UpdateInitiativeAnswer.call(current_initiative, @form) do
34
34
  on(:ok) do
35
35
  flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin")
36
36
  redirect_to initiatives_path
@@ -17,6 +17,8 @@ module Decidim
17
17
  helper Decidim::Initiatives::InitiativeHelper
18
18
  helper Decidim::Initiatives::SignatureTypeOptionsHelper
19
19
 
20
+ helper_method :show_initiative_type_callout?
21
+
20
22
  # GET /admin/initiatives
21
23
  def index
22
24
  enforce_permission_to :list, :initiative
@@ -46,7 +48,7 @@ module Decidim
46
48
  @form = form(Decidim::Initiatives::Admin::InitiativeForm)
47
49
  .from_params(params, initiative: current_initiative)
48
50
 
49
- Decidim::Initiatives::Admin::UpdateInitiative.call(current_initiative, @form, current_user) do
51
+ Decidim::Initiatives::Admin::UpdateInitiative.call(@form, current_initiative) do
50
52
  on(:ok) do |initiative|
51
53
  flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin")
52
54
  redirect_to edit_initiative_path(initiative)
@@ -183,6 +185,10 @@ module Decidim
183
185
 
184
186
  private
185
187
 
188
+ def show_initiative_type_callout?
189
+ Decidim::InitiativesType.where(organization: current_organization).none?
190
+ end
191
+
186
192
  def collection
187
193
  @collection ||= ManageableInitiatives.for(current_user)
188
194
  end
@@ -23,7 +23,7 @@ module Decidim
23
23
  @form = initiatives_settings_form
24
24
  .from_params(params, initiatives_settings: current_initiatives_settings)
25
25
 
26
- UpdateInitiativesSettings.call(current_initiatives_settings, @form) do
26
+ UpdateInitiativesSettings.call(@form, current_initiatives_settings) do
27
27
  on(:ok) do
28
28
  flash[:notice] = I18n.t("initiatives_settings.update.success", scope: "decidim.admin")
29
29
  redirect_to edit_initiatives_setting_path