decidim-admin 0.28.1 → 0.29.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/admin/content_block_cell.rb +0 -1
  3. data/app/cells/decidim/admin/results_per_page/show.erb +2 -2
  4. data/app/cells/decidim/admin/results_per_page_cell.rb +0 -2
  5. data/app/commands/decidim/admin/create_area.rb +4 -32
  6. data/app/commands/decidim/admin/create_area_type.rb +4 -33
  7. data/app/commands/decidim/admin/create_attachment.rb +5 -4
  8. data/app/commands/decidim/admin/create_attachment_collection.rb +3 -3
  9. data/app/commands/decidim/admin/create_category.rb +4 -37
  10. data/app/commands/decidim/admin/create_component.rb +7 -40
  11. data/app/commands/decidim/admin/create_newsletter.rb +11 -29
  12. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +3 -3
  13. data/app/commands/decidim/admin/create_scope.rb +15 -32
  14. data/app/commands/decidim/admin/create_scope_type.rb +3 -32
  15. data/app/commands/decidim/admin/create_static_page.rb +6 -47
  16. data/app/commands/decidim/admin/create_static_page_topic.rb +4 -26
  17. data/app/commands/decidim/admin/deliver_newsletter.rb +4 -5
  18. data/app/commands/decidim/admin/destroy_area.rb +2 -25
  19. data/app/commands/decidim/admin/destroy_category.rb +4 -29
  20. data/app/commands/decidim/admin/destroy_component.rb +5 -42
  21. data/app/commands/decidim/admin/destroy_newsletter.rb +2 -30
  22. data/app/commands/decidim/admin/destroy_participatory_space_private_user.rb +5 -32
  23. data/app/commands/decidim/admin/destroy_scope.rb +6 -33
  24. data/app/commands/decidim/admin/officialize_user.rb +1 -1
  25. data/app/commands/decidim/admin/participatory_space/create_admin.rb +4 -4
  26. data/app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb +5 -4
  27. data/app/commands/decidim/admin/promote_managed_user.rb +4 -5
  28. data/app/commands/decidim/admin/unofficialize_user.rb +1 -1
  29. data/app/commands/decidim/admin/update_area.rb +2 -41
  30. data/app/commands/decidim/admin/update_area_type.rb +2 -42
  31. data/app/commands/decidim/admin/update_attachment.rb +10 -7
  32. data/app/commands/decidim/admin/update_attachment_collection.rb +3 -3
  33. data/app/commands/decidim/admin/update_category.rb +2 -45
  34. data/app/commands/decidim/admin/update_component.rb +4 -5
  35. data/app/commands/decidim/admin/update_component_permissions.rb +3 -3
  36. data/app/commands/decidim/admin/{update_external_domain_whitelist.rb → update_external_domain_allowlist.rb} +6 -5
  37. data/app/commands/decidim/admin/update_help_sections.rb +6 -3
  38. data/app/commands/decidim/admin/update_newsletter.rb +8 -8
  39. data/app/commands/decidim/admin/update_organization.rb +9 -53
  40. data/app/commands/decidim/admin/update_organization_appearance.rb +10 -81
  41. data/app/commands/decidim/admin/update_scope.rb +7 -40
  42. data/app/commands/decidim/admin/update_scope_type.rb +2 -42
  43. data/app/commands/decidim/admin/update_static_page.rb +5 -46
  44. data/app/commands/decidim/admin/update_static_page_topic.rb +2 -43
  45. data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
  46. data/app/controllers/concerns/decidim/admin/content_blocks/landing_page.rb +2 -2
  47. data/app/controllers/concerns/decidim/admin/filterable.rb +78 -3
  48. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +1 -1
  49. data/app/controllers/concerns/decidim/admin/needs_admin_tos_accepted.rb +0 -7
  50. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +1 -1
  51. data/app/controllers/decidim/admin/application_controller.rb +1 -0
  52. data/app/controllers/decidim/admin/area_types_controller.rb +8 -9
  53. data/app/controllers/decidim/admin/areas_controller.rb +1 -1
  54. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +3 -1
  55. data/app/controllers/decidim/admin/categories_controller.rb +2 -2
  56. data/app/controllers/decidim/admin/component_permissions_controller.rb +1 -1
  57. data/app/controllers/decidim/admin/components_controller.rb +2 -2
  58. data/app/controllers/decidim/admin/concerns/has_attachment_collections.rb +2 -2
  59. data/app/controllers/decidim/admin/concerns/has_attachments.rb +2 -2
  60. data/app/controllers/decidim/admin/concerns/has_private_users.rb +1 -1
  61. data/app/controllers/decidim/admin/concerns/has_private_users_csv_import.rb +1 -1
  62. data/app/controllers/decidim/admin/help_sections_controller.rb +1 -1
  63. data/app/controllers/decidim/admin/managed_users/promotions_controller.rb +1 -1
  64. data/app/controllers/decidim/admin/moderations/reports_controller.rb +4 -4
  65. data/app/controllers/decidim/admin/moderations_controller.rb +7 -7
  66. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +1 -1
  67. data/app/controllers/decidim/admin/newsletters_controller.rb +5 -5
  68. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -1
  69. data/app/controllers/decidim/admin/organization_controller.rb +8 -5
  70. data/app/controllers/decidim/admin/{organization_external_domain_whitelist_controller.rb → organization_external_domain_allowlist_controller.rb} +7 -7
  71. data/app/controllers/decidim/admin/scope_types_controller.rb +7 -8
  72. data/app/controllers/decidim/admin/scopes_controller.rb +1 -1
  73. data/app/controllers/decidim/admin/share_tokens_controller.rb +1 -1
  74. data/app/controllers/decidim/admin/static_page_topics_controller.rb +2 -2
  75. data/app/controllers/decidim/admin/static_pages_controller.rb +2 -2
  76. data/app/forms/decidim/admin/attachment_form.rb +7 -1
  77. data/app/forms/decidim/admin/organization_appearance_form.rb +0 -3
  78. data/app/forms/decidim/admin/{organization_external_domain_whitelist_form.rb → organization_external_domain_allowlist_form.rb} +3 -3
  79. data/app/forms/decidim/admin/organization_form.rb +2 -2
  80. data/app/forms/decidim/admin/static_page_form.rb +0 -1
  81. data/app/helpers/decidim/admin/filterable_helper.rb +19 -3
  82. data/app/helpers/decidim/admin/moderations/reports_helper.rb +3 -1
  83. data/app/helpers/decidim/admin/newsletters_helper.rb +3 -3
  84. data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +2 -2
  85. data/app/packs/entrypoints/decidim_admin.js +4 -1
  86. data/app/packs/src/decidim/admin/application.js +25 -16
  87. data/app/packs/src/decidim/admin/choose_language.js +2 -0
  88. data/app/packs/src/decidim/admin/css_preview.js +39 -0
  89. data/app/packs/src/decidim/admin/dynamic_fields.component.js +2 -1
  90. data/app/packs/src/decidim/admin/form.js +18 -1
  91. data/app/packs/src/decidim/admin/participatory_space_search.js +1 -1
  92. data/app/packs/src/decidim/admin/proposal_infinite_edit.js +2 -2
  93. data/app/packs/src/decidim/admin/sync_radio_buttons.js +27 -0
  94. data/app/packs/src/decidim/admin/text_copy.js +19 -0
  95. data/app/packs/stylesheets/decidim/admin/_cards.scss +1 -1
  96. data/app/packs/stylesheets/decidim/admin/_datepicker.scss +62 -0
  97. data/app/packs/stylesheets/decidim/admin/_item_edit.scss +1 -1
  98. data/app/packs/stylesheets/decidim/admin/_item_show.scss +8 -0
  99. data/app/packs/stylesheets/decidim/admin/_proposal_status.scss +5 -0
  100. data/app/packs/stylesheets/decidim/admin/application.scss +2 -0
  101. data/app/permissions/decidim/admin/permissions.rb +2 -2
  102. data/app/queries/decidim/admin/user_filter.rb +4 -4
  103. data/app/queries/decidim/admin/user_groups_evaluation.rb +1 -1
  104. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  105. data/app/views/decidim/admin/attachments/_form.html.erb +21 -2
  106. data/app/views/decidim/admin/attachments/index.html.erb +2 -2
  107. data/app/views/decidim/admin/authorization_workflows/index.html.erb +26 -8
  108. data/app/views/decidim/admin/categories/index.html.erb +2 -2
  109. data/app/views/decidim/admin/components/_form.html.erb +1 -1
  110. data/app/views/decidim/admin/dashboard/_pending_moderations.html.erb +1 -1
  111. data/app/views/decidim/admin/dashboard/show.html.erb +1 -1
  112. data/app/views/decidim/admin/exports/_dropdown.html.erb +1 -1
  113. data/app/views/decidim/admin/impersonatable_users/index.html.erb +3 -3
  114. data/app/views/decidim/admin/imports/_dropdown.html.erb +1 -1
  115. data/app/views/decidim/admin/imports/new.html.erb +2 -2
  116. data/app/views/decidim/admin/logs/_filters.html.erb +3 -3
  117. data/app/views/decidim/admin/managed_users/promotions/new.html.erb +1 -1
  118. data/app/views/decidim/admin/moderated_users/index.html.erb +2 -2
  119. data/app/views/decidim/admin/moderations/index.html.erb +5 -5
  120. data/app/views/decidim/admin/moderations/reports/index.html.erb +6 -6
  121. data/app/views/decidim/admin/moderations/reports/show.html.erb +4 -4
  122. data/app/views/decidim/admin/newsletter_templates/index.html.erb +2 -2
  123. data/app/views/decidim/admin/newsletter_templates/show.html.erb +7 -7
  124. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  125. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +3 -3
  126. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  127. data/app/views/decidim/admin/organization/_form.html.erb +3 -3
  128. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +0 -3
  129. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +5 -5
  130. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_external_domain.html.erb +4 -4
  131. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/_form.html.erb +2 -2
  132. data/app/views/decidim/admin/{organization_external_domain_whitelist → organization_external_domain_allowlist}/edit.html.erb +2 -2
  133. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  134. data/app/views/decidim/admin/participatory_space_private_users_csv_imports/new.html.erb +1 -1
  135. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +1 -1
  136. data/app/views/decidim/admin/shared/_adjacent_navigation.html.erb +30 -0
  137. data/app/views/decidim/admin/shared/_admin_confirm_modal.html.erb +7 -7
  138. data/app/views/decidim/admin/shared/_filters.html.erb +1 -1
  139. data/app/views/decidim/admin/shared/_gallery.html.erb +1 -1
  140. data/app/views/decidim/admin/shared/_js-callout.html.erb +2 -2
  141. data/app/views/decidim/admin/shared/landing_page/_content_blocks.html.erb +2 -2
  142. data/app/views/decidim/admin/static_page_topics/index.html.erb +1 -1
  143. data/app/views/decidim/admin/static_pages/_form.html.erb +0 -4
  144. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +2 -2
  145. data/app/views/layouts/decidim/admin/_admin_timeout_modal.html.erb +2 -2
  146. data/app/views/layouts/decidim/admin/_application.html.erb +4 -4
  147. data/app/views/layouts/decidim/admin/_callouts_full.html.erb +1 -1
  148. data/app/views/layouts/decidim/admin/_js_configuration.html.erb +3 -1
  149. data/app/views/layouts/decidim/admin/_sidebar_menu.html.erb +2 -2
  150. data/app/views/layouts/decidim/admin/_title_bar.html.erb +2 -2
  151. data/app/views/layouts/decidim/admin/_title_bar_responsive.html.erb +2 -2
  152. data/config/locales/ar.yml +1 -7
  153. data/config/locales/bg.yml +1013 -11
  154. data/config/locales/ca.yml +18 -11
  155. data/config/locales/cs.yml +17 -10
  156. data/config/locales/de.yml +25 -18
  157. data/config/locales/el.yml +1 -12
  158. data/config/locales/en.yml +18 -11
  159. data/config/locales/es-MX.yml +25 -18
  160. data/config/locales/es-PY.yml +25 -18
  161. data/config/locales/es.yml +34 -27
  162. data/config/locales/eu.yml +18 -11
  163. data/config/locales/fi-plain.yml +16 -9
  164. data/config/locales/fi.yml +16 -9
  165. data/config/locales/fr-CA.yml +16 -9
  166. data/config/locales/fr.yml +15 -8
  167. data/config/locales/ga-IE.yml +1 -3
  168. data/config/locales/gl.yml +1 -5
  169. data/config/locales/hu.yml +10 -10
  170. data/config/locales/id-ID.yml +1 -3
  171. data/config/locales/is-IS.yml +1 -3
  172. data/config/locales/it.yml +2 -8
  173. data/config/locales/ja.yml +18 -11
  174. data/config/locales/kaa.yml +0 -3
  175. data/config/locales/ko.yml +0 -6
  176. data/config/locales/lb.yml +1 -8
  177. data/config/locales/lt.yml +2 -13
  178. data/config/locales/lv.yml +1 -3
  179. data/config/locales/nl.yml +1 -8
  180. data/config/locales/no.yml +1 -8
  181. data/config/locales/pl.yml +17 -9
  182. data/config/locales/pt-BR.yml +9 -10
  183. data/config/locales/pt.yml +1 -8
  184. data/config/locales/ro-RO.yml +1 -12
  185. data/config/locales/ru.yml +1 -3
  186. data/config/locales/sk.yml +1 -3
  187. data/config/locales/sl.yml +1 -0
  188. data/config/locales/sq-AL.yml +410 -0
  189. data/config/locales/sr-CS.yml +1 -3
  190. data/config/locales/sv.yml +1 -8
  191. data/config/locales/th-TH.yml +98 -0
  192. data/config/locales/tr-TR.yml +1 -5
  193. data/config/locales/uk.yml +1 -3
  194. data/config/locales/zh-CN.yml +1 -3
  195. data/config/locales/zh-TW.yml +2 -12
  196. data/config/routes.rb +1 -1
  197. data/decidim-admin.gemspec +1 -1
  198. data/lib/decidim/admin/import/creator.rb +1 -1
  199. data/lib/decidim/admin/import/importer_factory.rb +2 -2
  200. data/lib/decidim/admin/menu.rb +4 -4
  201. data/lib/decidim/admin/test/admin_participatory_space_access_examples.rb +27 -0
  202. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +3 -2
  203. data/lib/decidim/admin/test/commands/create_category_examples.rb +4 -2
  204. data/lib/decidim/admin/test/commands/update_attachment_collection_examples.rb +3 -2
  205. data/lib/decidim/admin/test/commands/update_category_examples.rb +3 -2
  206. data/lib/decidim/admin/test/filterable_examples.rb +5 -3
  207. data/lib/decidim/admin/test/filters_participatory_space_user_roles_examples.rb +5 -5
  208. data/lib/decidim/admin/test/invite_participatory_space_admins_shared_examples.rb +180 -0
  209. data/lib/decidim/admin/test/invite_participatory_space_collaborators_shared_examples.rb +67 -0
  210. data/lib/decidim/admin/test/invite_participatory_space_moderators_shared_examples.rb +77 -0
  211. data/lib/decidim/admin/test/invite_participatory_space_users_shared_context.rb +33 -0
  212. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +24 -23
  213. data/lib/decidim/admin/test/manage_attachments_examples.rb +51 -15
  214. data/lib/decidim/admin/test/manage_categories_examples.rb +24 -21
  215. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +5 -5
  216. data/lib/decidim/admin/test/manage_hide_content_examples.rb +8 -4
  217. data/lib/decidim/admin/test/manage_moderations_examples.rb +21 -21
  218. data/lib/decidim/admin/test/manage_paginated_collection_examples.rb +3 -3
  219. data/lib/decidim/admin/test/manage_participatory_space_publications_examples.rb +2 -2
  220. data/lib/decidim/admin/test.rb +1 -0
  221. data/lib/decidim/admin/version.rb +1 -1
  222. metadata +32 -27
  223. data/app/commands/decidim/admin/destroy_share_token.rb +0 -46
  224. data/app/commands/decidim/admin/destroy_static_page.rb +0 -40
  225. data/app/commands/decidim/admin/destroy_static_page_topic.rb +0 -40
  226. data/app/mailers/decidim/admin/application_mailer.rb +0 -12
  227. data/app/views/layouts/decidim/admin/login.html.erb +0 -19
  228. /data/app/packs/src/decidim/admin/{external_domain_whitelist.js → external_domain_allowlist.js} +0 -0
@@ -3,16 +3,7 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to destroy an area.
6
- class DestroyArea < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # area - The area to destroy
10
- # current_user - the user performing the action
11
- def initialize(area, current_user)
12
- @area = area
13
- @current_user = current_user
14
- end
15
-
6
+ class DestroyArea < Decidim::Commands::DestroyResource
16
7
  # Executes the command. Broadcasts these events:
17
8
  #
18
9
  # - :ok when everything is valid.
@@ -20,25 +11,11 @@ module Decidim
20
11
  #
21
12
  # Returns nothing.
22
13
  def call
23
- destroy_area
14
+ destroy_resource
24
15
  broadcast(:ok)
25
16
  rescue ActiveRecord::RecordNotDestroyed
26
17
  broadcast(:has_spaces)
27
18
  end
28
-
29
- private
30
-
31
- attr_reader :current_user
32
-
33
- def destroy_area
34
- Decidim.traceability.perform_action!(
35
- "delete",
36
- @area,
37
- current_user
38
- ) do
39
- @area.destroy!
40
- end
41
- end
42
19
  end
43
20
  end
44
21
  end
@@ -4,36 +4,11 @@ module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to destroy a category in the
6
6
  # system.
7
- class DestroyCategory < Decidim::Command
8
- # Public: Initializes the command.
9
- #
10
- # category - A Category that will be destroyed
11
- def initialize(category, user)
12
- @category = category
13
- @user = user
14
- end
15
-
16
- # Executes the command. Broadcasts these events:
17
- #
18
- # - :ok when everything is valid.
19
- # - :invalid if the data was not valid and we could not proceed.
20
- #
21
- # Returns nothing.
22
- def call
23
- return broadcast(:invalid) if category.nil? || category.subcategories.any? || !category.unused?
24
-
25
- destroy_category
26
- broadcast(:ok)
27
- end
28
-
29
- private
30
-
31
- attr_reader :category
7
+ class DestroyCategory < Decidim::Commands::DestroyResource
8
+ protected
32
9
 
33
- def destroy_category
34
- Decidim.traceability.perform_action!(:delete, category, @user) do
35
- category.destroy!
36
- end
10
+ def invalid?
11
+ resource.nil? || resource.subcategories.any? || !resource.unused?
37
12
  end
38
13
  end
39
14
  end
@@ -2,53 +2,16 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # This command deals with destroying a Component from the admin panel.
6
- class DestroyComponent < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # component - The Component to be destroyed.
10
- # current_user - the user performing the action
11
- def initialize(component, current_user)
12
- @component = component
13
- @current_user = current_user
14
- end
15
-
16
- # Public: Executes the command.
17
- #
18
- # Broadcasts :ok if it got destroyed, raises an exception otherwise.
19
- def call
20
- begin
21
- destroy_component
22
- rescue StandardError
23
- return broadcast(:invalid)
24
- end
25
- broadcast(:ok)
26
- end
27
-
5
+ # This command deals with destroying a component from the admin panel.
6
+ class DestroyComponent < Decidim::Commands::DestroyResource
28
7
  private
29
8
 
30
- def destroy_component
31
- transaction do
32
- run_before_hooks
33
-
34
- Decidim.traceability.perform_action!(
35
- "delete",
36
- @component,
37
- @current_user
38
- ) do
39
- @component.destroy!
40
- end
41
-
42
- run_hooks
43
- end
44
- end
45
-
46
9
  def run_before_hooks
47
- @component.manifest.run_hooks(:before_destroy, @component)
10
+ resource.manifest.run_hooks(:before_destroy, resource)
48
11
  end
49
12
 
50
- def run_hooks
51
- @component.manifest.run_hooks(:destroy, @component)
13
+ def run_after_hooks
14
+ resource.manifest.run_hooks(:destroy, resource)
52
15
  end
53
16
  end
54
17
  end
@@ -3,38 +3,10 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # This command deals with destroying a newsletter from the admin panel.
6
- class DestroyNewsletter < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # newsletter - The Newsletter to be destroyed.
10
- def initialize(newsletter, current_user)
11
- @newsletter = newsletter
12
- @current_user = current_user
13
- end
14
-
15
- # Public: Executes the command.
16
- #
17
- # Broadcasts :ok if it got destroyed
18
- def call
19
- return broadcast(:already_sent) if newsletter.sent?
20
-
21
- destroy_newsletter
22
- broadcast(:ok)
23
- end
24
-
6
+ class DestroyNewsletter < Decidim::Commands::DestroyResource
25
7
  private
26
8
 
27
- attr_reader :newsletter, :current_user
28
-
29
- def destroy_newsletter
30
- Decidim.traceability.perform_action!(
31
- "delete",
32
- newsletter,
33
- current_user
34
- ) do
35
- newsletter.destroy!
36
- end
37
- end
9
+ def invalid? = resource.sent?
38
10
  end
39
11
  end
40
12
  end
@@ -3,42 +3,15 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to destroy a participatory space private user.
6
- class DestroyParticipatorySpacePrivateUser < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # participatory_space_private_user - The participatory space private user to destroy
10
- # current_user - the user performing the action
11
- def initialize(participatory_space_private_user, current_user)
12
- @participatory_space_private_user = participatory_space_private_user
13
- @current_user = current_user
14
- end
15
-
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
- destroy_participatory_space_private_user
24
- broadcast(:ok)
25
- end
26
-
6
+ class DestroyParticipatorySpacePrivateUser < Decidim::Commands::DestroyResource
27
7
  private
28
8
 
29
- attr_reader :current_user
30
-
31
- def destroy_participatory_space_private_user
32
- Decidim.traceability.perform_action!(
33
- "delete",
34
- @participatory_space_private_user,
35
- current_user,
9
+ def extra_params
10
+ {
36
11
  resource: {
37
- title: @participatory_space_private_user.user.name
12
+ title: resource.user.name
38
13
  }
39
- ) do
40
- @participatory_space_private_user.destroy!
41
- end
14
+ }
42
15
  end
43
16
  end
44
17
  end
@@ -3,43 +3,16 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to destroy a scope.
6
- class DestroyScope < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # scope - The Scope to destroy
10
- # current_user - the user performing the action
11
- def initialize(scope, current_user)
12
- @scope = scope
13
- @current_user = current_user
14
- end
15
-
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
- update_scope
24
- broadcast(:ok)
25
- end
26
-
6
+ class DestroyScope < Decidim::Commands::DestroyResource
27
7
  private
28
8
 
29
- attr_reader :current_user
30
-
31
- def update_scope
32
- Decidim.traceability.perform_action!(
33
- "delete",
34
- @scope,
35
- current_user,
9
+ def extra_params
10
+ {
36
11
  extra: {
37
- parent_name: @scope.parent.try(:name),
38
- scope_type_name: @scope.scope_type.try(:name)
12
+ parent_name: resource.parent.try(:name),
13
+ scope_type_name: resource.scope_type.try(:name)
39
14
  }
40
- ) do
41
- @scope.destroy!
42
- end
15
+ }
43
16
  end
44
17
  end
45
18
  end
@@ -13,7 +13,7 @@ module Decidim
13
13
 
14
14
  # Executes the command. Broadcasts these events:
15
15
  #
16
- # - :ok when the officialization suceeds.
16
+ # - :ok when the officialization succeeds.
17
17
  # - :invalid when the form is invalid.
18
18
  #
19
19
  # Returns nothing.
@@ -4,6 +4,7 @@ module Decidim
4
4
  module Admin
5
5
  module ParticipatorySpace
6
6
  class CreateAdmin < Decidim::Command
7
+ delegate :current_user, to: :form
7
8
  # Public: Initializes the command.
8
9
  #
9
10
  # form - A form object with the params.
@@ -11,7 +12,6 @@ module Decidim
11
12
  # user role
12
13
  def initialize(form, participatory_space, options = {})
13
14
  @form = form
14
- @current_user = form.current_user
15
15
  @participatory_space = participatory_space
16
16
  @event_class = options.delete(:event_class)
17
17
  @event = options.delete(:event)
@@ -41,7 +41,7 @@ module Decidim
41
41
 
42
42
  private
43
43
 
44
- attr_reader :form, :participatory_space, :current_user, :user
44
+ attr_reader :form, :participatory_space, :user
45
45
 
46
46
  def event_class = @event_class || (raise NotImplementedError, "You must define an event_class")
47
47
 
@@ -67,7 +67,7 @@ module Decidim
67
67
 
68
68
  def extra_info = { resource: { title: user.name } }
69
69
 
70
- def role_params = { role: form.role.to_sym, user:, role_class.new.target_space_association => participatory_space }
70
+ def role_params = { :role => form.role.to_sym, :user => user, role_class.new.target_space_association => participatory_space }
71
71
 
72
72
  def send_notification(user)
73
73
  Decidim::EventsManager.publish(
@@ -114,7 +114,7 @@ module Decidim
114
114
  current_user: user
115
115
  )
116
116
 
117
- Decidim::CreateFollow.new(form, user).call
117
+ Decidim::CreateFollow.new(form).call
118
118
  end
119
119
 
120
120
  def existing_user
@@ -7,14 +7,13 @@ module Decidim
7
7
  class ProcessParticipatorySpacePrivateUserImportCsv < Decidim::Command
8
8
  include Decidim::Admin::CustomImport
9
9
 
10
+ delegate :current_user, to: :form
10
11
  # Public: Initializes the command.
11
12
  #
12
13
  # form - the form object containing the uploaded file
13
- # current_user - the user performing the action
14
14
  # private_users_to - The private_users_to that will hold the user role
15
- def initialize(form, current_user, private_users_to)
15
+ def initialize(form, private_users_to)
16
16
  @form = form
17
- @current_user = current_user
18
17
  @private_users_to = private_users_to
19
18
  end
20
19
 
@@ -33,9 +32,11 @@ module Decidim
33
32
 
34
33
  private
35
34
 
35
+ attr_reader :form
36
+
36
37
  def process_csv
37
38
  process_import_file(@form.file) do |(email, user_name)|
38
- ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, @current_user) if email.present? && user_name.present?
39
+ ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, current_user) if email.present? && user_name.present?
39
40
  end
40
41
  end
41
42
  end
@@ -8,15 +8,14 @@ module Decidim
8
8
  # will be invited to the application and will lose the managed flag
9
9
  # so the user cannot be impersonated anymore.
10
10
  class PromoteManagedUser < Decidim::Command
11
+ delegate :current_user, to: :form
11
12
  # Public: Initializes the command.
12
13
  #
13
14
  # form - A form object with the params.
14
15
  # user - The user to promote
15
- # promoted_by - The user performing the operation
16
- def initialize(form, user, promoted_by)
16
+ def initialize(form, user)
17
17
  @form = form
18
18
  @user = user
19
- @promoted_by = promoted_by
20
19
  end
21
20
 
22
21
  # Executes the command. Broadcasts these events:
@@ -35,7 +34,7 @@ module Decidim
35
34
  broadcast(:ok)
36
35
  end
37
36
 
38
- attr_reader :form, :user, :promoted_by
37
+ attr_reader :form, :user
39
38
 
40
39
  private
41
40
 
@@ -46,7 +45,7 @@ module Decidim
46
45
  end
47
46
 
48
47
  def invite_user
49
- user.invite!(promoted_by)
48
+ user.invite!(current_user)
50
49
  end
51
50
 
52
51
  def email_already_exists?
@@ -15,7 +15,7 @@ module Decidim
15
15
 
16
16
  # Executes the command. Broadcasts these events:
17
17
  #
18
- # - :ok when the unofficialization suceeds.
18
+ # - :ok when the unofficialization succeeds.
19
19
  # - :invalid when the form is invalid.
20
20
  #
21
21
  # Returns nothing.
@@ -3,47 +3,8 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when updating an area.
6
- class UpdateArea < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # area - The Area to update
10
- # form - A form object with the params.
11
- def initialize(area, form)
12
- @area = area
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 was not valid and we could not proceed.
20
- #
21
- # Returns nothing.
22
- def call
23
- return broadcast(:invalid) if form.invalid?
24
-
25
- update_area
26
- broadcast(:ok)
27
- end
28
-
29
- private
30
-
31
- attr_reader :form
32
-
33
- def update_area
34
- Decidim.traceability.update!(
35
- @area,
36
- form.current_user,
37
- attributes
38
- )
39
- end
40
-
41
- def attributes
42
- {
43
- name: form.name,
44
- area_type: form.area_type
45
- }
46
- end
6
+ class UpdateArea < Decidim::Commands::UpdateResource
7
+ fetch_form_attributes :name, :area_type
47
8
  end
48
9
  end
49
10
  end
@@ -3,48 +3,8 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when updating an area type.
6
- class UpdateAreaType < Decidim::Command
7
- # Public: Initializes the command.
8
- #
9
- # area_type - The AreaType to update
10
- # form - A form object with the params.
11
- def initialize(area_type, form, user)
12
- @area_type = area_type
13
- @form = form
14
- @user = user
15
- end
16
-
17
- # Executes the command. Broadcasts these events:
18
- #
19
- # - :ok when everything is valid.
20
- # - :invalid if the form was not valid and we could not proceed.
21
- #
22
- # Returns nothing.
23
- def call
24
- return broadcast(:invalid) if form.invalid?
25
-
26
- update_area_type
27
- broadcast(:ok)
28
- end
29
-
30
- private
31
-
32
- attr_reader :form
33
-
34
- def update_area_type
35
- Decidim.traceability.update!(
36
- @area_type,
37
- @user,
38
- attributes
39
- )
40
- end
41
-
42
- def attributes
43
- {
44
- name: form.name,
45
- plural: form.plural
46
- }
47
- end
6
+ class UpdateAreaType < Decidim::Commands::UpdateResource
7
+ fetch_form_attributes :name, :plural
48
8
  end
49
9
  end
50
10
  end
@@ -9,14 +9,14 @@ module Decidim
9
9
 
10
10
  attr_reader :attachment
11
11
 
12
+ delegate :current_user, to: :form
12
13
  # Public: Initializes the command.
13
14
  #
14
15
  # attachment - the Attachment to update
15
16
  # form - A form object with the params.
16
- def initialize(attachment, form, user)
17
+ def initialize(attachment, form)
17
18
  @attachment = attachment
18
19
  @form = form
19
- @user = user
20
20
  end
21
21
 
22
22
  # Executes the command. Broadcasts these events:
@@ -37,20 +37,23 @@ module Decidim
37
37
  attr_reader :form
38
38
 
39
39
  def update_attachment
40
- Decidim.traceability.update!(@attachment, @user, attributes)
40
+ Decidim.traceability.update!(@attachment, current_user, attributes)
41
41
  end
42
42
 
43
43
  def attributes
44
44
  {
45
45
  title: form.title,
46
46
  file: form.file,
47
+ link: form.link,
47
48
  description: form.description,
48
- weight: form.weight,
49
- attachment_collection: form.attachment_collection
49
+ weight: form.weight
50
50
  }.merge(
51
51
  attachment_attributes(:file)
52
- ).reject do |attribute, value|
53
- value.blank? && attribute != :attachment_collection
52
+ ).compact_blank.merge(
53
+ attachment_collection: form.attachment_collection
54
+ ).tap do |attrs|
55
+ attrs[:file] = nil if form.link.present? && form.file.blank?
56
+ attrs[:link] = nil if form.file.present? && form.link.blank?
54
57
  end
55
58
  end
56
59
  end
@@ -4,14 +4,14 @@ module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when updating an attachment collection.
6
6
  class UpdateAttachmentCollection < Decidim::Command
7
+ delegate :current_user, to: :form
7
8
  # Public: Initializes the command.
8
9
  #
9
10
  # attachment_collection - The AttachmentCollection to update
10
11
  # form - A form object with the params.
11
- def initialize(attachment_collection, form, user)
12
+ def initialize(attachment_collection, form)
12
13
  @attachment_collection = attachment_collection
13
14
  @form = form
14
- @user = user
15
15
  end
16
16
 
17
17
  # Executes the command. Broadcasts these events:
@@ -34,7 +34,7 @@ module Decidim
34
34
  def update_attachment_collection
35
35
  Decidim.traceability.update!(
36
36
  @attachment_collection,
37
- @user,
37
+ current_user,
38
38
  attributes
39
39
  )
40
40
  end
@@ -4,51 +4,8 @@ module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic when updating a category in the
6
6
  # system.
7
- class UpdateCategory < Decidim::Command
8
- attr_reader :category
9
-
10
- # Public: Initializes the command.
11
- #
12
- # category - the Category to update
13
- # form - A form object with the params.
14
- def initialize(category, form, user)
15
- @category = category
16
- @form = form
17
- @user = user
18
- end
19
-
20
- # Executes the command. Broadcasts these events:
21
- #
22
- # - :ok when everything is valid.
23
- # - :invalid if the form was not valid and we could not proceed.
24
- #
25
- # Returns nothing.
26
- def call
27
- return broadcast(:invalid) if form.invalid?
28
-
29
- update_category
30
- broadcast(:ok)
31
- end
32
-
33
- private
34
-
35
- attr_reader :form
36
-
37
- def update_category
38
- Decidim.traceability.update!(
39
- category,
40
- @user,
41
- attributes
42
- )
43
- end
44
-
45
- def attributes
46
- {
47
- name: form.name,
48
- weight: form.weight,
49
- parent_id: form.parent_id
50
- }
51
- end
7
+ class UpdateCategory < Decidim::Commands::UpdateResource
8
+ fetch_form_attributes :name, :weight, :parent_id
52
9
  end
53
10
  end
54
11
  end
@@ -3,18 +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 UpdateComponent < Decidim::Command
6
+ class UpdateComponent < Decidim::Commands::UpdateResource
7
7
  attr_reader :form, :component, :previous_settings
8
8
 
9
9
  # Public: Initializes the command.
10
10
  #
11
11
  # form - The form from which the data in this component comes from.
12
12
  # component - The component to update.
13
- def initialize(form, component, user)
14
- @manifest = component.manifest
13
+ def initialize(form, component)
15
14
  @form = form
16
15
  @component = component
17
- @user = user
16
+ @manifest = component.manifest
18
17
  end
19
18
 
20
19
  # Public: Creates the Component.
@@ -23,7 +22,7 @@ module Decidim
23
22
  def call
24
23
  return broadcast(:invalid) if form.invalid?
25
24
 
26
- Decidim.traceability.perform_action!("update", @component, @user) do
25
+ Decidim.traceability.perform_action!("update", @component, form.current_user) do
27
26
  transaction do
28
27
  update_component
29
28
  run_hooks