decidim-participatory_processes 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +36 -0
  3. data/Rakefile +3 -0
  4. data/app/assets/config/admin/decidim_participatory_processes_manifest.js +1 -0
  5. data/app/assets/config/decidim_participatory_processes_manifest.js +2 -0
  6. data/app/assets/images/decidim/participatory_processes/process.svg +10 -0
  7. data/app/assets/javascripts/decidim/participatory_processes/admin/participatory_processes.js.es6 +12 -0
  8. data/app/assets/javascripts/decidim/participatory_processes/filters.js.es6 +25 -0
  9. data/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb +46 -0
  10. data/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb +116 -0
  11. data/app/commands/decidim/participatory_processes/admin/create_participatory_process.rb +82 -0
  12. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_admin.rb +95 -0
  13. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb +57 -0
  14. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_step.rb +49 -0
  15. data/app/commands/decidim/participatory_processes/admin/deactivate_participatory_process_step.rb +38 -0
  16. data/app/commands/decidim/participatory_processes/admin/destroy_participatory_process_step.rb +46 -0
  17. data/app/commands/decidim/participatory_processes/admin/publish_participatory_process.rb +34 -0
  18. data/app/commands/decidim/participatory_processes/admin/reorder_participatory_process_steps.rb +54 -0
  19. data/app/commands/decidim/participatory_processes/admin/unpublish_participatory_process.rb +34 -0
  20. data/app/commands/decidim/participatory_processes/admin/update_participatory_process.rb +77 -0
  21. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb +43 -0
  22. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_group.rb +60 -0
  23. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb +51 -0
  24. data/app/constraints/decidim/participatory_processes/current_feature.rb +28 -0
  25. data/app/constraints/decidim/participatory_processes/current_participatory_process.rb +37 -0
  26. data/app/controllers/concerns/decidim/participatory_processes/admin/participatory_process_context.rb +21 -0
  27. data/app/controllers/concerns/decidim/participatory_processes/needs_participatory_process.rb +50 -0
  28. data/app/controllers/concerns/decidim/participatory_processes/participatory_process_context.rb +27 -0
  29. data/app/controllers/decidim/participatory_processes/admin/application_controller.rb +11 -0
  30. data/app/controllers/decidim/participatory_processes/admin/categories_controller.rb +13 -0
  31. data/app/controllers/decidim/participatory_processes/admin/concerns/participatory_process_admin.rb +26 -0
  32. data/app/controllers/decidim/participatory_processes/admin/exports_controller.rb +14 -0
  33. data/app/controllers/decidim/participatory_processes/admin/feature_permissions_controller.rb +14 -0
  34. data/app/controllers/decidim/participatory_processes/admin/features_controller.rb +14 -0
  35. data/app/controllers/decidim/participatory_processes/admin/moderations_controller.rb +12 -0
  36. data/app/controllers/decidim/participatory_processes/admin/participatory_process_attachments_controller.rb +27 -0
  37. data/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb +35 -0
  38. data/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb +90 -0
  39. data/app/controllers/decidim/participatory_processes/admin/participatory_process_publications_controller.rb +45 -0
  40. data/app/controllers/decidim/participatory_processes/admin/participatory_process_step_activations_controller.rb +39 -0
  41. data/app/controllers/decidim/participatory_processes/admin/participatory_process_step_ordering_controller.rb +29 -0
  42. data/app/controllers/decidim/participatory_processes/admin/participatory_process_steps_controller.rb +91 -0
  43. data/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb +99 -0
  44. data/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb +102 -0
  45. data/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb +28 -0
  46. data/app/controllers/decidim/participatory_processes/participatory_process_steps_controller.rb +20 -0
  47. data/app/controllers/decidim/participatory_processes/participatory_process_widgets_controller.rb +21 -0
  48. data/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb +64 -0
  49. data/app/forms/decidim/participatory_processes/admin/participatory_process_copy_form.rb +35 -0
  50. data/app/forms/decidim/participatory_processes/admin/participatory_process_form.rb +72 -0
  51. data/app/forms/decidim/participatory_processes/admin/participatory_process_group_form.rb +26 -0
  52. data/app/forms/decidim/participatory_processes/admin/participatory_process_step_form.rb +37 -0
  53. data/app/forms/decidim/participatory_processes/admin/participatory_process_user_role_form.rb +31 -0
  54. data/app/helpers/decidim/participatory_processes/admin/process_groups_for_select_helper.rb +23 -0
  55. data/app/helpers/decidim/participatory_processes/admin/processes_for_select_helper.rb +25 -0
  56. data/app/helpers/decidim/participatory_processes/participatory_process_helper.rb +19 -0
  57. data/app/helpers/decidim/participatory_processes/participatory_process_steps_helper.rb +20 -0
  58. data/app/models/decidim/participatory_process.rb +62 -0
  59. data/app/models/decidim/participatory_process_group.rb +15 -0
  60. data/app/models/decidim/participatory_process_step.rb +39 -0
  61. data/app/models/decidim/participatory_processes/abilities/admin/admin_ability.rb +21 -0
  62. data/app/models/decidim/participatory_processes/abilities/admin_ability.rb +16 -0
  63. data/app/models/decidim/participatory_processes/abilities/everyone_ability.rb +19 -0
  64. data/app/presenters/decidim/participatory_processes/participatory_process_stats_presenter.rb +52 -0
  65. data/app/queries/decidim/participatory_processes/admin/admin_users.rb +46 -0
  66. data/app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb +29 -0
  67. data/app/queries/decidim/participatory_processes/filtered_participatory_processes.rb +26 -0
  68. data/app/queries/decidim/participatory_processes/highlighted_participatory_processes.rb +12 -0
  69. data/app/queries/decidim/participatory_processes/organization_participatory_process_groups.rb +16 -0
  70. data/app/queries/decidim/participatory_processes/organization_participatory_processes.rb +16 -0
  71. data/app/queries/decidim/participatory_processes/organization_prioritized_participatory_process_groups.rb +20 -0
  72. data/app/queries/decidim/participatory_processes/organization_prioritized_participatory_processes.rb +22 -0
  73. data/app/queries/decidim/participatory_processes/organization_published_participatory_processes.rb +19 -0
  74. data/app/queries/decidim/participatory_processes/prioritized_participatory_processes.rb +13 -0
  75. data/app/queries/decidim/participatory_processes/promoted_participatory_processes.rb +12 -0
  76. data/app/queries/decidim/participatory_processes/published_participatory_processes.rb +12 -0
  77. data/app/views/decidim/participatory_process_groups/_participatory_process_group.html.erb +22 -0
  78. data/app/views/decidim/participatory_process_steps/_participatory_process_step.html.erb +16 -0
  79. data/app/views/decidim/participatory_processes/_order_by_processes.html.erb +12 -0
  80. data/app/views/decidim/participatory_processes/_participatory_process.html.erb +28 -0
  81. data/app/views/decidim/participatory_processes/admin/participatory_process_copies/_form.html.erb +38 -0
  82. data/app/views/decidim/participatory_processes/admin/participatory_process_copies/new.html.erb +7 -0
  83. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/_form.html.erb +17 -0
  84. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/edit.html.erb +19 -0
  85. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/index.html.erb +44 -0
  86. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/new.html.erb +13 -0
  87. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/show.html.erb +23 -0
  88. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/_form.html.erb +25 -0
  89. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/edit.html.erb +8 -0
  90. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/index.html.erb +63 -0
  91. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/new.html.erb +7 -0
  92. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/show.html.erb +18 -0
  93. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/_form.html.erb +22 -0
  94. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/edit.html.erb +7 -0
  95. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/index.html.erb +65 -0
  96. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/new.html.erb +7 -0
  97. data/app/views/decidim/participatory_processes/admin/participatory_processes/_form.html.erb +107 -0
  98. data/app/views/decidim/participatory_processes/admin/participatory_processes/edit.html.erb +19 -0
  99. data/app/views/decidim/participatory_processes/admin/participatory_processes/index.html.erb +66 -0
  100. data/app/views/decidim/participatory_processes/admin/participatory_processes/new.html.erb +11 -0
  101. data/app/views/decidim/participatory_processes/participatory_process_groups/show.html.erb +11 -0
  102. data/app/views/decidim/participatory_processes/participatory_process_steps/_timeline.html.erb +7 -0
  103. data/app/views/decidim/participatory_processes/participatory_process_steps/index.html.erb +14 -0
  104. data/app/views/decidim/participatory_processes/participatory_process_widgets/show.html.erb +17 -0
  105. data/app/views/decidim/participatory_processes/participatory_processes/_no_processes_yet.html.erb +3 -0
  106. data/app/views/decidim/participatory_processes/participatory_processes/_promoted_process.html.erb +32 -0
  107. data/app/views/decidim/participatory_processes/participatory_processes/_statistics.html.erb +10 -0
  108. data/app/views/decidim/participatory_processes/participatory_processes/index.html.erb +22 -0
  109. data/app/views/decidim/participatory_processes/participatory_processes/index.js.erb +6 -0
  110. data/app/views/decidim/participatory_processes/participatory_processes/show.html.erb +92 -0
  111. data/app/views/layouts/decidim/_process_header.html.erb +65 -0
  112. data/app/views/layouts/decidim/_process_header_steps.html.erb +27 -0
  113. data/app/views/layouts/decidim/admin/participatory_process.html.erb +64 -0
  114. data/app/views/layouts/decidim/admin/participatory_process_groups.html.erb +14 -0
  115. data/app/views/layouts/decidim/admin/participatory_processes.html.erb +14 -0
  116. data/app/views/layouts/decidim/participatory_process.html.erb +30 -0
  117. data/config/locales/ca.yml +281 -0
  118. data/config/locales/en.yml +281 -0
  119. data/config/locales/es.yml +281 -0
  120. data/config/locales/eu.yml +280 -0
  121. data/config/locales/fi.yml +280 -0
  122. data/config/locales/fr.yml +280 -0
  123. data/config/locales/it.yml +280 -0
  124. data/config/locales/nl.yml +280 -0
  125. data/config/locales/pl.yml +281 -0
  126. data/config/locales/uk.yml +282 -0
  127. data/db/migrate/20161005130108_add_participatory_processes.rb +19 -0
  128. data/db/migrate/20161010102356_translate_processes.rb +17 -0
  129. data/db/migrate/20161011125616_add_hero_image_to_processes.rb +7 -0
  130. data/db/migrate/20161011141033_add_banner_image_to_processes.rb +7 -0
  131. data/db/migrate/20161013134732_add_promoted_flag_to_processes.rb +7 -0
  132. data/db/migrate/20161017085822_add_participatory_process_steps.rb +18 -0
  133. data/db/migrate/20161019072016_add_active_flag_to_step.rb +13 -0
  134. data/db/migrate/20161020080756_add_position_to_steps.rb +9 -0
  135. data/db/migrate/20161025125300_add_published_at_to_processes.rb +7 -0
  136. data/db/migrate/20161107152228_remove_not_null_on_step_position.rb +7 -0
  137. data/db/migrate/20161110092735_add_index_for_process_slug_organization.rb +10 -0
  138. data/db/migrate/20161116115156_create_attachments.rb +18 -0
  139. data/db/migrate/20170116135237_loosen_step_requirements.rb +8 -0
  140. data/db/migrate/20170123134023_make_attachments_polymorphic.rb +20 -0
  141. data/db/migrate/20170125135937_rename_attachable_to_attached_to.rb +13 -0
  142. data/db/migrate/20170126151123_add_extra_info_to_processes.rb +10 -0
  143. data/db/migrate/20170206083118_rename_extra_info_on_processes.rb +14 -0
  144. data/db/migrate/20170220110740_remove_steps_short_description.rb +23 -0
  145. data/db/migrate/20170221094835_add_scopes_to_processes.rb +8 -0
  146. data/db/migrate/20170228142440_add_participatory_process_groups.rb +17 -0
  147. data/db/migrate/20170404132616_change_steps_end_and_start_date_to_date.rb +8 -0
  148. data/db/migrate/20170720120135_make_features_polymorphic.rb +27 -0
  149. data/db/migrate/20170725085104_add_show_statistics_to_participatory_processes.rb +7 -0
  150. data/db/migrate/20170804125402_attachment_description_nullable.rb +7 -0
  151. data/db/migrate/20170808080905_add_announcement_to_participatory_processes.rb +7 -0
  152. data/db/migrate/20170809084005_add_scopes_enabled_to_participatory_processes.rb +7 -0
  153. data/db/migrate/20170830081725_add_start_date_to_processes.rb +8 -0
  154. data/db/seeds/Exampledocument.pdf +0 -0
  155. data/db/seeds/city.jpeg +0 -0
  156. data/db/seeds/city2.jpeg +0 -0
  157. data/db/seeds/homepage_image.jpg +0 -0
  158. data/lib/decidim/participatory_processes.rb +12 -0
  159. data/lib/decidim/participatory_processes/admin.rb +10 -0
  160. data/lib/decidim/participatory_processes/admin_engine.rb +98 -0
  161. data/lib/decidim/participatory_processes/engine.rb +55 -0
  162. data/lib/decidim/participatory_processes/participatory_space.rb +118 -0
  163. data/lib/decidim/participatory_processes/test/factories.rb +97 -0
  164. metadata +266 -0
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when creating a new participatory
7
+ # process group in the system.
8
+ class CreateParticipatoryProcessGroup < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - A form object with the params.
12
+ def initialize(form)
13
+ @form = form
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid) if form.invalid?
24
+ group = create_participatory_process_group
25
+
26
+ if group.persisted?
27
+ broadcast(:ok, group)
28
+ else
29
+ form.errors.add(:hero_image, group.errors[:hero_image]) if group.errors.include? :hero_image
30
+ form.errors.add(:banner_image, group.errors[:banner_image]) if group.errors.include? :banner_image
31
+ broadcast(:invalid)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :form
38
+
39
+ def create_participatory_process_group
40
+ transaction do
41
+ ParticipatoryProcessGroup.create(
42
+ name: form.name,
43
+ description: form.description,
44
+ hero_image: form.hero_image,
45
+ participatory_processes: participatory_processes,
46
+ organization: form.current_organization
47
+ )
48
+ end
49
+ end
50
+
51
+ def participatory_processes
52
+ Decidim::ParticipatoryProcess.where(id: form.participatory_process_ids)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when creating a new participatory
7
+ # process in the system.
8
+ class CreateParticipatoryProcessStep < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - A form object with the params.
12
+ # participatory_process - The ParticipatoryProcess that will hold the
13
+ # step
14
+ def initialize(form, participatory_process)
15
+ @form = form
16
+ @participatory_process = participatory_process
17
+ end
18
+
19
+ # Executes the command. Broadcasts these events:
20
+ #
21
+ # - :ok when everything is valid.
22
+ # - :invalid if the form wasn't valid and we couldn't proceed.
23
+ #
24
+ # Returns nothing.
25
+ def call
26
+ return broadcast(:invalid) if form.invalid?
27
+
28
+ create_participatory_process_step
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :form
35
+
36
+ def create_participatory_process_step
37
+ ParticipatoryProcessStep.create!(
38
+ title: form.title,
39
+ description: form.description,
40
+ start_date: form.start_date,
41
+ end_date: form.end_date,
42
+ participatory_process: @participatory_process,
43
+ active: @participatory_process.steps.empty?
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that sets all steps in a participatory process as inactive
7
+ class DeactivateParticipatoryProcessStep < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # step - A ParticipatoryProcessStep that will be deactivated
11
+ def initialize(step)
12
+ @step = step
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the data wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if step.nil? || !step.active?
23
+
24
+ deactivate_active_steps
25
+ broadcast(:ok)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :step
31
+
32
+ def deactivate_active_steps
33
+ step.participatory_process.steps.where(active: true).update_all(active: false)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that sets all steps in a participatory process as inactive
7
+ class DestroyParticipatoryProcessStep < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # step - A ParticipatoryProcessStep that will be deactivated
11
+ def initialize(step)
12
+ @step = step
13
+ @participatory_process = step.participatory_process
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid.
19
+ # - :invalid if the data wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid, :active_step) if active_step?
24
+
25
+ @step.destroy!
26
+ reorder_steps
27
+ broadcast(:ok)
28
+ end
29
+
30
+ private
31
+
32
+ def active_step?
33
+ @participatory_process.steps.count > 1 && @step.active?
34
+ end
35
+
36
+ def reorder_steps
37
+ steps = @participatory_process.steps.reload
38
+
39
+ ReorderParticipatoryProcessSteps
40
+ .new(steps, steps.map(&:id))
41
+ .call
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that sets a participatory process as published.
7
+ class PublishParticipatoryProcess < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # process - A ParticipatoryProcess that will be published
11
+ def initialize(process)
12
+ @process = process
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the data wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if process.nil? || process.published?
23
+
24
+ process.publish!
25
+ broadcast(:ok)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :process
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that reorders the steps in a participatory process.
7
+ class ReorderParticipatoryProcessSteps < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # collection - an ActiveRecord::Relation of steps
11
+ # order - an Array holding the order of IDs of steps
12
+ def initialize(collection, order)
13
+ @collection = collection
14
+ @order = order
15
+ end
16
+
17
+ # Executes the command. Broadcasts these events:
18
+ #
19
+ # - :ok when everything is valid.
20
+ # - :invalid if the data wasn't valid and we couldn't proceed.
21
+ #
22
+ # Returns nothing.
23
+ def call
24
+ return broadcast(:invalid) unless order.present?
25
+
26
+ reorder_steps
27
+ broadcast(:ok)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :collection
33
+
34
+ def reorder_steps
35
+ data = order.each_with_index.inject({}) do |hash, (id, index)|
36
+ hash.update(id => { position: index })
37
+ end
38
+
39
+ ParticipatoryProcessStep.transaction do
40
+ collection.update_all(position: nil)
41
+ collection.reload
42
+ collection.update(data.keys, data.values)
43
+ end
44
+ end
45
+
46
+ def order
47
+ return nil unless @order.is_a?(Array) && @order.present?
48
+
49
+ @order
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that sets a participatory process as unpublished.
7
+ class UnpublishParticipatoryProcess < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # process - A ParticipatoryProcess that will be unpublished
11
+ def initialize(process)
12
+ @process = process
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the data wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if process.nil? || !process.published?
23
+
24
+ process.unpublish!
25
+ broadcast(:ok)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :process
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when creating a new participatory
7
+ # process in the system.
8
+ class UpdateParticipatoryProcess < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # participatory_process - the ParticipatoryProcess to update
12
+ # form - A form object with the params.
13
+ def initialize(participatory_process, form)
14
+ @participatory_process = participatory_process
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 wasn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if form.invalid?
26
+ update_participatory_process
27
+
28
+ if @participatory_process.valid?
29
+ broadcast(:ok, @participatory_process)
30
+ else
31
+ form.errors.add(:hero_image, @participatory_process.errors[:hero_image]) if @participatory_process.errors.include? :hero_image
32
+ form.errors.add(:banner_image, @participatory_process.errors[:banner_image]) if @participatory_process.errors.include? :banner_image
33
+ broadcast(:invalid)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :form, :participatory_process
40
+
41
+ def update_participatory_process
42
+ @participatory_process.assign_attributes(attributes)
43
+ @participatory_process.save! if @participatory_process.valid?
44
+ end
45
+
46
+ def attributes
47
+ {
48
+ title: form.title,
49
+ subtitle: form.subtitle,
50
+ slug: form.slug,
51
+ hashtag: form.hashtag,
52
+ hero_image: form.hero_image,
53
+ remove_hero_image: form.remove_hero_image,
54
+ banner_image: form.banner_image,
55
+ remove_banner_image: form.remove_banner_image,
56
+ promoted: form.promoted,
57
+ description: form.description,
58
+ short_description: form.short_description,
59
+ scopes_enabled: form.scopes_enabled,
60
+ scope: form.scope,
61
+ developer_group: form.developer_group,
62
+ local_area: form.local_area,
63
+ target: form.target,
64
+ participatory_scope: form.participatory_scope,
65
+ participatory_structure: form.participatory_structure,
66
+ meta_scope: form.meta_scope,
67
+ start_date: form.start_date,
68
+ end_date: form.end_date,
69
+ participatory_process_group: form.participatory_process_group,
70
+ show_statistics: form.show_statistics,
71
+ announcement: form.announcement
72
+ }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when updated a participatory
7
+ # process admin in the system.
8
+ class UpdateParticipatoryProcessAdmin < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - A form object with the params.
12
+ # participatory_process - The ParticipatoryProcess that will hold the
13
+ # user role
14
+ def initialize(form, user_role)
15
+ @form = form
16
+ @user_role = user_role
17
+ end
18
+
19
+ # Executes the command. Broadcasts these events:
20
+ #
21
+ # - :ok when everything is valid.
22
+ # - :invalid if the form wasn't valid and we couldn't proceed.
23
+ #
24
+ # Returns nothing.
25
+ def call
26
+ return broadcast(:invalid) if form.invalid?
27
+ return broadcast(:invalid) unless user_role
28
+
29
+ update_role!
30
+ broadcast(:ok)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :form, :user_role
36
+
37
+ def update_role!
38
+ user_role.update_attributes!(role: form.role)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when creating a new participatory
7
+ # process group in the system.
8
+ class UpdateParticipatoryProcessGroup < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # participatory_process_group - the ParticipatoryProcessGroup to update
12
+ # form - A form object with the params.
13
+ def initialize(participatory_process_group, form)
14
+ @participatory_process_group = participatory_process_group
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 wasn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if form.invalid?
26
+ update_participatory_process_group
27
+
28
+ if @participatory_process_group.valid?
29
+ broadcast(:ok, @participatory_process_group)
30
+ else
31
+ form.errors.add(:hero_image, @participatory_process_group.errors[:hero_image]) if @participatory_process_group.errors.include? :hero_image
32
+ broadcast(:invalid)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :form
39
+
40
+ def update_participatory_process_group
41
+ @participatory_process_group.assign_attributes(attributes)
42
+ @participatory_process_group.save! if @participatory_process_group.valid?
43
+ end
44
+
45
+ def attributes
46
+ {
47
+ name: form.name,
48
+ hero_image: form.hero_image,
49
+ description: form.description,
50
+ participatory_processes: participatory_processes
51
+ }
52
+ end
53
+
54
+ def participatory_processes
55
+ Decidim::ParticipatoryProcess.where(id: form.participatory_process_ids)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end