decidim-admin 0.28.4 → 0.29.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) 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/create_area.rb +4 -32
  7. data/app/commands/decidim/admin/create_area_type.rb +4 -33
  8. data/app/commands/decidim/admin/create_attachment.rb +5 -4
  9. data/app/commands/decidim/admin/create_attachment_collection.rb +3 -3
  10. data/app/commands/decidim/admin/create_category.rb +4 -37
  11. data/app/commands/decidim/admin/create_component.rb +7 -40
  12. data/app/commands/decidim/admin/create_newsletter.rb +11 -29
  13. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +4 -4
  14. data/app/commands/decidim/admin/create_scope.rb +15 -32
  15. data/app/commands/decidim/admin/create_scope_type.rb +3 -32
  16. data/app/commands/decidim/admin/create_static_page.rb +6 -47
  17. data/app/commands/decidim/admin/create_static_page_topic.rb +4 -26
  18. data/app/commands/decidim/admin/deliver_newsletter.rb +4 -5
  19. data/app/commands/decidim/admin/destroy_area.rb +2 -25
  20. data/app/commands/decidim/admin/destroy_category.rb +4 -29
  21. data/app/commands/decidim/admin/destroy_component.rb +5 -43
  22. data/app/commands/decidim/admin/destroy_newsletter.rb +2 -30
  23. data/app/commands/decidim/admin/destroy_participatory_space_private_user.rb +5 -32
  24. data/app/commands/decidim/admin/destroy_scope.rb +6 -33
  25. data/app/commands/decidim/admin/officialize_user.rb +1 -1
  26. data/app/commands/decidim/admin/participatory_space/create_admin.rb +4 -4
  27. data/app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb +5 -4
  28. data/app/commands/decidim/admin/promote_managed_user.rb +4 -5
  29. data/app/commands/decidim/admin/unofficialize_user.rb +1 -1
  30. data/app/commands/decidim/admin/update_area.rb +2 -41
  31. data/app/commands/decidim/admin/update_area_type.rb +2 -42
  32. data/app/commands/decidim/admin/update_attachment.rb +10 -7
  33. data/app/commands/decidim/admin/update_attachment_collection.rb +3 -3
  34. data/app/commands/decidim/admin/update_category.rb +2 -45
  35. data/app/commands/decidim/admin/update_component.rb +4 -5
  36. data/app/commands/decidim/admin/update_component_permissions.rb +3 -3
  37. data/app/commands/decidim/admin/{update_external_domain_whitelist.rb → update_external_domain_allowlist.rb} +6 -5
  38. data/app/commands/decidim/admin/update_help_sections.rb +6 -3
  39. data/app/commands/decidim/admin/update_newsletter.rb +8 -8
  40. data/app/commands/decidim/admin/update_organization.rb +9 -53
  41. data/app/commands/decidim/admin/update_organization_appearance.rb +10 -81
  42. data/app/commands/decidim/admin/update_scope.rb +7 -40
  43. data/app/commands/decidim/admin/update_scope_type.rb +2 -42
  44. data/app/commands/decidim/admin/update_static_page.rb +5 -46
  45. data/app/commands/decidim/admin/update_static_page_topic.rb +2 -43
  46. data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
  47. data/app/controllers/concerns/decidim/admin/content_blocks/landing_page.rb +2 -2
  48. data/app/controllers/concerns/decidim/admin/filterable.rb +79 -4
  49. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +1 -1
  50. data/app/controllers/concerns/decidim/admin/needs_admin_tos_accepted.rb +0 -7
  51. data/app/controllers/concerns/decidim/admin/paginable.rb +20 -0
  52. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +1 -1
  53. data/app/controllers/decidim/admin/application_controller.rb +2 -1
  54. data/app/controllers/decidim/admin/area_types_controller.rb +8 -9
  55. data/app/controllers/decidim/admin/areas_controller.rb +1 -1
  56. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +1 -1
  57. data/app/controllers/decidim/admin/categories_controller.rb +2 -2
  58. data/app/controllers/decidim/admin/component_permissions_controller.rb +1 -1
  59. data/app/controllers/decidim/admin/components_controller.rb +2 -2
  60. data/app/controllers/decidim/admin/concerns/has_attachment_collections.rb +2 -2
  61. data/app/controllers/decidim/admin/concerns/has_attachments.rb +2 -2
  62. data/app/controllers/decidim/admin/concerns/has_private_users.rb +1 -1
  63. data/app/controllers/decidim/admin/concerns/has_private_users_csv_import.rb +1 -1
  64. data/app/controllers/decidim/admin/conflicts_controller.rb +5 -13
  65. data/app/controllers/decidim/admin/help_sections_controller.rb +1 -1
  66. data/app/controllers/decidim/admin/managed_users/promotions_controller.rb +1 -1
  67. data/app/controllers/decidim/admin/moderations/reports_controller.rb +4 -4
  68. data/app/controllers/decidim/admin/moderations_controller.rb +7 -7
  69. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +1 -1
  70. data/app/controllers/decidim/admin/newsletters_controller.rb +5 -5
  71. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -1
  72. data/app/controllers/decidim/admin/organization_controller.rb +1 -1
  73. data/app/controllers/decidim/admin/{organization_external_domain_whitelist_controller.rb → organization_external_domain_allowlist_controller.rb} +7 -7
  74. data/app/controllers/decidim/admin/scope_types_controller.rb +7 -8
  75. data/app/controllers/decidim/admin/scopes_controller.rb +1 -1
  76. data/app/controllers/decidim/admin/share_tokens_controller.rb +1 -1
  77. data/app/controllers/decidim/admin/static_page_topics_controller.rb +2 -2
  78. data/app/controllers/decidim/admin/static_pages_controller.rb +2 -2
  79. data/app/forms/decidim/admin/attachment_form.rb +7 -1
  80. data/app/forms/decidim/admin/organization_appearance_form.rb +0 -3
  81. data/app/forms/decidim/admin/{organization_external_domain_whitelist_form.rb → organization_external_domain_allowlist_form.rb} +3 -3
  82. data/app/forms/decidim/admin/organization_form.rb +2 -2
  83. data/app/forms/decidim/admin/static_page_form.rb +0 -1
  84. data/app/helpers/decidim/admin/application_helper.rb +0 -13
  85. data/app/helpers/decidim/admin/filterable_helper.rb +19 -3
  86. data/app/helpers/decidim/admin/moderations/reports_helper.rb +3 -1
  87. data/app/helpers/decidim/admin/newsletters_helper.rb +3 -3
  88. data/app/helpers/decidim/admin/paginable/per_page_helper.rb +22 -0
  89. data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +2 -2
  90. data/app/packs/entrypoints/decidim_admin.js +4 -1
  91. data/app/packs/src/decidim/admin/application.js +19 -15
  92. data/app/packs/src/decidim/admin/css_preview.js +39 -0
  93. data/app/packs/src/decidim/admin/form.js +18 -1
  94. data/app/packs/src/decidim/admin/participatory_space_search.js +1 -1
  95. data/app/packs/src/decidim/admin/proposal_infinite_edit.js +2 -2
  96. data/app/packs/src/decidim/admin/sync_radio_buttons.js +27 -0
  97. data/app/packs/src/decidim/admin/text_copy.js +19 -0
  98. data/app/packs/stylesheets/decidim/admin/_cards.scss +1 -1
  99. data/app/packs/stylesheets/decidim/admin/_datepicker.scss +62 -0
  100. data/app/packs/stylesheets/decidim/admin/_item_edit.scss +1 -1
  101. data/app/packs/stylesheets/decidim/admin/_item_show.scss +8 -0
  102. data/app/packs/stylesheets/decidim/admin/_proposal_status.scss +5 -0
  103. data/app/packs/stylesheets/decidim/admin/application.scss +2 -0
  104. data/app/permissions/decidim/admin/permissions.rb +2 -2
  105. data/app/queries/decidim/admin/user_filter.rb +4 -4
  106. data/app/queries/decidim/admin/user_groups_evaluation.rb +1 -1
  107. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  108. data/app/views/decidim/admin/attachments/_form.html.erb +21 -2
  109. data/app/views/decidim/admin/attachments/index.html.erb +2 -2
  110. data/app/views/decidim/admin/authorization_workflows/index.html.erb +26 -8
  111. data/app/views/decidim/admin/block_user/new.html.erb +1 -1
  112. data/app/views/decidim/admin/categories/index.html.erb +2 -2
  113. data/app/views/decidim/admin/components/_form.html.erb +1 -1
  114. data/app/views/decidim/admin/components/index.html.erb +1 -5
  115. data/app/views/decidim/admin/conflicts/index.html.erb +6 -29
  116. data/app/views/decidim/admin/dashboard/_pending_moderations.html.erb +1 -1
  117. data/app/views/decidim/admin/dashboard/show.html.erb +1 -1
  118. data/app/views/decidim/admin/exports/_dropdown.html.erb +6 -6
  119. data/app/views/decidim/admin/impersonatable_users/index.html.erb +3 -3
  120. data/app/views/decidim/admin/imports/_dropdown.html.erb +5 -7
  121. data/app/views/decidim/admin/imports/new.html.erb +6 -7
  122. data/app/views/decidim/admin/logs/_filters.html.erb +3 -3
  123. data/app/views/decidim/admin/managed_users/promotions/new.html.erb +1 -1
  124. data/app/views/decidim/admin/moderated_users/index.html.erb +2 -2
  125. data/app/views/decidim/admin/moderations/index.html.erb +5 -5
  126. data/app/views/decidim/admin/moderations/reports/index.html.erb +6 -6
  127. data/app/views/decidim/admin/moderations/reports/show.html.erb +4 -4
  128. data/app/views/decidim/admin/newsletter_templates/index.html.erb +2 -2
  129. data/app/views/decidim/admin/newsletter_templates/show.html.erb +7 -7
  130. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  131. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +6 -7
  132. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  133. data/app/views/decidim/admin/organization/_form.html.erb +3 -3
  134. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +0 -3
  135. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +5 -5
  136. data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +3 -3
  137. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_external_domain.html.erb +4 -4
  138. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_form.html.erb +2 -2
  139. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/edit.html.erb +2 -2
  140. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  141. data/app/views/decidim/admin/participatory_space_private_users_csv_imports/new.html.erb +1 -1
  142. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +1 -1
  143. data/app/views/decidim/admin/shared/_adjacent_navigation.html.erb +30 -0
  144. data/app/views/decidim/admin/shared/_admin_confirm_modal.html.erb +7 -7
  145. data/app/views/decidim/admin/shared/_filters.html.erb +1 -1
  146. data/app/views/decidim/admin/shared/_gallery.html.erb +1 -1
  147. data/app/views/decidim/admin/shared/landing_page/_content_blocks.html.erb +2 -2
  148. data/app/views/decidim/admin/static_page_topics/index.html.erb +1 -1
  149. data/app/views/decidim/admin/static_pages/_form.html.erb +0 -4
  150. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +2 -2
  151. data/app/views/layouts/decidim/admin/_admin_timeout_modal.html.erb +2 -2
  152. data/app/views/layouts/decidim/admin/_application.html.erb +4 -4
  153. data/app/views/layouts/decidim/admin/_callouts_full.html.erb +1 -1
  154. data/app/views/layouts/decidim/admin/_js_configuration.html.erb +3 -1
  155. data/app/views/layouts/decidim/admin/_title_bar.html.erb +2 -2
  156. data/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb +2 -2
  157. data/config/locales/ar.yml +0 -7
  158. data/config/locales/bg.yml +15 -12
  159. data/config/locales/ca.yml +18 -15
  160. data/config/locales/cs.yml +15 -17
  161. data/config/locales/de.yml +15 -12
  162. data/config/locales/el.yml +0 -12
  163. data/config/locales/en.yml +16 -13
  164. data/config/locales/es-MX.yml +16 -13
  165. data/config/locales/es-PY.yml +16 -13
  166. data/config/locales/es.yml +18 -15
  167. data/config/locales/eu.yml +16 -13
  168. data/config/locales/fi-plain.yml +15 -12
  169. data/config/locales/fi.yml +19 -16
  170. data/config/locales/fr-CA.yml +14 -11
  171. data/config/locales/fr.yml +13 -10
  172. data/config/locales/ga-IE.yml +0 -3
  173. data/config/locales/gl.yml +0 -5
  174. data/config/locales/hu.yml +9 -10
  175. data/config/locales/id-ID.yml +0 -3
  176. data/config/locales/is-IS.yml +0 -3
  177. data/config/locales/it.yml +0 -8
  178. data/config/locales/ja.yml +18 -15
  179. data/config/locales/kaa.yml +0 -3
  180. data/config/locales/ko.yml +0 -6
  181. data/config/locales/lb.yml +0 -8
  182. data/config/locales/lt.yml +0 -13
  183. data/config/locales/lv.yml +0 -3
  184. data/config/locales/nl.yml +0 -8
  185. data/config/locales/no.yml +0 -8
  186. data/config/locales/pl.yml +14 -9
  187. data/config/locales/pt-BR.yml +8 -13
  188. data/config/locales/pt.yml +0 -8
  189. data/config/locales/ro-RO.yml +3 -21
  190. data/config/locales/ru.yml +0 -3
  191. data/config/locales/sk.yml +0 -3
  192. data/config/locales/sq-AL.yml +0 -3
  193. data/config/locales/sr-CS.yml +0 -3
  194. data/config/locales/sv.yml +207 -355
  195. data/config/locales/th-TH.yml +0 -3
  196. data/config/locales/tr-TR.yml +0 -5
  197. data/config/locales/uk.yml +0 -3
  198. data/config/locales/zh-CN.yml +0 -3
  199. data/config/locales/zh-TW.yml +0 -12
  200. data/config/routes.rb +1 -1
  201. data/decidim-admin.gemspec +1 -1
  202. data/lib/decidim/admin/import/creator.rb +1 -1
  203. data/lib/decidim/admin/import/importer_factory.rb +2 -2
  204. data/lib/decidim/admin/menu.rb +4 -4
  205. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +3 -2
  206. data/lib/decidim/admin/test/commands/create_category_examples.rb +4 -2
  207. data/lib/decidim/admin/test/commands/update_attachment_collection_examples.rb +3 -2
  208. data/lib/decidim/admin/test/commands/update_category_examples.rb +3 -2
  209. data/lib/decidim/admin/test/filterable_examples.rb +5 -3
  210. data/lib/decidim/admin/test/filters_participatory_space_user_roles_examples.rb +5 -5
  211. data/lib/decidim/admin/test/invite_participatory_space_admins_shared_examples.rb +1 -1
  212. data/lib/decidim/admin/test/invite_participatory_space_users_shared_context.rb +0 -1
  213. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +12 -12
  214. data/lib/decidim/admin/test/manage_attachments_examples.rb +52 -28
  215. data/lib/decidim/admin/test/manage_categories_examples.rb +13 -13
  216. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +5 -5
  217. data/lib/decidim/admin/test/manage_hide_content_examples.rb +4 -4
  218. data/lib/decidim/admin/test/manage_moderations_examples.rb +21 -21
  219. data/lib/decidim/admin/test/manage_paginated_collection_examples.rb +5 -5
  220. data/lib/decidim/admin/test/manage_participatory_space_publications_examples.rb +2 -2
  221. data/lib/decidim/admin/version.rb +1 -1
  222. data/lib/decidim/admin.rb +15 -0
  223. metadata +27 -24
  224. data/app/commands/decidim/admin/destroy_share_token.rb +0 -46
  225. data/app/commands/decidim/admin/destroy_static_page.rb +0 -40
  226. data/app/commands/decidim/admin/destroy_static_page_topic.rb +0 -40
  227. data/app/controllers/concerns/decidim/admin/verification_conflicts/filterable.rb +0 -31
  228. data/app/views/layouts/decidim/admin/login.html.erb +0 -19
  229. /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: e2df15806d18b7a9463fba1af0a915d7eb271b42171c44b8ca6ba2d4b0314d7c
4
- data.tar.gz: 542095a6b09cc350520f884ec35316b19e59cfb2ec8dd23474f0929020155c78
3
+ metadata.gz: f2203fd3c924ab306246e912329cdaac02091b61e4e8d2db4027ff44705b8032
4
+ data.tar.gz: 6119bde10948eca047d065a5030536b2c7ac720062f2ff0f81862b6f07b5c384
5
5
  SHA512:
6
- metadata.gz: 853c6bc0e5b9ea946576f04a4fda4c00d3dbade41e6c7f1b95aae97a65cacee29de9df3196dd6570fba5453c6ee99f76fe7b66b3376907adb57813e08b6363f3
7
- data.tar.gz: b5fa7e8a4122cae417e557638ef8526ef9f9213241ec5d321ffdee25cc768eeb459e2dcc12d5c2c9098fa3576c3e16a237e04988d6479492dc9a56353c44f15a
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
@@ -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