decidim-admin 0.29.2 → 0.30.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) 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/bulk_action.rb +92 -0
  5. data/app/commands/decidim/admin/bulk_block_users.rb +75 -0
  6. data/app/commands/decidim/admin/bulk_unblock_users.rb +66 -0
  7. data/app/commands/decidim/admin/bulk_unreport_users.rb +69 -0
  8. data/app/commands/decidim/admin/content_blocks/update_content_block.rb +1 -1
  9. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +3 -1
  10. data/app/commands/decidim/admin/create_share_token.rb +39 -0
  11. data/app/commands/decidim/admin/create_taxonomy.rb +23 -0
  12. data/app/commands/decidim/admin/create_taxonomy_filter.rb +24 -0
  13. data/app/commands/decidim/admin/destroy_share_token.rb +22 -0
  14. data/app/commands/decidim/admin/destroy_taxonomy.rb +18 -0
  15. data/app/commands/decidim/admin/destroy_taxonomy_filter.rb +20 -0
  16. data/app/commands/decidim/admin/hide_menu_component.rb +37 -0
  17. data/app/commands/decidim/admin/hide_resource.rb +4 -3
  18. data/app/commands/decidim/admin/publish_all_participatory_space_private_users.rb +50 -0
  19. data/app/commands/decidim/admin/publish_component.rb +3 -0
  20. data/app/commands/decidim/admin/reorder_components.rb +47 -0
  21. data/app/commands/decidim/admin/reorder_taxonomies.rb +76 -0
  22. data/app/commands/decidim/admin/unhide_resource.rb +11 -3
  23. data/app/commands/decidim/admin/unpublish_all_participatory_space_private_users.rb +50 -0
  24. data/app/commands/decidim/admin/unreport_resource.rb +11 -3
  25. data/app/commands/decidim/admin/update_component_permissions.rb +53 -13
  26. data/app/commands/decidim/admin/update_participatory_space_private_user.rb +11 -0
  27. data/app/commands/decidim/admin/update_share_token.rb +24 -0
  28. data/app/commands/decidim/admin/update_taxonomy.rb +20 -0
  29. data/app/commands/decidim/admin/update_taxonomy_filter.rb +28 -0
  30. data/app/controllers/concerns/decidim/admin/component_taxonomies_helper.rb +19 -0
  31. data/app/controllers/concerns/decidim/admin/filterable.rb +15 -18
  32. data/app/controllers/concerns/decidim/admin/has_trashable_resources.rb +170 -0
  33. data/app/controllers/concerns/decidim/admin/needs_admin_tos_accepted.rb +2 -29
  34. data/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb +12 -2
  35. data/app/controllers/concerns/decidim/admin/taxonomies/filterable.rb +27 -0
  36. data/app/controllers/decidim/admin/application_controller.rb +1 -2
  37. data/app/controllers/decidim/admin/areas_controller.rb +1 -0
  38. data/app/controllers/decidim/admin/block_user_controller.rb +42 -0
  39. data/app/controllers/decidim/admin/component_permissions_controller.rb +2 -4
  40. data/app/controllers/decidim/admin/components_controller.rb +50 -9
  41. data/app/controllers/decidim/admin/concerns/has_private_users.rb +59 -2
  42. data/app/controllers/decidim/admin/global_moderations_controller.rb +4 -0
  43. data/app/controllers/decidim/admin/moderated_users_controller.rb +26 -0
  44. data/app/controllers/decidim/admin/moderations_controller.rb +18 -0
  45. data/app/controllers/decidim/admin/newsletters_controller.rb +50 -7
  46. data/app/controllers/decidim/admin/resource_permissions_controller.rb +1 -1
  47. data/app/controllers/decidim/admin/scopes_controller.rb +1 -0
  48. data/app/controllers/decidim/admin/share_tokens_controller.rb +109 -7
  49. data/app/controllers/decidim/admin/taxonomies_controller.rb +129 -0
  50. data/app/controllers/decidim/admin/taxonomy_filters_controller.rb +112 -0
  51. data/app/controllers/decidim/admin/taxonomy_filters_selector_controller.rb +81 -0
  52. data/app/controllers/decidim/admin/taxonomy_items_controller.rb +91 -0
  53. data/app/forms/concerns/decidim/has_taxonomy_form_attributes.rb +57 -0
  54. data/app/forms/decidim/admin/block_users_form.rb +21 -0
  55. data/app/forms/decidim/admin/import_example_form.rb +1 -1
  56. data/app/forms/decidim/admin/newsletter_form.rb +1 -1
  57. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +5 -0
  58. data/app/forms/decidim/admin/selective_newsletter_form.rb +46 -11
  59. data/app/forms/decidim/admin/share_token_form.rb +55 -0
  60. data/app/forms/decidim/admin/taxonomy_filter_form.rb +85 -0
  61. data/app/forms/decidim/admin/taxonomy_form.rb +20 -0
  62. data/app/forms/decidim/admin/taxonomy_item_form.rb +54 -0
  63. data/app/helpers/decidim/admin/application_helper.rb +0 -1
  64. data/app/helpers/decidim/admin/bulk_actions_helper.rb +0 -31
  65. data/app/helpers/decidim/admin/moderations/reports_helper.rb +1 -1
  66. data/app/helpers/decidim/admin/moderations_helper.rb +1 -1
  67. data/app/helpers/decidim/admin/newsletters_helper.rb +57 -27
  68. data/app/helpers/decidim/admin/scopes_helper.rb +0 -6
  69. data/app/helpers/decidim/admin/search_form_helper.rb +1 -1
  70. data/app/helpers/decidim/admin/settings_helper.rb +85 -11
  71. data/app/jobs/decidim/admin/newsletter_job.rb +3 -1
  72. data/app/packs/entrypoints/decidim_admin.js +4 -0
  73. data/app/packs/src/decidim/admin/application.js +2 -0
  74. data/app/packs/src/decidim/admin/draggable-table.js +33 -0
  75. data/app/packs/src/decidim/admin/form.js +0 -1
  76. data/app/packs/src/decidim/admin/global_moderations.js +186 -0
  77. data/app/packs/src/decidim/admin/managed_moderated_users.js +186 -0
  78. data/app/packs/src/decidim/admin/newsletters.js +164 -82
  79. data/app/packs/src/decidim/admin/proposal_infinite_edit.js +3 -6
  80. data/app/packs/src/decidim/admin/sortable.js +28 -16
  81. data/app/packs/src/decidim/admin/taxonomy_filters.js +93 -0
  82. data/app/packs/stylesheets/decidim/admin/_component-show.scss +66 -5
  83. data/app/packs/stylesheets/decidim/admin/_legacy_foundation.scss +13 -0
  84. data/app/packs/stylesheets/decidim/admin/_select_picker.scss +20 -0
  85. data/app/packs/stylesheets/decidim/admin/_table-list.scss +22 -0
  86. data/app/packs/stylesheets/decidim/admin/_taxonomies.scss +74 -0
  87. data/app/packs/stylesheets/decidim/admin/application.scss +3 -0
  88. data/app/permissions/decidim/admin/permissions.rb +32 -1
  89. data/app/queries/decidim/admin/newsletter_recipients.rb +50 -14
  90. data/app/views/decidim/admin/areas/index.html.erb +3 -0
  91. data/app/views/decidim/admin/block_user/bulk_new.html.erb +45 -0
  92. data/app/views/decidim/admin/components/_actions.html.erb +50 -33
  93. data/app/views/decidim/admin/components/{_component.html.erb → _component_row.html.erb} +10 -5
  94. data/app/views/decidim/admin/components/_components_table.html.erb +18 -0
  95. data/app/views/decidim/admin/components/_form.html.erb +0 -12
  96. data/app/views/decidim/admin/components/_taxonomy_filters_drawer.html.erb +2 -0
  97. data/app/views/decidim/admin/components/_visibility_label.html.erb +9 -0
  98. data/app/views/decidim/admin/components/index.html.erb +12 -14
  99. data/app/views/decidim/admin/components/manage_trash.html.erb +11 -0
  100. data/app/views/decidim/admin/moderated_users/_bulk-actions.html.erb +6 -0
  101. data/app/views/decidim/admin/moderated_users/bulk_actions/_block.html.erb +20 -0
  102. data/app/views/decidim/admin/moderated_users/bulk_actions/_dropdown.html.erb +40 -0
  103. data/app/views/decidim/admin/moderated_users/bulk_actions/_unblock.html.erb +20 -0
  104. data/app/views/decidim/admin/moderated_users/bulk_actions/_unreport.html.erb +20 -0
  105. data/app/views/decidim/admin/moderated_users/index.html.erb +14 -6
  106. data/app/views/decidim/admin/moderations/_bulk-actions.html.erb +7 -0
  107. data/app/views/decidim/admin/moderations/_moderation-tr.html.erb +50 -0
  108. data/app/views/decidim/admin/moderations/_moderations-thead.html.erb +18 -0
  109. data/app/views/decidim/admin/moderations/bulk_actions/_dropdown.html.erb +43 -0
  110. data/app/views/decidim/admin/moderations/bulk_actions/_hide.html.erb +20 -0
  111. data/app/views/decidim/admin/moderations/bulk_actions/_unhide.html.erb +20 -0
  112. data/app/views/decidim/admin/moderations/bulk_actions/_unreport.html.erb +20 -0
  113. data/app/views/decidim/admin/moderations/index.html.erb +13 -81
  114. data/app/views/decidim/admin/newsletters/confirm_recipients.html.erb +64 -0
  115. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +44 -20
  116. data/app/views/decidim/admin/participatory_space_private_users/_form.html.erb +6 -0
  117. data/app/views/decidim/admin/participatory_space_private_users/edit.html.erb +19 -0
  118. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +15 -1
  119. data/app/views/decidim/admin/resource_permissions/_options_form.html.erb +5 -0
  120. data/app/views/decidim/admin/resource_permissions/edit.html.erb +2 -2
  121. data/app/views/decidim/admin/scope_types/index.html.erb +3 -0
  122. data/app/views/decidim/admin/scopes/index.html.erb +3 -0
  123. data/app/views/decidim/admin/share_tokens/_form.html.erb +52 -0
  124. data/app/views/decidim/admin/share_tokens/edit.html.erb +33 -0
  125. data/app/views/decidim/admin/share_tokens/index.html.erb +47 -0
  126. data/app/views/decidim/admin/share_tokens/new.html.erb +69 -0
  127. data/app/views/decidim/admin/taxonomies/_filters.html.erb +19 -0
  128. data/app/views/decidim/admin/taxonomies/_form.html.erb +5 -0
  129. data/app/views/decidim/admin/taxonomies/_row.html.erb +40 -0
  130. data/app/views/decidim/admin/taxonomies/_row_children.html.erb +8 -0
  131. data/app/views/decidim/admin/taxonomies/_table.html.erb +86 -0
  132. data/app/views/decidim/admin/taxonomies/_taxonomy_actions.html.erb +15 -0
  133. data/app/views/decidim/admin/taxonomies/edit.html.erb +87 -0
  134. data/app/views/decidim/admin/taxonomies/index.html.erb +28 -0
  135. data/app/views/decidim/admin/taxonomies/new.html.erb +16 -0
  136. data/app/views/decidim/admin/taxonomy_filters/_check_boxes.html.erb +10 -0
  137. data/app/views/decidim/admin/taxonomy_filters/_form.html.erb +96 -0
  138. data/app/views/decidim/admin/taxonomy_filters/_table.html.erb +33 -0
  139. data/app/views/decidim/admin/taxonomy_filters/edit.html.erb +22 -0
  140. data/app/views/decidim/admin/taxonomy_filters/index.html.erb +26 -0
  141. data/app/views/decidim/admin/taxonomy_filters/new.html.erb +32 -0
  142. data/app/views/decidim/admin/taxonomy_filters_selector/_check_boxes.html.erb +7 -0
  143. data/app/views/decidim/admin/taxonomy_filters_selector/_component_table.html.erb +25 -0
  144. data/app/views/decidim/admin/taxonomy_filters_selector/_taxonomies_select.html.erb +16 -0
  145. data/app/views/decidim/admin/taxonomy_filters_selector/index.html.erb +1 -0
  146. data/app/views/decidim/admin/taxonomy_filters_selector/new.html.erb +27 -0
  147. data/app/views/decidim/admin/taxonomy_filters_selector/show.html.erb +18 -0
  148. data/app/views/decidim/admin/taxonomy_items/_form.html.erb +8 -0
  149. data/app/views/decidim/admin/taxonomy_items/edit.html.erb +12 -0
  150. data/app/views/decidim/admin/taxonomy_items/new.html.erb +12 -0
  151. data/app/views/layouts/decidim/admin/taxonomy_filters.html.erb +17 -0
  152. data/app/views/layouts/decidim/admin/taxonomy_filters_selector.html.erb +10 -0
  153. data/config/locales/ar.yml +45 -37
  154. data/config/locales/bg.yml +48 -51
  155. data/config/locales/bs-BA.yml +1 -27
  156. data/config/locales/ca.yml +301 -50
  157. data/config/locales/cs.yml +299 -46
  158. data/config/locales/de.yml +301 -50
  159. data/config/locales/el.yml +1 -50
  160. data/config/locales/en.yml +301 -50
  161. data/config/locales/es-MX.yml +298 -47
  162. data/config/locales/es-PY.yml +298 -47
  163. data/config/locales/es.yml +298 -47
  164. data/config/locales/eu.yml +302 -51
  165. data/config/locales/fi-plain.yml +298 -47
  166. data/config/locales/fi.yml +298 -47
  167. data/config/locales/fr-CA.yml +184 -47
  168. data/config/locales/fr.yml +184 -47
  169. data/config/locales/ga-IE.yml +0 -23
  170. data/config/locales/gl.yml +1 -46
  171. data/config/locales/hu.yml +1 -51
  172. data/config/locales/id-ID.yml +0 -24
  173. data/config/locales/is-IS.yml +0 -30
  174. data/config/locales/it.yml +2 -46
  175. data/config/locales/ja.yml +299 -50
  176. data/config/locales/kaa.yml +0 -7
  177. data/config/locales/ko.yml +0 -50
  178. data/config/locales/lb.yml +1 -46
  179. data/config/locales/lt.yml +1 -50
  180. data/config/locales/lv.yml +1 -28
  181. data/config/locales/nl.yml +1 -46
  182. data/config/locales/no.yml +1 -46
  183. data/config/locales/pl.yml +3 -51
  184. data/config/locales/pt-BR.yml +38 -50
  185. data/config/locales/pt.yml +29 -49
  186. data/config/locales/ro-RO.yml +38 -52
  187. data/config/locales/ru.yml +1 -24
  188. data/config/locales/sk.yml +1 -28
  189. data/config/locales/sl.yml +0 -5
  190. data/config/locales/sq-AL.yml +0 -22
  191. data/config/locales/sr-CS.yml +1 -27
  192. data/config/locales/sv.yml +296 -46
  193. data/config/locales/th-TH.yml +0 -10
  194. data/config/locales/tr-TR.yml +1 -44
  195. data/config/locales/uk.yml +0 -23
  196. data/config/locales/zh-CN.yml +0 -38
  197. data/config/locales/zh-TW.yml +1 -50
  198. data/config/routes.rb +13 -12
  199. data/decidim-admin.gemspec +1 -1
  200. data/lib/decidim/admin/engine.rb +2 -1
  201. data/lib/decidim/admin/import/creator.rb +2 -6
  202. data/lib/decidim/admin/import/readers/json.rb +1 -1
  203. data/lib/decidim/admin/menu.rb +9 -1
  204. data/lib/decidim/admin/search_form_builder.rb +1 -1
  205. data/lib/decidim/admin/test/destroy_admin_examples.rb +2 -2
  206. data/lib/decidim/admin/test/filterable_examples.rb +100 -9
  207. data/lib/decidim/admin/test/forms/attachment_collection_form_examples.rb +1 -1
  208. data/lib/decidim/admin/test/forms/attachment_form_examples.rb +1 -1
  209. data/lib/decidim/admin/test/invite_participatory_space_admins_shared_examples.rb +2 -4
  210. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +5 -5
  211. data/lib/decidim/admin/test/manage_hide_content_examples.rb +0 -1
  212. data/lib/decidim/admin/test/manage_moderations_examples.rb +3 -3
  213. data/lib/decidim/admin/test/manage_resource_soft_deletion_examples.rb +113 -0
  214. data/lib/decidim/admin/test/manage_taxonomy_filters_examples.rb +127 -0
  215. data/lib/decidim/admin/test/taxonomy_filters_examples.rb +32 -0
  216. data/lib/decidim/admin/test.rb +3 -1
  217. data/lib/decidim/admin/version.rb +1 -1
  218. metadata +103 -29
  219. data/app/commands/decidim/admin/create_category.rb +0 -15
  220. data/app/commands/decidim/admin/destroy_category.rb +0 -15
  221. data/app/commands/decidim/admin/destroy_component.rb +0 -19
  222. data/app/commands/decidim/admin/update_category.rb +0 -11
  223. data/app/controllers/decidim/admin/categories_controller.rb +0 -98
  224. data/app/forms/decidim/admin/category_form.rb +0 -32
  225. data/app/helpers/decidim/admin/resource_scope_helper.rb +0 -52
  226. data/app/packs/src/decidim/admin/scope_picker_enabler.component.js +0 -12
  227. data/app/views/decidim/admin/categories/_form.html.erb +0 -18
  228. data/app/views/decidim/admin/categories/edit.html.erb +0 -19
  229. data/app/views/decidim/admin/categories/index.html.erb +0 -65
  230. data/app/views/decidim/admin/categories/new.html.erb +0 -19
  231. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +0 -45
  232. data/lib/decidim/admin/test/commands/create_category_examples.rb +0 -74
  233. data/lib/decidim/admin/test/commands/destroy_category_examples.rb +0 -83
  234. data/lib/decidim/admin/test/commands/update_category_examples.rb +0 -76
  235. data/lib/decidim/admin/test/forms/category_form_examples.rb +0 -70
  236. 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: b5369e22c8aa5d1eef8398ca2971c4231fcdda8284df5350ca231b68e47e78cf
4
- data.tar.gz: 28d412f0fbd4683f6031784abf212ba6341f0dd803a57eb167b9d1bf186f83a1
3
+ metadata.gz: 26bfbf8e68bdc41e593b48bc9d1b89a69430c0d3aa7848a98bc65ca326c5bba2
4
+ data.tar.gz: caee2c19de1daae78bf7e885ae79f67c61a278bba2f553654e7d9a6768b9a3f6
5
5
  SHA512:
6
- metadata.gz: d25815c8206161af6f158106f8258abc3280cb05e03c528fb7e628479bae1c43551a4172014a181a09f66ec6eb24da6f0cfd55e4d3302fb0b8aa0391d0cfd430
7
- data.tar.gz: 71a6522e75aed08bbdc65577cd76b2c69741d66f28b350c04dc02c1c92850e96fd50c481a23e02da804316f8eb24e5a1186dad94912eae6b2bb1072774d292fb
6
+ metadata.gz: 881f684019ec01981278bd367050e381160662ed72d46df229f97ed62c0f564d3fc520f9351ab936244f33d4d1abf87df7bf776e843cac4d14f4d5f7b8a87e4b
7
+ data.tar.gz: be0e2fc5ccc488c230cb5e7d39a9cfb9c1cafe12715dde1204325e3d45cd62cb85dd4e613b7c548383ef444832a1c044f172fc416ceb1a1202ea8a629e917374
@@ -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
@@ -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,8 +26,7 @@ module Decidim
24
26
 
25
27
  with_events do
26
28
  tool = Decidim::ModerationTools.new(@reportable, @current_user)
27
- tool.hide!
28
- tool.send_notification_to_author
29
+ @with_admin_log ? tool.hide_with_admin_log! : tool.hide!
29
30
  end
30
31
 
31
32
  broadcast(:ok, @reportable)
@@ -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