decidim-admin 0.29.1 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/admin/multi_select_picker/show.erb +10 -0
  3. data/app/cells/decidim/admin/multi_select_picker_cell.rb +38 -0
  4. data/app/commands/decidim/admin/block_user.rb +1 -0
  5. data/app/commands/decidim/admin/bulk_action.rb +92 -0
  6. data/app/commands/decidim/admin/bulk_block_users.rb +75 -0
  7. data/app/commands/decidim/admin/bulk_unblock_users.rb +66 -0
  8. data/app/commands/decidim/admin/bulk_unreport_users.rb +69 -0
  9. data/app/commands/decidim/admin/content_blocks/update_content_block.rb +1 -1
  10. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +3 -1
  11. data/app/commands/decidim/admin/create_share_token.rb +39 -0
  12. data/app/commands/decidim/admin/create_taxonomy.rb +23 -0
  13. data/app/commands/decidim/admin/create_taxonomy_filter.rb +24 -0
  14. data/app/commands/decidim/admin/destroy_share_token.rb +22 -0
  15. data/app/commands/decidim/admin/destroy_taxonomy.rb +18 -0
  16. data/app/commands/decidim/admin/destroy_taxonomy_filter.rb +20 -0
  17. data/app/commands/decidim/admin/hide_menu_component.rb +37 -0
  18. data/app/commands/decidim/admin/hide_resource.rb +4 -2
  19. data/app/commands/decidim/admin/publish_all_participatory_space_private_users.rb +50 -0
  20. data/app/commands/decidim/admin/publish_component.rb +3 -0
  21. data/app/commands/decidim/admin/reorder_components.rb +47 -0
  22. data/app/commands/decidim/admin/reorder_taxonomies.rb +76 -0
  23. data/app/commands/decidim/admin/unhide_resource.rb +11 -3
  24. data/app/commands/decidim/admin/unpublish_all_participatory_space_private_users.rb +50 -0
  25. data/app/commands/decidim/admin/unreport_resource.rb +11 -3
  26. data/app/commands/decidim/admin/update_component_permissions.rb +53 -13
  27. data/app/commands/decidim/admin/update_participatory_space_private_user.rb +11 -0
  28. data/app/commands/decidim/admin/update_share_token.rb +24 -0
  29. data/app/commands/decidim/admin/update_taxonomy.rb +20 -0
  30. data/app/commands/decidim/admin/update_taxonomy_filter.rb +28 -0
  31. data/app/controllers/concerns/decidim/admin/component_taxonomies_helper.rb +19 -0
  32. data/app/controllers/concerns/decidim/admin/filterable.rb +15 -18
  33. data/app/controllers/concerns/decidim/admin/has_trashable_resources.rb +170 -0
  34. data/app/controllers/concerns/decidim/admin/needs_admin_tos_accepted.rb +2 -29
  35. data/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb +12 -2
  36. data/app/controllers/concerns/decidim/admin/taxonomies/filterable.rb +27 -0
  37. data/app/controllers/decidim/admin/application_controller.rb +1 -2
  38. data/app/controllers/decidim/admin/areas_controller.rb +1 -0
  39. data/app/controllers/decidim/admin/block_user_controller.rb +43 -1
  40. data/app/controllers/decidim/admin/component_permissions_controller.rb +2 -4
  41. data/app/controllers/decidim/admin/components_controller.rb +50 -9
  42. data/app/controllers/decidim/admin/concerns/has_private_users.rb +59 -2
  43. data/app/controllers/decidim/admin/conflicts_controller.rb +1 -1
  44. data/app/controllers/decidim/admin/global_moderations_controller.rb +4 -0
  45. data/app/controllers/decidim/admin/impersonations_controller.rb +1 -0
  46. data/app/controllers/decidim/admin/moderated_users_controller.rb +26 -0
  47. data/app/controllers/decidim/admin/moderations_controller.rb +18 -0
  48. data/app/controllers/decidim/admin/newsletters_controller.rb +50 -6
  49. data/app/controllers/decidim/admin/resource_permissions_controller.rb +1 -1
  50. data/app/controllers/decidim/admin/scopes_controller.rb +1 -0
  51. data/app/controllers/decidim/admin/share_tokens_controller.rb +109 -7
  52. data/app/controllers/decidim/admin/taxonomies_controller.rb +129 -0
  53. data/app/controllers/decidim/admin/taxonomy_filters_controller.rb +112 -0
  54. data/app/controllers/decidim/admin/taxonomy_filters_selector_controller.rb +81 -0
  55. data/app/controllers/decidim/admin/taxonomy_items_controller.rb +91 -0
  56. data/app/forms/concerns/decidim/has_taxonomy_form_attributes.rb +57 -0
  57. data/app/forms/decidim/admin/block_users_form.rb +21 -0
  58. data/app/forms/decidim/admin/help_section_form.rb +1 -1
  59. data/app/forms/decidim/admin/impersonate_user_form.rb +5 -0
  60. data/app/forms/decidim/admin/import_example_form.rb +1 -1
  61. data/app/forms/decidim/admin/newsletter_form.rb +1 -1
  62. data/app/forms/decidim/admin/organization_appearance_form.rb +2 -2
  63. data/app/forms/decidim/admin/organization_form.rb +2 -2
  64. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +5 -0
  65. data/app/forms/decidim/admin/selective_newsletter_form.rb +46 -11
  66. data/app/forms/decidim/admin/share_token_form.rb +55 -0
  67. data/app/forms/decidim/admin/static_page_form.rb +1 -1
  68. data/app/forms/decidim/admin/taxonomy_filter_form.rb +85 -0
  69. data/app/forms/decidim/admin/taxonomy_form.rb +20 -0
  70. data/app/forms/decidim/admin/taxonomy_item_form.rb +54 -0
  71. data/app/forms/decidim/admin/transfer_user_form.rb +15 -0
  72. data/app/helpers/decidim/admin/application_helper.rb +0 -1
  73. data/app/helpers/decidim/admin/bulk_actions_helper.rb +0 -31
  74. data/app/helpers/decidim/admin/moderations/reports_helper.rb +1 -1
  75. data/app/helpers/decidim/admin/moderations_helper.rb +1 -1
  76. data/app/helpers/decidim/admin/newsletters_helper.rb +57 -27
  77. data/app/helpers/decidim/admin/scopes_helper.rb +0 -6
  78. data/app/helpers/decidim/admin/search_form_helper.rb +1 -1
  79. data/app/helpers/decidim/admin/settings_helper.rb +85 -11
  80. data/app/jobs/decidim/admin/newsletter_job.rb +3 -1
  81. data/app/packs/entrypoints/decidim_admin.js +4 -0
  82. data/app/packs/src/decidim/admin/application.js +2 -0
  83. data/app/packs/src/decidim/admin/draggable-table.js +33 -0
  84. data/app/packs/src/decidim/admin/form.js +0 -1
  85. data/app/packs/src/decidim/admin/global_moderations.js +186 -0
  86. data/app/packs/src/decidim/admin/managed_moderated_users.js +186 -0
  87. data/app/packs/src/decidim/admin/newsletters.js +164 -73
  88. data/app/packs/src/decidim/admin/proposal_infinite_edit.js +3 -6
  89. data/app/packs/src/decidim/admin/sortable.js +28 -16
  90. data/app/packs/src/decidim/admin/taxonomy_filters.js +93 -0
  91. data/app/packs/stylesheets/decidim/admin/_component-show.scss +66 -5
  92. data/app/packs/stylesheets/decidim/admin/_legacy_foundation.scss +13 -0
  93. data/app/packs/stylesheets/decidim/admin/_moderations.scss +8 -0
  94. data/app/packs/stylesheets/decidim/admin/_select_picker.scss +20 -0
  95. data/app/packs/stylesheets/decidim/admin/_table-list.scss +22 -0
  96. data/app/packs/stylesheets/decidim/admin/_taxonomies.scss +74 -0
  97. data/app/packs/stylesheets/decidim/admin/application.scss +3 -0
  98. data/app/permissions/decidim/admin/permissions.rb +32 -1
  99. data/app/queries/decidim/admin/newsletter_recipients.rb +59 -19
  100. data/app/views/decidim/admin/areas/index.html.erb +3 -0
  101. data/app/views/decidim/admin/block_user/bulk_new.html.erb +45 -0
  102. data/app/views/decidim/admin/components/_actions.html.erb +50 -33
  103. data/app/views/decidim/admin/components/{_component.html.erb → _component_row.html.erb} +10 -5
  104. data/app/views/decidim/admin/components/_components_table.html.erb +18 -0
  105. data/app/views/decidim/admin/components/_form.html.erb +0 -12
  106. data/app/views/decidim/admin/components/_taxonomy_filters_drawer.html.erb +2 -0
  107. data/app/views/decidim/admin/components/_visibility_label.html.erb +9 -0
  108. data/app/views/decidim/admin/components/index.html.erb +12 -14
  109. data/app/views/decidim/admin/components/manage_trash.html.erb +11 -0
  110. data/app/views/decidim/admin/conflicts/edit.html.erb +21 -11
  111. data/app/views/decidim/admin/moderated_users/_bulk-actions.html.erb +6 -0
  112. data/app/views/decidim/admin/moderated_users/bulk_actions/_block.html.erb +20 -0
  113. data/app/views/decidim/admin/moderated_users/bulk_actions/_dropdown.html.erb +40 -0
  114. data/app/views/decidim/admin/moderated_users/bulk_actions/_unblock.html.erb +20 -0
  115. data/app/views/decidim/admin/moderated_users/bulk_actions/_unreport.html.erb +20 -0
  116. data/app/views/decidim/admin/moderated_users/index.html.erb +15 -7
  117. data/app/views/decidim/admin/moderations/_bulk-actions.html.erb +7 -0
  118. data/app/views/decidim/admin/moderations/_moderation-tr.html.erb +50 -0
  119. data/app/views/decidim/admin/moderations/_moderations-thead.html.erb +18 -0
  120. data/app/views/decidim/admin/moderations/bulk_actions/_dropdown.html.erb +43 -0
  121. data/app/views/decidim/admin/moderations/bulk_actions/_hide.html.erb +20 -0
  122. data/app/views/decidim/admin/moderations/bulk_actions/_unhide.html.erb +20 -0
  123. data/app/views/decidim/admin/moderations/bulk_actions/_unreport.html.erb +20 -0
  124. data/app/views/decidim/admin/moderations/index.html.erb +13 -81
  125. data/app/views/decidim/admin/newsletter_templates/index.html.erb +0 -1
  126. data/app/views/decidim/admin/newsletters/confirm_recipients.html.erb +64 -0
  127. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +44 -20
  128. data/app/views/decidim/admin/participatory_space_private_users/_form.html.erb +6 -0
  129. data/app/views/decidim/admin/participatory_space_private_users/edit.html.erb +19 -0
  130. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +15 -1
  131. data/app/views/decidim/admin/resource_permissions/_options_form.html.erb +5 -0
  132. data/app/views/decidim/admin/resource_permissions/edit.html.erb +2 -2
  133. data/app/views/decidim/admin/scope_types/index.html.erb +3 -0
  134. data/app/views/decidim/admin/scopes/index.html.erb +3 -0
  135. data/app/views/decidim/admin/share_tokens/_form.html.erb +52 -0
  136. data/app/views/decidim/admin/share_tokens/edit.html.erb +33 -0
  137. data/app/views/decidim/admin/share_tokens/index.html.erb +47 -0
  138. data/app/views/decidim/admin/share_tokens/new.html.erb +69 -0
  139. data/app/views/decidim/admin/shared/landing_page_content_blocks/edit.html.erb +1 -1
  140. data/app/views/decidim/admin/taxonomies/_filters.html.erb +19 -0
  141. data/app/views/decidim/admin/taxonomies/_form.html.erb +5 -0
  142. data/app/views/decidim/admin/taxonomies/_row.html.erb +40 -0
  143. data/app/views/decidim/admin/taxonomies/_row_children.html.erb +8 -0
  144. data/app/views/decidim/admin/taxonomies/_table.html.erb +86 -0
  145. data/app/views/decidim/admin/taxonomies/_taxonomy_actions.html.erb +15 -0
  146. data/app/views/decidim/admin/taxonomies/edit.html.erb +87 -0
  147. data/app/views/decidim/admin/taxonomies/index.html.erb +28 -0
  148. data/app/views/decidim/admin/taxonomies/new.html.erb +16 -0
  149. data/app/views/decidim/admin/taxonomy_filters/_check_boxes.html.erb +10 -0
  150. data/app/views/decidim/admin/taxonomy_filters/_form.html.erb +96 -0
  151. data/app/views/decidim/admin/taxonomy_filters/_table.html.erb +33 -0
  152. data/app/views/decidim/admin/taxonomy_filters/edit.html.erb +22 -0
  153. data/app/views/decidim/admin/taxonomy_filters/index.html.erb +26 -0
  154. data/app/views/decidim/admin/taxonomy_filters/new.html.erb +32 -0
  155. data/app/views/decidim/admin/taxonomy_filters_selector/_check_boxes.html.erb +7 -0
  156. data/app/views/decidim/admin/taxonomy_filters_selector/_component_table.html.erb +25 -0
  157. data/app/views/decidim/admin/taxonomy_filters_selector/_taxonomies_select.html.erb +16 -0
  158. data/app/views/decidim/admin/taxonomy_filters_selector/index.html.erb +1 -0
  159. data/app/views/decidim/admin/taxonomy_filters_selector/new.html.erb +27 -0
  160. data/app/views/decidim/admin/taxonomy_filters_selector/show.html.erb +18 -0
  161. data/app/views/decidim/admin/taxonomy_items/_form.html.erb +8 -0
  162. data/app/views/decidim/admin/taxonomy_items/edit.html.erb +12 -0
  163. data/app/views/decidim/admin/taxonomy_items/new.html.erb +12 -0
  164. data/app/views/layouts/decidim/admin/taxonomy_filters.html.erb +17 -0
  165. data/app/views/layouts/decidim/admin/taxonomy_filters_selector.html.erb +10 -0
  166. data/config/locales/ar.yml +91 -36
  167. data/config/locales/bg.yml +48 -51
  168. data/config/locales/bn-BD.yml +1 -0
  169. data/config/locales/bs-BA.yml +499 -0
  170. data/config/locales/ca.yml +300 -50
  171. data/config/locales/cs.yml +298 -46
  172. data/config/locales/de.yml +300 -50
  173. data/config/locales/el.yml +1 -50
  174. data/config/locales/en.yml +300 -50
  175. data/config/locales/es-MX.yml +298 -48
  176. data/config/locales/es-PY.yml +298 -48
  177. data/config/locales/es.yml +298 -48
  178. data/config/locales/eu.yml +433 -171
  179. data/config/locales/fi-plain.yml +298 -48
  180. data/config/locales/fi.yml +315 -65
  181. data/config/locales/fr-CA.yml +183 -47
  182. data/config/locales/fr.yml +183 -47
  183. data/config/locales/ga-IE.yml +0 -23
  184. data/config/locales/gl.yml +1 -46
  185. data/config/locales/hu.yml +1 -51
  186. data/config/locales/id-ID.yml +0 -20
  187. data/config/locales/is-IS.yml +0 -18
  188. data/config/locales/it.yml +1 -46
  189. data/config/locales/ja.yml +303 -55
  190. data/config/locales/kaa.yml +0 -10
  191. data/config/locales/ko.yml +0 -50
  192. data/config/locales/lb.yml +1 -46
  193. data/config/locales/lt.yml +1 -50
  194. data/config/locales/lv.yml +1 -27
  195. data/config/locales/nl.yml +1 -46
  196. data/config/locales/no.yml +1 -46
  197. data/config/locales/pl.yml +3 -51
  198. data/config/locales/pt-BR.yml +38 -50
  199. data/config/locales/pt.yml +30 -46
  200. data/config/locales/ro-RO.yml +35 -50
  201. data/config/locales/ru.yml +1 -22
  202. data/config/locales/sk.yml +1 -27
  203. data/config/locales/sl.yml +0 -7
  204. data/config/locales/sq-AL.yml +0 -25
  205. data/config/locales/sr-CS.yml +1 -27
  206. data/config/locales/sv.yml +297 -47
  207. data/config/locales/tr-TR.yml +1 -44
  208. data/config/locales/uk.yml +0 -20
  209. data/config/locales/zh-CN.yml +0 -44
  210. data/config/locales/zh-TW.yml +1 -50
  211. data/config/routes.rb +14 -13
  212. data/decidim-admin.gemspec +2 -2
  213. data/lib/decidim/admin/engine.rb +3 -1
  214. data/lib/decidim/admin/import/creator.rb +2 -6
  215. data/lib/decidim/admin/import/readers/json.rb +1 -1
  216. data/lib/decidim/admin/menu.rb +9 -1
  217. data/lib/decidim/admin/search_form_builder.rb +1 -1
  218. data/lib/decidim/admin/test/destroy_admin_examples.rb +2 -2
  219. data/lib/decidim/admin/test/filterable_examples.rb +100 -9
  220. data/lib/decidim/admin/test/forms/attachment_collection_form_examples.rb +1 -1
  221. data/lib/decidim/admin/test/forms/attachment_form_examples.rb +1 -1
  222. data/lib/decidim/admin/test/invite_participatory_space_admins_shared_examples.rb +2 -4
  223. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +5 -5
  224. data/lib/decidim/admin/test/manage_hide_content_examples.rb +0 -1
  225. data/lib/decidim/admin/test/manage_moderations_examples.rb +3 -3
  226. data/lib/decidim/admin/test/manage_resource_soft_deletion_examples.rb +113 -0
  227. data/lib/decidim/admin/test/manage_taxonomy_filters_examples.rb +127 -0
  228. data/lib/decidim/admin/test/taxonomy_filters_examples.rb +32 -0
  229. data/lib/decidim/admin/test.rb +3 -1
  230. data/lib/decidim/admin/version.rb +1 -1
  231. metadata +106 -30
  232. data/app/commands/decidim/admin/create_category.rb +0 -15
  233. data/app/commands/decidim/admin/destroy_category.rb +0 -15
  234. data/app/commands/decidim/admin/destroy_component.rb +0 -19
  235. data/app/commands/decidim/admin/update_category.rb +0 -11
  236. data/app/controllers/decidim/admin/categories_controller.rb +0 -98
  237. data/app/forms/decidim/admin/category_form.rb +0 -32
  238. data/app/helpers/decidim/admin/resource_scope_helper.rb +0 -52
  239. data/app/packs/src/decidim/admin/scope_picker_enabler.component.js +0 -12
  240. data/app/views/decidim/admin/categories/_form.html.erb +0 -18
  241. data/app/views/decidim/admin/categories/edit.html.erb +0 -19
  242. data/app/views/decidim/admin/categories/index.html.erb +0 -65
  243. data/app/views/decidim/admin/categories/new.html.erb +0 -19
  244. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +0 -45
  245. data/lib/decidim/admin/test/commands/create_category_examples.rb +0 -74
  246. data/lib/decidim/admin/test/commands/destroy_category_examples.rb +0 -83
  247. data/lib/decidim/admin/test/commands/update_category_examples.rb +0 -76
  248. data/lib/decidim/admin/test/forms/category_form_examples.rb +0 -70
  249. data/lib/decidim/admin/test/manage_categories_examples.rb +0 -128
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f285a47f80f5bdf3a2d992daab51c9945cbccd2c6f714ca15b2529b8923e79
4
- data.tar.gz: 8f4965b0ee06c4d6b5fa74418e52d36f03fe239da058d67927b713955e1211d4
3
+ metadata.gz: 48272c228554c612efad0837403c06e2955c0a5a71df4b1f57ef0b9d12d986c6
4
+ data.tar.gz: bfd117609106eb1d64f292a6b2e84cc524c7c9dab2bfa3dce05bc8ddfe44408a
5
5
  SHA512:
6
- metadata.gz: ef1df3729f97261f2a3164eff704c5d503e6a4731daf5e5d586476c64f5f0eb4409234e107f82ce972ce1b2f697685e940d420c6d3d3ebc43d39db579c459540
7
- data.tar.gz: 6e21939582031fc8774833fbed42bf22647dc359b1e5fffe983e593092e89ad2959ebe94042602ac3ba32e0b2f7f61ff8c1ac8c9db3862884e88d3cad8e99e8f
6
+ metadata.gz: 9af4afad6391f293b4b3a1a8fd6b3bb262b1da9bda95b8cbadb0a43236475b0ba3a615315278d7da8e750dbe2a1d9a76e30f513cbb4993c580e83dd08b2123de
7
+ data.tar.gz: 57fad1f9f4ff5488fd0f5d35d2aff8105f7c7e37cb66dbf6da69a577e74567b11c037a88f82be3b4dc0834d505e2248ec8697ada0a42a02c15f3dbd956789ea6
@@ -0,0 +1,10 @@
1
+ <%= select_tag field_name,
2
+ options_for_select(
3
+ cell_options_for_select.map { |option| [option[0], option[1]] },
4
+ selected_values
5
+ ),
6
+ id: select_id,
7
+ class: css_classes,
8
+ placeholder:,
9
+ multiple: true,
10
+ data: { multiselect: true } %>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Universal cell for rendering multi-select pickers
6
+ class MultiSelectPickerCell < Decidim::ViewModel
7
+ include ActionView::Helpers::FormOptionsHelper
8
+
9
+ def show
10
+ render :show
11
+ end
12
+
13
+ def cell_options_for_select
14
+ context[:options_for_select] || []
15
+ end
16
+
17
+ def selected_values
18
+ context[:selected_values] || []
19
+ end
20
+
21
+ def select_id
22
+ context[:select_id]
23
+ end
24
+
25
+ def field_name
26
+ context[:field_name]
27
+ end
28
+
29
+ def placeholder
30
+ context[:placeholder] || ""
31
+ end
32
+
33
+ def css_classes
34
+ context[:class] || ""
35
+ end
36
+ end
37
+ end
38
+ end
@@ -77,6 +77,7 @@ 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"
80
81
  form.user.save!
81
82
  end
82
83
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class BulkAction < Decidim::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # current_user - the user that performs the action
9
+ # action - can be hide, unhide and unreport resources
10
+ # selected_moderations - all resources selected by current_user
11
+ def initialize(current_user, action, selected_moderations)
12
+ @current_user = current_user
13
+ @action = action
14
+ @selected_moderations = selected_moderations
15
+ @result = { ok: [], ko: [] }
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid, together with the resource.
21
+ # - :invalid if the resource is not reported
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if selected_moderations.blank?
26
+
27
+ process_reportables
28
+ create_action_log if selected_moderations.first.reportable
29
+
30
+ broadcast(:ok, **result)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :action, :selected_moderations, :current_user, :result, :with_admin_log
36
+
37
+ def create_action_log
38
+ action_log_type = "bulk_#{action}"
39
+
40
+ Decidim::ActionLogger.log(
41
+ action_log_type,
42
+ current_user,
43
+ selected_moderations.first,
44
+ nil,
45
+ extra: {
46
+ reported_content:,
47
+ reported_count: result[:ok].count
48
+ }
49
+ )
50
+ end
51
+
52
+ def reported_content
53
+ @reported_content ||= result[:ok].group_by(&:decidim_reportable_type).to_h do |klass, moderations|
54
+ [
55
+ klass.split("::").last.downcase.pluralize,
56
+ moderations.to_h { |moderation| [moderation.reportable.id, moderation.title] }
57
+ ]
58
+ end
59
+ end
60
+
61
+ def process_reportables
62
+ selected_moderations.each do |moderation|
63
+ next unless moderation
64
+
65
+ if moderation.respond_to?(:organization) && moderation.organization != current_user.organization
66
+ result[:ko] << moderation
67
+ next
68
+ end
69
+ command.call(moderation.reportable, current_user, with_admin_log: false) do
70
+ on(:ok) do
71
+ result[:ok] << moderation
72
+ end
73
+ on(:invalid) do
74
+ result[:ko] << moderation
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def command
81
+ case action
82
+ when "hide"
83
+ Admin::HideResource
84
+ when "unreport"
85
+ Admin::UnreportResource
86
+ when "unhide"
87
+ Admin::UnhideResource
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class BulkBlockUsers < Decidim::Command
6
+ # Public: Initializes the command.
7
+ def initialize(form)
8
+ @form = form
9
+ @result = { ok: [], ko: [] }
10
+ end
11
+
12
+ # Executes the command. Broadcasts these events:
13
+ #
14
+ # - :ok when everything is valid, together with the resource.
15
+ # - :invalid if the resource is not reported
16
+ #
17
+ # Returns nothing.
18
+ def call
19
+ return broadcast(:invalid) unless form.valid?
20
+
21
+ block_all_users!
22
+ create_action_log if first_blocked
23
+
24
+ broadcast(:ok, **result)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :form, :result, :first_blocked
30
+
31
+ def create_action_log
32
+ Decidim::ActionLogger.log(
33
+ "bulk_block",
34
+ form.current_user,
35
+ first_blocked,
36
+ nil,
37
+ extra: {
38
+ blocked:,
39
+ reportable_type: first_blocked.class.name,
40
+ current_justification: form.justification
41
+ }
42
+ )
43
+ end
44
+
45
+ def blocked
46
+ @blocked ||= result[:ok].to_h { |user| [user.id, user.extended_data["user_name"]] }
47
+ end
48
+
49
+ def block_all_users!
50
+ form.users.each do |user|
51
+ transaction do
52
+ Decidim::UserModeration.find_or_create_by!(user:)
53
+
54
+ @current_blocking = UserBlock.create!(
55
+ justification: form.justification,
56
+ user:,
57
+ blocking_user: form.current_user
58
+ )
59
+
60
+ user.blocked = true
61
+ user.blocked_at = Time.current
62
+ user.block_id = @current_blocking.id
63
+ user.extended_data["user_name"] = user.name
64
+ user.name = "Blocked user"
65
+ user.save!
66
+ end
67
+ result[:ok] << user
68
+ @first_blocked ||= user
69
+ rescue ActiveRecord::RecordInvalid
70
+ result[:ko] << user
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class BulkUnblockUsers < Decidim::Command
6
+ # Public: Initializes the command.
7
+ def initialize(blocked_users, current_user)
8
+ @blocked_users = blocked_users
9
+ @current_user = current_user
10
+ @result = { ok: [], ko: [] }
11
+ end
12
+
13
+ # Executes the command. Broadcasts these events:
14
+ #
15
+ # - :ok when everything is valid, together with the resource.
16
+ # - :invalid if the resource is not reported
17
+ #
18
+ # Returns nothing.
19
+ def call
20
+ return broadcast(:invalid) if blocked_users.blank?
21
+
22
+ unblock_users!
23
+ create_action_log if first_unblocked
24
+
25
+ broadcast(:ok, **result)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :current_user, :blocked_users, :result, :first_unblocked
31
+
32
+ def create_action_log
33
+ Decidim::ActionLogger.log(
34
+ "bulk_unblock",
35
+ current_user,
36
+ first_unblocked,
37
+ nil,
38
+ extra: {
39
+ unblocked:,
40
+ reportable_type: first_unblocked.class.name
41
+ }
42
+ )
43
+ end
44
+
45
+ def unblocked
46
+ @unblocked ||= result[:ok].to_h { |blocked_user| [blocked_user.id, blocked_user.extended_data["user_name"]] }
47
+ end
48
+
49
+ def unblock_users!
50
+ blocked_users.each do |blocked_user|
51
+ transaction do
52
+ blocked_user.blocked = false
53
+ blocked_user.blocked_at = nil
54
+ blocked_user.block_id = nil
55
+ blocked_user.name = blocked_user.extended_data["user_name"]
56
+ blocked_user.save!
57
+ end
58
+ result[:ok] << blocked_user
59
+ @first_unblocked ||= blocked_user
60
+ rescue ActiveRecord::RecordInvalid
61
+ result[:ko] << blocked_user
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class BulkUnreportUsers < Decidim::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # current_user - the user that performs the action
9
+ # reportables - all Decidim::Reportable selected by current_user
10
+ def initialize(current_user, reportables)
11
+ @current_user = current_user
12
+ @reportables = reportables
13
+ @result = { ok: [], ko: [] }
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid, together with the resource.
19
+ # - :invalid if the resource is not reported
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid) if reportables.blank?
24
+
25
+ bulk_unreport_users!
26
+ create_action_log if first_unreported
27
+
28
+ broadcast(:ok, **result)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :reportables, :current_user, :result, :first_unreported
34
+
35
+ def create_action_log
36
+ Decidim::ActionLogger.log(
37
+ "bulk_ignore",
38
+ current_user,
39
+ first_unreported,
40
+ nil,
41
+ extra: {
42
+ unreported:,
43
+ reportable_type: first_unreported.class.name
44
+ }
45
+ )
46
+ end
47
+
48
+ def unreported
49
+ @unreported ||= result[:ok].to_h { |reportable| [reportable.id, reportable.name] }
50
+ end
51
+
52
+ def bulk_unreport_users!
53
+ reportables.each do |reportable|
54
+ next unless reportable
55
+
56
+ if reportable.respond_to?(:organization) && reportable.organization != current_user.organization
57
+ result[:ok] << reportable
58
+ next
59
+ end
60
+ reportable.user_moderation.destroy!
61
+ result[:ok] << reportable
62
+ @first_unreported ||= reportable
63
+ rescue ActiveRecord::RecordInvalid
64
+ result[:ko] << reportable
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -70,7 +70,7 @@ module Decidim
70
70
 
71
71
  if form.images[image_name]
72
72
  content_block.images_container.send("#{image_name}=", form.images[image_name])
73
- elsif form.images["remove_#{image_name}".to_sym] == "1"
73
+ elsif form.images[:"remove_#{image_name}"] == "1"
74
74
  content_block.images_container.send("#{image_name}=", nil)
75
75
  end
76
76
  end
@@ -53,7 +53,9 @@ module Decidim
53
53
  ) do
54
54
  Decidim::ParticipatorySpacePrivateUser.find_or_create_by!(
55
55
  user:,
56
- privatable_to: @private_user_to
56
+ privatable_to: @private_user_to,
57
+ role: form.role,
58
+ published: form.published
57
59
  )
58
60
  end
59
61
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to create a share token.
6
+ # This command is called from the controller.
7
+ class CreateShareToken < Decidim::Commands::CreateResource
8
+ fetch_form_attributes :token, :expires_at, :registered_only, :organization, :user, :token_for
9
+
10
+ protected
11
+
12
+ def resource_class = Decidim::ShareToken
13
+
14
+ def extra_params
15
+ {
16
+ participatory_space: {
17
+ title: participatory_space&.title
18
+ },
19
+ resource: {
20
+ title: component&.name
21
+ }
22
+ }
23
+ end
24
+
25
+ def participatory_space
26
+ return form.token_for if form.token_for.try(:manifest).is_a?(Decidim::ParticipatorySpaceManifest)
27
+ return current_participatory_space if respond_to?(:current_participatory_space)
28
+
29
+ component&.participatory_space
30
+ end
31
+
32
+ def component
33
+ return form.token_for if form.token_for.is_a?(Decidim::Component)
34
+
35
+ form.token_for.try(:component)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to create a taxonomy.
6
+ # This command is called from the controller.
7
+ class CreateTaxonomy < Decidim::Commands::CreateResource
8
+ fetch_form_attributes :name, :organization, :parent_id
9
+
10
+ protected
11
+
12
+ def resource_class = Decidim::Taxonomy
13
+
14
+ def extra_params
15
+ {
16
+ extra: {
17
+ parent_name: form.try(:parent).try(:name)
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to create a new taxonomy filter in the
6
+ # system.
7
+ class CreateTaxonomyFilter < Decidim::Commands::CreateResource
8
+ fetch_form_attributes :root_taxonomy_id, :filter_items, :internal_name, :name, :participatory_space_manifests
9
+
10
+ protected
11
+
12
+ def resource_class = Decidim::TaxonomyFilter
13
+
14
+ def extra_params
15
+ {
16
+ extra: {
17
+ taxonomy_name: form.root_taxonomy.name,
18
+ filter_items_count: form.filter_items.count
19
+ }
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to destroy a share token.
6
+ # This command is called from the controller.
7
+ class DestroyShareToken < Decidim::Commands::DestroyResource
8
+ delegate :participatory_space, :component, to: :resource
9
+
10
+ def extra_params
11
+ {
12
+ participatory_space: {
13
+ title: participatory_space&.title
14
+ },
15
+ resource: {
16
+ title: component&.name
17
+ }
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to destroy a taxonomy.
6
+ class DestroyTaxonomy < Decidim::Commands::DestroyResource
7
+ private
8
+
9
+ def extra_params
10
+ {
11
+ extra: {
12
+ parent_name: resource.parent.try(:name)
13
+ }
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to destroy a taxonomy in the
6
+ # system.
7
+ class DestroyTaxonomyFilter < Decidim::Commands::DestroyResource
8
+ private
9
+
10
+ def extra_params
11
+ {
12
+ extra: {
13
+ taxonomy_name: resource.root_taxonomy.name,
14
+ filter_items_count: resource.try(:filter_items_count)
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This command gets called when a component is marked as not visible (hidden) in the menu from the admin panel.
6
+ class HideMenuComponent < Decidim::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # component - The component to publish.
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: Publishes the Component.
17
+ #
18
+ # Broadcasts :ok if disabled visibility, :invalid otherwise.
19
+ def call
20
+ Decidim.traceability.perform_action!(
21
+ :menu_hidden,
22
+ component,
23
+ current_user,
24
+ visibility: "all"
25
+ ) do
26
+ component.update!(visible: false)
27
+ end
28
+
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :component, :current_user
35
+ end
36
+ end
37
+ end
@@ -8,9 +8,11 @@ module Decidim
8
8
  #
9
9
  # reportable - A Decidim::Reportable
10
10
  # current_user - the user that performs the action
11
- def initialize(reportable, current_user)
11
+ # with_admin_log Boolean - determines whether to log the action of hiding a resource in the admin log
12
+ def initialize(reportable, current_user, with_admin_log: true)
12
13
  @reportable = reportable
13
14
  @current_user = current_user
15
+ @with_admin_log = with_admin_log
14
16
  end
15
17
 
16
18
  # Executes the command. Broadcasts these events:
@@ -24,7 +26,7 @@ module Decidim
24
26
 
25
27
  with_events do
26
28
  tool = Decidim::ModerationTools.new(@reportable, @current_user)
27
- tool.hide!
29
+ @with_admin_log ? tool.hide_with_admin_log! : tool.hide!
28
30
  tool.send_notification_to_author
29
31
  end
30
32
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class PublishAllParticipatorySpacePrivateUsers < Decidim::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # participatory_space - the participatory space
9
+ # current_user - the current user
10
+ def initialize(participatory_space, current_user)
11
+ @participatory_space = participatory_space
12
+ @current_user = current_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
+ publish_all
23
+ create_action_log
24
+ broadcast(:ok)
25
+ rescue ActiveRecord::RecordInvalid
26
+ broadcast(:invalid)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :participatory_space, :current_user
32
+
33
+ def publish_all
34
+ # rubocop:disable Rails/SkipsModelValidations
35
+ # Using update_all for performance reasons
36
+ participatory_space.participatory_space_private_users.update_all(published: true)
37
+ # rubocop:enable Rails/SkipsModelValidations
38
+ end
39
+
40
+ def create_action_log
41
+ Decidim.traceability.perform_action!(
42
+ "publish_all_members",
43
+ participatory_space,
44
+ current_user,
45
+ private_users_ids: participatory_space.participatory_space_private_users.pluck(:id)
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
@@ -35,6 +35,9 @@ module Decidim
35
35
  visibility: "all"
36
36
  ) do
37
37
  component.publish!
38
+ component.update!(
39
+ visible: true
40
+ )
38
41
  component
39
42
  end
40
43
  end