decidim-admin 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 (244) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/cells/decidim/admin/content_block_cell.rb +0 -1
  4. data/app/cells/decidim/admin/results_per_page/show.erb +2 -2
  5. data/app/cells/decidim/admin/results_per_page_cell.rb +0 -2
  6. data/app/commands/decidim/admin/block_user.rb +0 -1
  7. data/app/commands/decidim/admin/create_area.rb +4 -32
  8. data/app/commands/decidim/admin/create_area_type.rb +4 -33
  9. data/app/commands/decidim/admin/create_attachment.rb +5 -4
  10. data/app/commands/decidim/admin/create_attachment_collection.rb +3 -3
  11. data/app/commands/decidim/admin/create_category.rb +4 -37
  12. data/app/commands/decidim/admin/create_component.rb +7 -40
  13. data/app/commands/decidim/admin/create_newsletter.rb +11 -29
  14. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +4 -4
  15. data/app/commands/decidim/admin/create_scope.rb +15 -32
  16. data/app/commands/decidim/admin/create_scope_type.rb +3 -32
  17. data/app/commands/decidim/admin/create_static_page.rb +6 -47
  18. data/app/commands/decidim/admin/create_static_page_topic.rb +4 -26
  19. data/app/commands/decidim/admin/deliver_newsletter.rb +4 -5
  20. data/app/commands/decidim/admin/destroy_area.rb +2 -25
  21. data/app/commands/decidim/admin/destroy_category.rb +4 -29
  22. data/app/commands/decidim/admin/destroy_component.rb +5 -43
  23. data/app/commands/decidim/admin/destroy_newsletter.rb +2 -30
  24. data/app/commands/decidim/admin/destroy_participatory_space_private_user.rb +5 -32
  25. data/app/commands/decidim/admin/destroy_scope.rb +6 -33
  26. data/app/commands/decidim/admin/officialize_user.rb +1 -1
  27. data/app/commands/decidim/admin/participatory_space/create_admin.rb +4 -4
  28. data/app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb +5 -4
  29. data/app/commands/decidim/admin/promote_managed_user.rb +4 -5
  30. data/app/commands/decidim/admin/unofficialize_user.rb +1 -1
  31. data/app/commands/decidim/admin/update_area.rb +2 -41
  32. data/app/commands/decidim/admin/update_area_type.rb +2 -42
  33. data/app/commands/decidim/admin/update_attachment.rb +10 -7
  34. data/app/commands/decidim/admin/update_attachment_collection.rb +3 -3
  35. data/app/commands/decidim/admin/update_category.rb +2 -45
  36. data/app/commands/decidim/admin/update_component.rb +4 -5
  37. data/app/commands/decidim/admin/update_component_permissions.rb +3 -3
  38. data/app/commands/decidim/admin/{update_external_domain_whitelist.rb → update_external_domain_allowlist.rb} +6 -5
  39. data/app/commands/decidim/admin/update_help_sections.rb +6 -3
  40. data/app/commands/decidim/admin/update_newsletter.rb +8 -8
  41. data/app/commands/decidim/admin/update_organization.rb +9 -53
  42. data/app/commands/decidim/admin/update_organization_appearance.rb +10 -81
  43. data/app/commands/decidim/admin/update_scope.rb +7 -40
  44. data/app/commands/decidim/admin/update_scope_type.rb +2 -42
  45. data/app/commands/decidim/admin/update_static_page.rb +5 -46
  46. data/app/commands/decidim/admin/update_static_page_topic.rb +2 -43
  47. data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
  48. data/app/controllers/concerns/decidim/admin/content_blocks/landing_page.rb +2 -2
  49. data/app/controllers/concerns/decidim/admin/filterable.rb +79 -4
  50. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +1 -1
  51. data/app/controllers/concerns/decidim/admin/needs_admin_tos_accepted.rb +0 -7
  52. data/app/controllers/concerns/decidim/admin/paginable.rb +20 -0
  53. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +1 -1
  54. data/app/controllers/decidim/admin/application_controller.rb +2 -1
  55. data/app/controllers/decidim/admin/area_types_controller.rb +8 -9
  56. data/app/controllers/decidim/admin/areas_controller.rb +1 -1
  57. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +1 -1
  58. data/app/controllers/decidim/admin/block_user_controller.rb +1 -1
  59. data/app/controllers/decidim/admin/categories_controller.rb +2 -2
  60. data/app/controllers/decidim/admin/component_permissions_controller.rb +1 -1
  61. data/app/controllers/decidim/admin/components_controller.rb +2 -2
  62. data/app/controllers/decidim/admin/concerns/has_attachment_collections.rb +2 -2
  63. data/app/controllers/decidim/admin/concerns/has_attachments.rb +2 -2
  64. data/app/controllers/decidim/admin/concerns/has_private_users.rb +1 -1
  65. data/app/controllers/decidim/admin/concerns/has_private_users_csv_import.rb +1 -1
  66. data/app/controllers/decidim/admin/conflicts_controller.rb +6 -14
  67. data/app/controllers/decidim/admin/help_sections_controller.rb +1 -1
  68. data/app/controllers/decidim/admin/impersonations_controller.rb +0 -1
  69. data/app/controllers/decidim/admin/managed_users/promotions_controller.rb +1 -1
  70. data/app/controllers/decidim/admin/moderations/reports_controller.rb +4 -4
  71. data/app/controllers/decidim/admin/moderations_controller.rb +7 -7
  72. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +1 -1
  73. data/app/controllers/decidim/admin/newsletters_controller.rb +6 -7
  74. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -1
  75. data/app/controllers/decidim/admin/organization_controller.rb +1 -1
  76. data/app/controllers/decidim/admin/{organization_external_domain_whitelist_controller.rb → organization_external_domain_allowlist_controller.rb} +7 -7
  77. data/app/controllers/decidim/admin/scope_types_controller.rb +7 -8
  78. data/app/controllers/decidim/admin/scopes_controller.rb +1 -1
  79. data/app/controllers/decidim/admin/share_tokens_controller.rb +1 -1
  80. data/app/controllers/decidim/admin/static_page_topics_controller.rb +2 -2
  81. data/app/controllers/decidim/admin/static_pages_controller.rb +2 -2
  82. data/app/forms/decidim/admin/attachment_form.rb +7 -1
  83. data/app/forms/decidim/admin/help_section_form.rb +1 -1
  84. data/app/forms/decidim/admin/impersonate_user_form.rb +0 -5
  85. data/app/forms/decidim/admin/organization_appearance_form.rb +2 -5
  86. data/app/forms/decidim/admin/{organization_external_domain_whitelist_form.rb → organization_external_domain_allowlist_form.rb} +3 -3
  87. data/app/forms/decidim/admin/organization_form.rb +4 -4
  88. data/app/forms/decidim/admin/static_page_form.rb +1 -2
  89. data/app/forms/decidim/admin/transfer_user_form.rb +0 -15
  90. data/app/helpers/decidim/admin/application_helper.rb +0 -13
  91. data/app/helpers/decidim/admin/filterable_helper.rb +19 -3
  92. data/app/helpers/decidim/admin/moderations/reports_helper.rb +3 -1
  93. data/app/helpers/decidim/admin/newsletters_helper.rb +3 -3
  94. data/app/helpers/decidim/admin/paginable/per_page_helper.rb +22 -0
  95. data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +2 -2
  96. data/app/packs/entrypoints/decidim_admin.js +4 -1
  97. data/app/packs/src/decidim/admin/application.js +19 -15
  98. data/app/packs/src/decidim/admin/css_preview.js +39 -0
  99. data/app/packs/src/decidim/admin/form.js +18 -1
  100. data/app/packs/src/decidim/admin/newsletters.js +9 -18
  101. data/app/packs/src/decidim/admin/participatory_space_search.js +1 -1
  102. data/app/packs/src/decidim/admin/proposal_infinite_edit.js +2 -2
  103. data/app/packs/src/decidim/admin/sync_radio_buttons.js +27 -0
  104. data/app/packs/src/decidim/admin/text_copy.js +19 -0
  105. data/app/packs/stylesheets/decidim/admin/_cards.scss +1 -1
  106. data/app/packs/stylesheets/decidim/admin/_datepicker.scss +62 -0
  107. data/app/packs/stylesheets/decidim/admin/_item_edit.scss +1 -1
  108. data/app/packs/stylesheets/decidim/admin/_item_show.scss +8 -0
  109. data/app/packs/stylesheets/decidim/admin/_moderations.scss +0 -8
  110. data/app/packs/stylesheets/decidim/admin/_proposal_status.scss +5 -0
  111. data/app/packs/stylesheets/decidim/admin/application.scss +2 -0
  112. data/app/permissions/decidim/admin/permissions.rb +2 -2
  113. data/app/queries/decidim/admin/newsletter_recipients.rb +5 -9
  114. data/app/queries/decidim/admin/user_filter.rb +4 -4
  115. data/app/queries/decidim/admin/user_groups_evaluation.rb +1 -1
  116. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  117. data/app/views/decidim/admin/attachments/_form.html.erb +21 -2
  118. data/app/views/decidim/admin/attachments/index.html.erb +2 -2
  119. data/app/views/decidim/admin/authorization_workflows/index.html.erb +26 -8
  120. data/app/views/decidim/admin/block_user/new.html.erb +1 -1
  121. data/app/views/decidim/admin/categories/index.html.erb +2 -2
  122. data/app/views/decidim/admin/components/_form.html.erb +1 -1
  123. data/app/views/decidim/admin/components/index.html.erb +1 -5
  124. data/app/views/decidim/admin/conflicts/edit.html.erb +11 -21
  125. data/app/views/decidim/admin/conflicts/index.html.erb +6 -29
  126. data/app/views/decidim/admin/dashboard/_pending_moderations.html.erb +1 -1
  127. data/app/views/decidim/admin/dashboard/show.html.erb +1 -1
  128. data/app/views/decidim/admin/exports/_dropdown.html.erb +6 -6
  129. data/app/views/decidim/admin/impersonatable_users/index.html.erb +3 -3
  130. data/app/views/decidim/admin/imports/_dropdown.html.erb +5 -7
  131. data/app/views/decidim/admin/imports/new.html.erb +6 -7
  132. data/app/views/decidim/admin/logs/_filters.html.erb +3 -3
  133. data/app/views/decidim/admin/managed_users/promotions/new.html.erb +1 -1
  134. data/app/views/decidim/admin/moderated_users/index.html.erb +4 -4
  135. data/app/views/decidim/admin/moderations/index.html.erb +5 -5
  136. data/app/views/decidim/admin/moderations/reports/index.html.erb +6 -6
  137. data/app/views/decidim/admin/moderations/reports/show.html.erb +4 -4
  138. data/app/views/decidim/admin/newsletter_templates/index.html.erb +3 -2
  139. data/app/views/decidim/admin/newsletter_templates/show.html.erb +7 -7
  140. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  141. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +6 -7
  142. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  143. data/app/views/decidim/admin/organization/_form.html.erb +3 -3
  144. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +0 -3
  145. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +5 -5
  146. data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +3 -3
  147. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_external_domain.html.erb +4 -4
  148. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_form.html.erb +2 -2
  149. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/edit.html.erb +2 -2
  150. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  151. data/app/views/decidim/admin/participatory_space_private_users_csv_imports/new.html.erb +1 -1
  152. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +1 -1
  153. data/app/views/decidim/admin/shared/_adjacent_navigation.html.erb +30 -0
  154. data/app/views/decidim/admin/shared/_admin_confirm_modal.html.erb +7 -7
  155. data/app/views/decidim/admin/shared/_filters.html.erb +1 -1
  156. data/app/views/decidim/admin/shared/_gallery.html.erb +1 -1
  157. data/app/views/decidim/admin/shared/landing_page/_content_blocks.html.erb +2 -2
  158. data/app/views/decidim/admin/shared/landing_page_content_blocks/edit.html.erb +1 -1
  159. data/app/views/decidim/admin/static_page_topics/index.html.erb +1 -1
  160. data/app/views/decidim/admin/static_pages/_form.html.erb +0 -4
  161. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +2 -2
  162. data/app/views/layouts/decidim/admin/_admin_timeout_modal.html.erb +2 -2
  163. data/app/views/layouts/decidim/admin/_application.html.erb +4 -4
  164. data/app/views/layouts/decidim/admin/_callouts_full.html.erb +1 -1
  165. data/app/views/layouts/decidim/admin/_js_configuration.html.erb +3 -1
  166. data/app/views/layouts/decidim/admin/_title_bar.html.erb +2 -2
  167. data/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb +2 -2
  168. data/config/locales/ar.yml +1 -54
  169. data/config/locales/bg.yml +15 -12
  170. data/config/locales/ca.yml +18 -15
  171. data/config/locales/cs.yml +15 -17
  172. data/config/locales/de.yml +18 -15
  173. data/config/locales/el.yml +0 -11
  174. data/config/locales/en.yml +15 -12
  175. data/config/locales/es-MX.yml +17 -14
  176. data/config/locales/es-PY.yml +17 -14
  177. data/config/locales/es.yml +19 -16
  178. data/config/locales/eu.yml +145 -154
  179. data/config/locales/fi-plain.yml +18 -15
  180. data/config/locales/fi.yml +39 -36
  181. data/config/locales/fr-CA.yml +15 -12
  182. data/config/locales/fr.yml +13 -10
  183. data/config/locales/ga-IE.yml +0 -3
  184. data/config/locales/gl.yml +2 -6
  185. data/config/locales/hu.yml +9 -10
  186. data/config/locales/id-ID.yml +0 -7
  187. data/config/locales/is-IS.yml +0 -15
  188. data/config/locales/it.yml +3 -10
  189. data/config/locales/ja.yml +20 -17
  190. data/config/locales/kaa.yml +3 -3
  191. data/config/locales/ko.yml +1 -6
  192. data/config/locales/lb.yml +4 -11
  193. data/config/locales/lt.yml +0 -12
  194. data/config/locales/lv.yml +2 -6
  195. data/config/locales/nl.yml +1 -8
  196. data/config/locales/no.yml +1 -8
  197. data/config/locales/pl.yml +15 -10
  198. data/config/locales/pt-BR.yml +8 -12
  199. data/config/locales/pt.yml +0 -11
  200. data/config/locales/ro-RO.yml +5 -22
  201. data/config/locales/ru.yml +1 -6
  202. data/config/locales/sk.yml +2 -6
  203. data/config/locales/sl.yml +2 -0
  204. data/config/locales/sq-AL.yml +3 -3
  205. data/config/locales/sr-CS.yml +3 -6
  206. data/config/locales/sv.yml +209 -357
  207. data/config/locales/th-TH.yml +0 -13
  208. data/config/locales/tr-TR.yml +2 -6
  209. data/config/locales/uk.yml +0 -6
  210. data/config/locales/zh-CN.yml +6 -3
  211. data/config/locales/zh-TW.yml +0 -11
  212. data/config/routes.rb +2 -2
  213. data/decidim-admin.gemspec +2 -2
  214. data/lib/decidim/admin/engine.rb +0 -1
  215. data/lib/decidim/admin/import/creator.rb +1 -1
  216. data/lib/decidim/admin/import/importer_factory.rb +2 -2
  217. data/lib/decidim/admin/menu.rb +4 -4
  218. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +3 -2
  219. data/lib/decidim/admin/test/commands/create_category_examples.rb +4 -2
  220. data/lib/decidim/admin/test/commands/update_attachment_collection_examples.rb +3 -2
  221. data/lib/decidim/admin/test/commands/update_category_examples.rb +3 -2
  222. data/lib/decidim/admin/test/filterable_examples.rb +5 -3
  223. data/lib/decidim/admin/test/filters_participatory_space_user_roles_examples.rb +5 -5
  224. data/lib/decidim/admin/test/invite_participatory_space_admins_shared_examples.rb +1 -1
  225. data/lib/decidim/admin/test/invite_participatory_space_users_shared_context.rb +0 -1
  226. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +12 -12
  227. data/lib/decidim/admin/test/manage_attachments_examples.rb +52 -28
  228. data/lib/decidim/admin/test/manage_categories_examples.rb +13 -13
  229. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +5 -5
  230. data/lib/decidim/admin/test/manage_hide_content_examples.rb +4 -4
  231. data/lib/decidim/admin/test/manage_moderations_examples.rb +21 -21
  232. data/lib/decidim/admin/test/manage_paginated_collection_examples.rb +5 -5
  233. data/lib/decidim/admin/test/manage_participatory_space_publications_examples.rb +2 -2
  234. data/lib/decidim/admin/version.rb +1 -1
  235. data/lib/decidim/admin.rb +15 -0
  236. metadata +28 -27
  237. data/app/commands/decidim/admin/destroy_share_token.rb +0 -46
  238. data/app/commands/decidim/admin/destroy_static_page.rb +0 -40
  239. data/app/commands/decidim/admin/destroy_static_page_topic.rb +0 -40
  240. data/app/controllers/concerns/decidim/admin/verification_conflicts/filterable.rb +0 -31
  241. data/app/views/layouts/decidim/admin/login.html.erb +0 -19
  242. data/config/locales/bn-BD.yml +0 -1
  243. data/config/locales/bs-BA.yml +0 -528
  244. /data/app/packs/src/decidim/admin/{external_domain_whitelist.js → external_domain_allowlist.js} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9771d30ebd9a776647bbf2a1e0b1e53094472ecdca1dd880239409d94dc82abb
4
- data.tar.gz: da4b0ee762d4beac83d9c68dd69a2ebecef34ad0a21b04292f43ab5808b95bb8
3
+ metadata.gz: f2203fd3c924ab306246e912329cdaac02091b61e4e8d2db4027ff44705b8032
4
+ data.tar.gz: 6119bde10948eca047d065a5030536b2c7ac720062f2ff0f81862b6f07b5c384
5
5
  SHA512:
6
- metadata.gz: 2789e6d5e4e5bd0b153eae4f9a41667dca6199e481bb848b98286d228c01ec2a75d5f75f4328260dc55340bea9b42f63761744e26adafffaf43948649c8cc707
7
- data.tar.gz: 76503d6285aae3b0c1a18f9ef080cc0689c69352625bf8c784d9fa8dfedd6887f3d7ead68003d46559519667c5f91e7351a32019768890730ccfbc76f7103f19
6
+ metadata.gz: 981be4fdb86e6aa0eed5d5d51f3df7d7fff0fd317646247a06e14de255d4d5235ca2cc70d87705ce061ca35178c3ead74d6555df004e6cd5349c27d273d656e8
7
+ data.tar.gz: 586c39385d2a7b2bc6fe356c9405b6b426b39f30c5afe457cab495d905f177829a3c7ebca332ee51e08b1cd5a6ede59cc00b1c160922ea9b9322d964acc9cde5
data/README.md CHANGED
@@ -42,6 +42,19 @@ There are some pages that exist by default and cannot be deleted since there
42
42
  are links to them inside the Decidim framework, see `Decidim::StaticPage` for
43
43
  the default list.
44
44
 
45
+ ### Pager Configuration
46
+
47
+ The number of results shown per page and per page range can be configured in the app `decidim.rb` initializer as follows:
48
+
49
+ ```ruby
50
+ Decidim::Admin.configure do |config|
51
+ config.per_page_range = [15, 50, 100]
52
+ end
53
+ ```
54
+
55
+ * `Decidim::Admin.per_page_range.first` sets the `default_per_page` value for `Decidim::Admin` (in Kaminari)
56
+ * `Decidim::Admin.per_page_range.last` sets the `max_per_page` value for `Decidim::Admin` (in Kaminari)
57
+
45
58
  ## Contributing
46
59
 
47
60
  See [Decidim](https://github.com/decidim/decidim).
@@ -3,7 +3,6 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  class ContentBlockCell < Decidim::ViewModel
6
- include Decidim::IconHelper
7
6
  include Decidim::ContentBlocks::HasRelatedComponents
8
7
 
9
8
  delegate :public_name_key, :has_settings?, :component_manifest_name, to: :model
@@ -1,5 +1,5 @@
1
- <span class="dropdown-menu-inverted_label"><%= t("decidim.admin.actions.per_page") %> :</span>
2
- <ul class="results-per-page__dropdown dropdown menu dropdown-inverted" data-dropdown-menu data-close-on-click-inside="false">
1
+ <span><%= t("decidim.admin.actions.per_page") %> :</span>
2
+ <ul class="dropdown menu" data-dropdown-menu data-close-on-click-inside="false">
3
3
  <li class="is-dropdown-submenu-parent">
4
4
  <a title="<%= %(#{per_page} #{t("decidim.admin.actions.per_page")}) %>">
5
5
  <%= per_page %>
@@ -4,8 +4,6 @@ module Decidim
4
4
  module Admin
5
5
  class ResultsPerPageCell < Decidim::ViewModel
6
6
  property :per_page, :per_page_range
7
- delegate :params, to: :controller, prefix: false
8
-
9
7
  def path_for_num_per_page(num_per_page = per_page_range.first)
10
8
  controller.url_for(params.to_unsafe_h.merge(per_page: num_per_page))
11
9
  end
@@ -77,7 +77,6 @@ module Decidim
77
77
  form.user.block_id = @current_blocking.id
78
78
  form.user.extended_data["user_name"] = form.user.name
79
79
  form.user.name = "Blocked user"
80
- form.user.notifications_sending_frequency = "none"
81
80
  form.user.save!
82
81
  end
83
82
  end
@@ -3,40 +3,12 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when creating an area
6
- class CreateArea < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # form - A form object with the params.
10
- def initialize(form)
11
- @form = form
12
- end
6
+ class CreateArea < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :organization, :area_type
13
8
 
14
- # Executes the command. Broadcasts these events:
15
- #
16
- # - :ok when everything is valid.
17
- # - :invalid if the form was not valid and we could not proceed.
18
- #
19
- # Returns nothing.
20
- def call
21
- return broadcast(:invalid) if form.invalid?
9
+ protected
22
10
 
23
- create_area
24
- broadcast(:ok)
25
- end
26
-
27
- private
28
-
29
- attr_reader :form
30
-
31
- def create_area
32
- Decidim.traceability.create!(
33
- Area,
34
- form.current_user,
35
- name: form.name,
36
- organization: form.organization,
37
- area_type: form.area_type
38
- )
39
- end
11
+ def resource_class = Decidim::Area
40
12
  end
41
13
  end
42
14
  end
@@ -3,41 +3,12 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when creating an area type.
6
- class CreateAreaType < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # form - A form object with the params.
10
- def initialize(form, user)
11
- @form = form
12
- @user = user
13
- end
6
+ class CreateAreaType < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :organization, :plural
14
8
 
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?
9
+ protected
23
10
 
24
- create_area_type
25
- broadcast(:ok)
26
- end
27
-
28
- private
29
-
30
- attr_reader :form
31
-
32
- def create_area_type
33
- Decidim.traceability.create!(
34
- AreaType,
35
- @user,
36
- name: form.name,
37
- organization: form.organization,
38
- plural: form.plural
39
- )
40
- end
11
+ def resource_class = Decidim::AreaType
41
12
  end
42
13
  end
43
14
  end
@@ -5,14 +5,14 @@ module Decidim
5
5
  # A command with all the business logic to add an attachment to a
6
6
  # participatory process.
7
7
  class CreateAttachment < Decidim::Command
8
+ delegate :current_user, to: :form
8
9
  # Public: Initializes the command.
9
10
  #
10
11
  # form - A form object with the params.
11
12
  # attached_to - The ActiveRecord::Base that will hold the attachment
12
- def initialize(form, attached_to, user)
13
+ def initialize(form, attached_to)
13
14
  @form = form
14
15
  @attached_to = attached_to
15
- @user = user
16
16
  end
17
17
 
18
18
  # Executes the command. Broadcasts these events:
@@ -27,7 +27,7 @@ module Decidim
27
27
  build_attachment
28
28
 
29
29
  if @attachment.valid?
30
- Decidim.traceability.perform_action!(:create, Decidim::Attachment, @user) do
30
+ Decidim.traceability.perform_action!(:create, Decidim::Attachment, current_user) do
31
31
  @attachment.save!
32
32
  notify_followers
33
33
  broadcast(:ok)
@@ -51,7 +51,8 @@ module Decidim
51
51
  weight: form.weight,
52
52
  attachment_collection: form.attachment_collection,
53
53
  file: form.file, # Define attached_to before this
54
- content_type: blob(form.file).content_type
54
+ content_type: form.file && blob(form.file).content_type,
55
+ link: form.file ? nil : form.link
55
56
  )
56
57
  end
57
58
 
@@ -5,14 +5,14 @@ module Decidim
5
5
  # A command with all the business logic to add an attachment collection
6
6
  # to a participatory space.
7
7
  class CreateAttachmentCollection < Decidim::Command
8
+ delegate :current_user, to: :form
8
9
  # Public: Initializes the command.
9
10
  #
10
11
  # form - A form object with the params.
11
12
  # collection_for - The ActiveRecord::Base that will hold the collection
12
- def initialize(form, collection_for, user)
13
+ def initialize(form, collection_for)
13
14
  @form = form
14
15
  @collection_for = collection_for
15
- @user = user
16
16
  end
17
17
 
18
18
  # Executes the command. Broadcasts these events:
@@ -35,7 +35,7 @@ module Decidim
35
35
  def create_attachment_collection
36
36
  Decidim.traceability.create!(
37
37
  AttachmentCollection,
38
- @user,
38
+ current_user,
39
39
  attributes
40
40
  )
41
41
  end
@@ -4,45 +4,12 @@ module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to create a new category in the
6
6
  # system.
7
- class CreateCategory < Decidim::Command
8
- # Public: Initializes the command.
9
- #
10
- # form - A form object with the params.
11
- # participatory_space - The participatory space that will hold the
12
- # category
13
- def initialize(form, participatory_space, user)
14
- @form = form
15
- @participatory_space = participatory_space
16
- @user = user
17
- end
7
+ class CreateCategory < Decidim::Commands::CreateResource
8
+ fetch_form_attributes :name, :weight, :parent_id, :participatory_space
18
9
 
19
- # Executes the command. Broadcasts these events:
20
- #
21
- # - :ok when everything is valid.
22
- # - :invalid if the form was not valid and we could not proceed.
23
- #
24
- # Returns nothing.
25
- def call
26
- return broadcast(:invalid) if form.invalid?
10
+ protected
27
11
 
28
- create_category
29
- broadcast(:ok)
30
- end
31
-
32
- private
33
-
34
- attr_reader :form
35
-
36
- def create_category
37
- Decidim.traceability.create!(
38
- Category,
39
- @user,
40
- name: form.name,
41
- weight: form.weight,
42
- parent_id: form.parent_id,
43
- participatory_space: @participatory_space
44
- )
45
- end
12
+ def resource_class = Decidim::Category
46
13
  end
47
14
  end
48
15
  end
@@ -3,50 +3,17 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # This command gets called when a component is created from the admin panel.
6
- class CreateComponent < Decidim::Command
7
- attr_reader :form, :manifest, :participatory_space
8
-
9
- # Public: Initializes the command.
10
- #
11
- # form - The form from which the data in this component comes from.
12
- def initialize(form)
13
- @form = form
14
- @manifest = form.manifest
15
- end
16
-
17
- # Public: Creates the Component.
18
- #
19
- # Broadcasts :ok if created, :invalid otherwise.
20
- def call
21
- return broadcast(:invalid) if form.invalid?
22
-
23
- transaction do
24
- create_component
25
- run_hooks
26
- end
27
-
28
- broadcast(:ok)
29
- end
6
+ class CreateComponent < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :participatory_space, :weight, :settings, :default_step_settings, :step_settings
30
8
 
31
9
  private
32
10
 
33
- def create_component
34
- @component = Decidim.traceability.create!(
35
- Component,
36
- form.current_user,
37
- manifest_name: manifest.name,
38
- name: form.name,
39
- participatory_space: form.participatory_space,
40
- weight: form.weight,
41
- settings: form.settings,
42
- default_step_settings: form.default_step_settings,
43
- step_settings: form.step_settings
44
- )
45
- end
11
+ # Use `reverse_merge` instead of `merge` as we need the `manifest_name` first
12
+ def attributes = super.reverse_merge({ manifest_name: form.manifest.name })
13
+
14
+ def resource_class = Decidim::Component
46
15
 
47
- def run_hooks
48
- manifest.run_hooks(:create, @component)
49
- end
16
+ def run_after_hooks = form.manifest.run_hooks(:create, resource)
50
17
  end
51
18
  end
52
19
  end
@@ -4,48 +4,30 @@ module Decidim
4
4
  module Admin
5
5
  # Creates a newsletter and assigns the right author and
6
6
  # organization.
7
- class CreateNewsletter < Decidim::Command
7
+ class CreateNewsletter < Decidim::Commands::CreateResource
8
+ fetch_form_attributes :subject, :organization
8
9
  # Initializes the command.
9
10
  #
10
11
  # form - The source fo data for this newsletter.
11
12
  # content_block - An instance of `Decidim::ContentBlock` that holds the
12
13
  # newsletter attributes.
13
- # user - The User that authored this newsletter.
14
- def initialize(form, content_block, user)
15
- @form = form
14
+ def initialize(form, content_block)
15
+ super(form)
16
16
  @content_block = content_block
17
- @user = user
18
- end
19
-
20
- def call
21
- return broadcast(:invalid) unless form.valid?
22
-
23
- transaction do
24
- create_newsletter
25
- create_content_block
26
- end
27
-
28
- broadcast(:ok, newsletter)
29
17
  end
30
18
 
31
19
  private
32
20
 
33
- attr_reader :user, :form, :newsletter, :content_block
21
+ attr_reader :content_block
34
22
 
35
- def create_newsletter
36
- @newsletter = Decidim.traceability.create!(
37
- Newsletter,
38
- user,
39
- subject: form.subject,
40
- author: user,
41
- organization: user.organization
42
- )
43
- end
23
+ def resource_class = Decidim::Newsletter
24
+
25
+ def attributes = super.merge({ author: form.current_user })
44
26
 
45
- def create_content_block
46
- ContentBlocks::UpdateContentBlock.call(form, content_block, user) do
27
+ def run_after_hooks
28
+ ContentBlocks::UpdateContentBlock.call(form, content_block, form.current_user) do
47
29
  on(:ok) do |content_block|
48
- content_block.update(scoped_resource_id: newsletter.id)
30
+ content_block.update(scoped_resource_id: resource.id)
49
31
  @content_block = content_block
50
32
  end
51
33
  on(:invalid) do
@@ -5,14 +5,14 @@ module Decidim
5
5
  # A command with all the business logic when creating a new participatory space
6
6
  # private user in the system.
7
7
  class CreateParticipatorySpacePrivateUser < Decidim::Command
8
+ delegate :current_user, to: :form
8
9
  # Public: Initializes the command.
9
10
  #
10
11
  # form - A form object with the params.
11
12
  # private_user_to - The private_user_to that will hold the
12
13
  # user role
13
- def initialize(form, current_user, private_user_to, via_csv: false)
14
+ def initialize(form, private_user_to, via_csv: false)
14
15
  @form = form
15
- @current_user = current_user
16
16
  @private_user_to = private_user_to
17
17
  @via_csv = via_csv
18
18
  end
@@ -39,7 +39,7 @@ module Decidim
39
39
 
40
40
  private
41
41
 
42
- attr_reader :form, :private_user_to, :current_user, :user
42
+ attr_reader :form, :private_user_to, :user
43
43
 
44
44
  def create_private_user
45
45
  action = @via_csv ? "create_via_csv" : "create"
@@ -62,7 +62,7 @@ module Decidim
62
62
  return @existing_user if defined?(@existing_user)
63
63
 
64
64
  @existing_user = User.find_by(
65
- email: form.email.downcase,
65
+ email: form.email,
66
66
  organization: private_user_to.organization
67
67
  )
68
68
 
@@ -2,50 +2,33 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # A command with all the business logic when creating a static scope.
6
- class CreateScope < Decidim::Command
5
+ # A command with all the business logic when creating a scope.
6
+ class CreateScope < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :organization, :code, :scope_type
7
8
  # Public: Initializes the command.
8
9
  #
9
10
  # form - A form object with the params.
10
- # parent_scope - A parent scope for the scope to be created
11
- def initialize(form, parent_scope = nil)
12
- @form = form
13
- @parent_scope = parent_scope
11
+ # parent - A parent scope for the scope to be created
12
+ def initialize(form, parent = nil)
13
+ super(form)
14
+ @parent = parent
14
15
  end
15
16
 
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?
17
+ protected
24
18
 
25
- create_scope
26
- broadcast(:ok)
27
- end
19
+ attr_reader :parent
28
20
 
29
- private
21
+ def resource_class = Decidim::Scope
30
22
 
31
- attr_reader :form
23
+ def attributes = super.merge({ parent: })
32
24
 
33
- def create_scope
34
- Decidim.traceability.create!(
35
- Scope,
36
- form.current_user,
37
- {
38
- name: form.name,
39
- organization: form.organization,
40
- code: form.code,
41
- scope_type: form.scope_type,
42
- parent: @parent_scope
43
- },
25
+ def extra_params
26
+ {
44
27
  extra: {
45
- parent_name: @parent_scope.try(:name),
28
+ parent_name: parent.try(:name),
46
29
  scope_type_name: form.scope_type.try(:name)
47
30
  }
48
- )
31
+ }
49
32
  end
50
33
  end
51
34
  end
@@ -3,41 +3,12 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when creating a scope type.
6
- class CreateScopeType < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # form - A form object with the params.
10
- def initialize(form, user)
11
- @form = form
12
- @user = user
13
- end
14
-
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?
23
-
24
- create_scope_type
25
- broadcast(:ok)
26
- end
6
+ class CreateScopeType < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :organization, :plural
27
8
 
28
9
  private
29
10
 
30
- attr_reader :form
31
-
32
- def create_scope_type
33
- Decidim.traceability.create!(
34
- ScopeType,
35
- @user,
36
- name: form.name,
37
- organization: form.organization,
38
- plural: form.plural
39
- )
40
- end
11
+ def resource_class = Decidim::ScopeType
41
12
  end
42
13
  end
43
14
  end
@@ -3,56 +3,15 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when creating a static page.
6
- class CreateStaticPage < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # form - A form object with the params.
10
- def initialize(form)
11
- @form = form
12
- @page = nil
13
- end
14
-
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?
23
-
24
- create_page
25
- update_organization_tos_version
26
- broadcast(:ok)
27
- end
6
+ class CreateStaticPage < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :organization, :title, :slug, :weight, :topic, :content, :allow_public_access
28
8
 
29
- private
9
+ protected
30
10
 
31
- attr_reader :form
32
-
33
- def create_page
34
- @page = Decidim.traceability.create!(
35
- StaticPage,
36
- form.current_user,
37
- attributes
38
- )
39
- end
40
-
41
- def attributes
42
- {
43
- organization: form.organization,
44
- title: form.title,
45
- slug: form.slug,
46
- show_in_footer: form.show_in_footer,
47
- weight: form.weight,
48
- topic: form.topic,
49
- content: form.content,
50
- allow_public_access: form.allow_public_access
51
- }
52
- end
11
+ def resource_class = Decidim::StaticPage
53
12
 
54
- def update_organization_tos_version
55
- UpdateOrganizationTosVersion.call(@form.organization, @page, @form)
13
+ def run_after_hooks
14
+ UpdateOrganizationTosVersion.call(form.organization, resource, form)
56
15
  end
57
16
  end
58
17
  end
@@ -3,34 +3,12 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when creating a static page topic.
6
- class CreateStaticPageTopic < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # form - A form object with the params.
10
- def initialize(form)
11
- @form = form
12
- end
6
+ class CreateStaticPageTopic < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :title, :description, :show_in_footer, :weight, :organization
13
8
 
14
- # Executes the command. Broadcasts these events:
15
- #
16
- # - :ok when everything is valid.
17
- # - :invalid if the form was not valid and we could not proceed.
18
- #
19
- # Returns nothing.
20
- def call
21
- return broadcast(:invalid) if @form.invalid?
9
+ protected
22
10
 
23
- @topic = Decidim.traceability.create!(
24
- StaticPageTopic,
25
- @form.current_user,
26
- title: @form.title,
27
- description: @form.description,
28
- organization: @form.current_organization,
29
- show_in_footer: @form.show_in_footer,
30
- weight: @form.weight
31
- )
32
- broadcast(:ok)
33
- end
11
+ def resource_class = Decidim::StaticPageTopic
34
12
  end
35
13
  end
36
14
  end
@@ -4,19 +4,18 @@ module Decidim
4
4
  module Admin
5
5
  # Delivers the newsletter to its recipients.
6
6
  class DeliverNewsletter < Decidim::Command
7
+ delegate :current_user, to: :form
7
8
  # Initializes the command.
8
9
  #
9
10
  # newsletter - The newsletter to deliver.
10
11
  # form - A form object with the params.
11
- # user - the Decidim::User that delivers the newsletter
12
- def initialize(newsletter, form, user)
12
+ def initialize(newsletter, form)
13
13
  @newsletter = newsletter
14
14
  @form = form
15
- @user = user
16
15
  end
17
16
 
18
17
  def call
19
- return broadcast(:invalid) if @form.send_to_all_users && !@user.admin?
18
+ return broadcast(:invalid) if @form.send_to_all_users && !current_user.admin?
20
19
  return broadcast(:invalid) unless @form.valid?
21
20
  return broadcast(:invalid) if @newsletter.sent?
22
21
  return broadcast(:no_recipients) if recipients.blank?
@@ -36,7 +35,7 @@ module Decidim
36
35
  Decidim.traceability.perform_action!(
37
36
  "deliver",
38
37
  @newsletter,
39
- @user
38
+ current_user
40
39
  ) do
41
40
  NewsletterJob.perform_later(@newsletter, @form.as_json, recipients.map(&:id))
42
41
  end