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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ed5778305ec15d3856385d206b64cb0ddf00d48
4
+ data.tar.gz: 84b18b608fff22066df3d690ee87e0635e85d46d
5
+ SHA512:
6
+ metadata.gz: 043f3e5ad638d4340701af8047f7fd2fd89e1183b3ccda119c3e41a37a921fd047beadf089640c9546e9118d94c336d4fe44ac1e16f202f9dc393c1dabdb3737
7
+ data.tar.gz: c0ab2b56c3515fefa73af22f4ba57ca82624307a7b4b972198061c6541f84ad836dff98bb231903220b8735f15aec2c5a18f8e44b5ed180a326baa6deeaccf84
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Decidim::ParticipatoryProcesses
2
+
3
+ Participatory processes are the standard Decidim's participatory space.
4
+
5
+ A participatory process can define its own steps, and attach different features
6
+ (such as meetings or proposals) with different configurations to each of them.
7
+
8
+ A participatory process can have attachments, be associated to custom
9
+ categories, and are fully manageable via an administration UI.
10
+
11
+ ## Usage
12
+
13
+ This plugin provides:
14
+
15
+ * A CRUD engine to manage participatory processes.
16
+
17
+ * Public views for participatory process via a high level section in the main
18
+ menu.
19
+
20
+ ## Installation
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'decidim-participatory_processes'
25
+ ```
26
+
27
+ And then execute:
28
+ ```bash
29
+ $ bundle
30
+ ```
31
+
32
+ ## Contributing
33
+ See [Decidim](https://github.com/decidim/decidim).
34
+
35
+ ## License
36
+ See [Decidim](https://github.com/decidim/decidim).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/dev/common_rake"
@@ -0,0 +1 @@
1
+ //= link decidim/participatory_processes/admin/participatory_processes.js
@@ -0,0 +1,2 @@
1
+ //= link_directory ../images/decidim/participatory_processes
2
+ //= link decidim/participatory_processes/filters.js
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36.02 36.02">
2
+ <path d="M883.8,543.84a18,18,0,1,1,18-18A18,18,0,0,1,883.8,543.84Zm0-34a16,16,0,1,0,16,16A16,16,0,0,0,883.8,509.83Z" transform="translate(-865.8 -507.83)"/>
3
+ <g transform="rotate(60 18.1 18.1)">
4
+ <path d="M883.8,528.75a2.91,2.91,0,1,1,2.91-2.91A2.92,2.92,0,0,1,883.8,528.75Zm0-3.83a0.91,0.91,0,1,0,.91.92A0.92,0.92,0,0,0,883.8,524.92Z" transform="translate(-865.8 -507.83)"/>
5
+ <path d="M883.8,521.18a2.91,2.91,0,1,1,2.91-2.91A2.92,2.92,0,0,1,883.8,521.18Zm0-3.83a0.91,0.91,0,1,0,.91.92A0.92,0.92,0,0,0,883.8,517.35Z" transform="translate(-865.8 -507.83)"/>
6
+ <path d="M883.8,536.32a2.92,2.92,0,1,1,2.91-2.91A2.92,2.92,0,0,1,883.8,536.32Zm0-3.83a0.92,0.92,0,1,0,.91.92A0.92,0.92,0,0,0,883.8,532.49Z" transform="translate(-865.8 -507.83)"/>
7
+ <path d="M881.52,526.85a4.79,4.79,0,1,1,0-9.59,1,1,0,0,1,0,2,2.79,2.79,0,1,0,0,5.59A1,1,0,0,1,881.52,526.85Z" transform="translate(-865.8 -507.83)"/>
8
+ <path d="M886.09,534.47a1,1,0,0,1,0-2,2.79,2.79,0,0,0,0-5.59,1,1,0,0,1,0-2A4.79,4.79,0,0,1,886.09,534.47Z" transform="translate(-865.8 -507.83)"/>
9
+ </g>
10
+ </svg>
@@ -0,0 +1,12 @@
1
+ $(() => {
2
+ const $participatoryProcessScopeEnabled = $('#participatory_process_scopes_enabled');
3
+ const $participatoryProcessScopeId = $("#participatory_process_scope_id");
4
+
5
+ if ($('.edit_participatory_process, .new_participatory_process').length > 0) {
6
+ $participatoryProcessScopeEnabled.on('change', (event) => {
7
+ const checked = event.target.checked;
8
+ $participatoryProcessScopeId.attr("disabled", !checked);
9
+ })
10
+ $participatoryProcessScopeId.attr("disabled", !$participatoryProcessScopeEnabled.prop('checked'));
11
+ }
12
+ });
@@ -0,0 +1,25 @@
1
+ $(() => {
2
+ ((exports) => {
3
+ const $processesGrid = $('#processes-grid');
4
+ const $loading = $processesGrid.find('.loading');
5
+ const filterLinksSelector = '.order-by__tabs a'
6
+
7
+ $loading.hide();
8
+
9
+ $processesGrid.on('click', filterLinksSelector, (event) => {
10
+ const $target = $(event.target);
11
+ const $processesGridCards = $processesGrid.find('.card-grid .column');
12
+
13
+ $(filterLinksSelector).removeClass('is-active');
14
+ $target.addClass('is-active');
15
+
16
+ $processesGridCards.hide();
17
+ $loading.show();
18
+
19
+ if (exports.history) {
20
+ exports.history.pushState(null, null, $target.attr('href'));
21
+ }
22
+ });
23
+ })(window);
24
+
25
+ });
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command that sets a step in a participatory process as active (and
7
+ # unsets a previous active step)
8
+ class ActivateParticipatoryProcessStep < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # step - A ParticipatoryProcessStep that will be activated
12
+ def initialize(step)
13
+ @step = step
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) if step.nil? || step.active?
24
+
25
+ Decidim::ParticipatoryProcessStep.transaction do
26
+ deactivate_active_steps
27
+ activate_step
28
+ end
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :step
35
+
36
+ def deactivate_active_steps
37
+ step.participatory_process.steps.where(active: true).update_all(active: false)
38
+ end
39
+
40
+ def activate_step
41
+ step.update_attribute(:active, true)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A command with all the business logic when copying a new participatory
7
+ # process in the system.
8
+ class CopyParticipatoryProcess < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - A form object with the params.
12
+ # participatory_process - A participatory_process we want to duplicate
13
+ def initialize(form, participatory_process)
14
+ @form = form
15
+ @participatory_process = participatory_process
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
+
27
+ ParticipatoryProcess.transaction do
28
+ copy_participatory_process
29
+ copy_participatory_process_steps if @form.copy_steps?
30
+ copy_participatory_process_categories if @form.copy_categories?
31
+ copy_participatory_process_features if @form.copy_features?
32
+ end
33
+
34
+ broadcast(:ok, @copied_process)
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :form
40
+
41
+ def copy_participatory_process
42
+ @copied_process = ParticipatoryProcess.create!(
43
+ organization: @participatory_process.organization,
44
+ title: form.title,
45
+ subtitle: @participatory_process.subtitle,
46
+ slug: form.slug,
47
+ hashtag: @participatory_process.hashtag,
48
+ description: @participatory_process.description,
49
+ short_description: @participatory_process.short_description,
50
+ hero_image: @participatory_process.hero_image,
51
+ banner_image: @participatory_process.banner_image,
52
+ promoted: @participatory_process.promoted,
53
+ scope: @participatory_process.scope,
54
+ developer_group: @participatory_process.developer_group,
55
+ local_area: @participatory_process.local_area,
56
+ target: @participatory_process.target,
57
+ participatory_scope: @participatory_process.participatory_scope,
58
+ participatory_structure: @participatory_process.participatory_structure,
59
+ meta_scope: @participatory_process.meta_scope,
60
+ start_date: @participatory_process.start_date,
61
+ end_date: @participatory_process.end_date,
62
+ participatory_process_group: @participatory_process.participatory_process_group
63
+ )
64
+ end
65
+
66
+ def copy_participatory_process_steps
67
+ @steps_relationship = {}
68
+
69
+ @participatory_process.steps.each do |step|
70
+ new_step = ParticipatoryProcessStep.create!(
71
+ title: step.title,
72
+ description: step.description,
73
+ start_date: step.start_date,
74
+ end_date: step.end_date,
75
+ participatory_process: @copied_process,
76
+ position: step.position,
77
+ active: step.active
78
+ )
79
+ @steps_relationship[step.id.to_s] = new_step.id.to_s
80
+ end
81
+ end
82
+
83
+ def copy_participatory_process_categories
84
+ @participatory_process.categories.each do |category|
85
+ Category.create!(
86
+ name: category.name,
87
+ description: category.description,
88
+ parent_id: category.parent_id,
89
+ participatory_space: @copied_process
90
+ )
91
+ end
92
+ end
93
+
94
+ def copy_participatory_process_features
95
+ @participatory_process.features.each do |feature|
96
+ copied_step_settings = @form.copy_steps? ? map_step_settings(feature.step_settings) : {}
97
+ new_feature = Feature.create!(
98
+ manifest_name: feature.manifest_name,
99
+ name: feature.name,
100
+ participatory_space: @copied_process,
101
+ settings: feature.settings,
102
+ step_settings: copied_step_settings
103
+ )
104
+ feature.manifest.run_hooks(:copy, new_feature: new_feature, old_feature: feature)
105
+ end
106
+ end
107
+
108
+ def map_step_settings(step_settings)
109
+ step_settings.each_with_object({}) do |(step_id, settings), acc|
110
+ acc.update(@steps_relationship[step_id.to_s] => settings)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,82 @@
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 CreateParticipatoryProcess < 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
+ process = create_participatory_process
25
+
26
+ if process.persisted?
27
+ broadcast(:ok, process)
28
+ else
29
+ form.errors.add(:hero_image, process.errors[:hero_image]) if process.errors.include? :hero_image
30
+ form.errors.add(:banner_image, process.errors[:banner_image]) if process.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
40
+ process = ParticipatoryProcess.new(
41
+ organization: form.current_organization,
42
+ title: form.title,
43
+ subtitle: form.subtitle,
44
+ slug: form.slug,
45
+ hashtag: form.hashtag,
46
+ description: form.description,
47
+ short_description: form.short_description,
48
+ hero_image: form.hero_image,
49
+ banner_image: form.banner_image,
50
+ promoted: form.promoted,
51
+ scopes_enabled: form.scopes_enabled,
52
+ scope: form.scope,
53
+ developer_group: form.developer_group,
54
+ local_area: form.local_area,
55
+ target: form.target,
56
+ participatory_scope: form.participatory_scope,
57
+ participatory_structure: form.participatory_structure,
58
+ meta_scope: form.meta_scope,
59
+ start_date: form.start_date,
60
+ end_date: form.end_date,
61
+ participatory_process_group: form.participatory_process_group
62
+ )
63
+
64
+ return process unless process.valid?
65
+ transaction do
66
+ process.save!
67
+
68
+ process.steps.create!(
69
+ title: TranslationsHelper.multi_translation(
70
+ "decidim.admin.participatory_process_steps.default_title",
71
+ form.current_organization.available_locales
72
+ ),
73
+ active: true
74
+ )
75
+
76
+ process
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,95 @@
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 admin in the system.
8
+ class CreateParticipatoryProcessAdmin < 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, current_user, participatory_process)
15
+ @form = form
16
+ @current_user = current_user
17
+ @participatory_process = participatory_process
18
+ end
19
+
20
+ # Executes the command. Broadcasts these events:
21
+ #
22
+ # - :ok when everything is valid.
23
+ # - :invalid if the form wasn't valid and we couldn't proceed.
24
+ #
25
+ # Returns nothing.
26
+ def call
27
+ return broadcast(:invalid) if form.invalid?
28
+
29
+ ActiveRecord::Base.transaction do
30
+ create_or_invite_user
31
+ create_role
32
+ end
33
+
34
+ broadcast(:ok)
35
+ rescue ActiveRecord::RecordInvalid
36
+ form.errors.add(:email, :taken)
37
+ broadcast(:invalid)
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :form, :participatory_process, :current_user, :user
43
+
44
+ def create_role
45
+ Decidim::ParticipatoryProcessUserRole.find_or_create_by!(
46
+ role: form.role.to_sym,
47
+ user: user,
48
+ participatory_process: @participatory_process
49
+ )
50
+ end
51
+
52
+ def create_or_invite_user
53
+ @user ||= existing_user || new_user
54
+ end
55
+
56
+ def existing_user
57
+ return @existing_user if defined?(@existing_user)
58
+
59
+ @existing_user = User.where(
60
+ email: form.email,
61
+ organization: participatory_process.organization
62
+ ).first
63
+
64
+ if @existing_user && !@existing_user.invitation_accepted?
65
+ InviteUserAgain.call(@existing_user, invitation_instructions)
66
+ end
67
+
68
+ @existing_user
69
+ end
70
+
71
+ def new_user
72
+ @new_user ||= InviteUser.call(user_form) do
73
+ on(:ok) do |user|
74
+ return user
75
+ end
76
+ end
77
+ end
78
+
79
+ def user_form
80
+ OpenStruct.new(name: form.name,
81
+ email: form.email.downcase,
82
+ organization: participatory_process.organization,
83
+ admin: false,
84
+ invited_by: current_user,
85
+ invitation_instructions: invitation_instructions)
86
+ end
87
+
88
+ def invitation_instructions
89
+ return "invite_admin" if form.role == "admin"
90
+ "invite_collaborator"
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end