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
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command that reorders a collection of components
6
+ class ReorderComponents < Decidim::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # components - the components to reorder
10
+ # order - an Array holding the order of IDs of the components
11
+ def initialize(components, order)
12
+ @components = components
13
+ @order = order
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) unless valid_params?
24
+
25
+ reorder_components
26
+ broadcast(:ok)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :components, :order
32
+
33
+ def valid_params?
34
+ order.present? && components.present?
35
+ end
36
+
37
+ def reorder_components
38
+ transaction do
39
+ order.each_with_index do |id, index|
40
+ component = components.find_by(id:)
41
+ component.update!(weight: index + 1) if component.present?
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command that reorders a collection of taxonomies
6
+ # the ones that might be missing.
7
+ class ReorderTaxonomies < Decidim::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # organization - the Organization where the content blocks reside
11
+ # order - an Array holding the order of IDs of published content blocks.
12
+ def initialize(organization, order, offset = 0)
13
+ @organization = organization
14
+ @order = order
15
+ @offset = offset
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the data was not valid and we could not proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if order.blank?
26
+ return broadcast(:invalid) if collection.empty?
27
+
28
+ reorder_steps
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :organization, :offset
35
+
36
+ def reorder_steps
37
+ transaction do
38
+ reset_weights
39
+ collection.reload
40
+ set_new_weights
41
+ end
42
+ end
43
+
44
+ def reset_weights
45
+ # rubocop:disable Rails/SkipsModelValidations
46
+ collection.where.not(weight: nil).where(id: order).update_all(weight: nil)
47
+ # rubocop:enable Rails/SkipsModelValidations
48
+ end
49
+
50
+ def set_new_weights
51
+ data = order.each_with_index.inject({}) do |hash, (id, index)|
52
+ hash.update(id => index + 1 + offset)
53
+ end
54
+
55
+ data.each do |id, weight|
56
+ item = collection.find_by(id:)
57
+ item.update!(weight:) if item.present?
58
+ end
59
+ end
60
+
61
+ def order
62
+ return nil unless @order.is_a?(Array) && @order.present?
63
+
64
+ @order
65
+ end
66
+
67
+ def collection
68
+ @collection ||= Decidim::Taxonomy.where(organization:, parent_id: first_item.parent_id)
69
+ end
70
+
71
+ def first_item
72
+ @first_item ||= Decidim::Taxonomy.where(organization:).find(order.first)
73
+ end
74
+ end
75
+ end
76
+ 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 unhide 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:
@@ -22,7 +24,7 @@ module Decidim
22
24
  def call
23
25
  return broadcast(:invalid) unless unhideable?
24
26
 
25
- unhide!
27
+ @with_admin_log ? unhide_with_admin_log! : unhide!
26
28
  broadcast(:ok, @reportable)
27
29
  end
28
30
 
@@ -32,7 +34,7 @@ module Decidim
32
34
  @reportable.hidden? && @reportable.reported?
33
35
  end
34
36
 
35
- def unhide!
37
+ def unhide_with_admin_log!
36
38
  Decidim.traceability.perform_action!(
37
39
  "unhide",
38
40
  @reportable.moderation,
@@ -41,6 +43,12 @@ module Decidim
41
43
  reportable_type: @reportable.class.name
42
44
  }
43
45
  ) do
46
+ unhide!
47
+ end
48
+ end
49
+
50
+ def unhide!
51
+ Decidim.traceability.perform_action_without_log!(@current_user) do
44
52
  @reportable.moderation.update!(hidden_at: nil)
45
53
  end
46
54
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class UnpublishAllParticipatorySpacePrivateUsers < 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
+ unpublish_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 unpublish_all
34
+ # rubocop:disable Rails/SkipsModelValidations
35
+ # Using update_all for performance reasons
36
+ participatory_space.participatory_space_private_users.update_all(published: false)
37
+ # rubocop:enable Rails/SkipsModelValidations
38
+ end
39
+
40
+ def create_action_log
41
+ Decidim.traceability.perform_action!(
42
+ "unpublish_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
@@ -8,9 +8,11 @@ module Decidim
8
8
  #
9
9
  # reportable - A Decidim::Reportable
10
10
  # current_user - the user performing the action
11
- def initialize(reportable, current_user)
11
+ # with_admin_log Boolean - determines whether to log the action of unreport 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:
@@ -22,13 +24,13 @@ module Decidim
22
24
  def call
23
25
  return broadcast(:invalid) unless @reportable.reported?
24
26
 
25
- unreport!
27
+ @with_admin_log ? unreport_with_admin_log! : unreport!
26
28
  broadcast(:ok, @reportable)
27
29
  end
28
30
 
29
31
  private
30
32
 
31
- def unreport!
33
+ def unreport_with_admin_log!
32
34
  Decidim.traceability.perform_action!(
33
35
  "unreport",
34
36
  @reportable.moderation,
@@ -37,6 +39,12 @@ module Decidim
37
39
  reportable_type: @reportable.class.name
38
40
  }
39
41
  ) do
42
+ unreport!
43
+ end
44
+ end
45
+
46
+ def unreport!
47
+ Decidim.traceability.perform_action_without_log!(@current_user) do
40
48
  @reportable.moderation.destroy!
41
49
  end
42
50
  end
@@ -25,7 +25,10 @@ module Decidim
25
25
 
26
26
  Decidim.traceability.perform_action!("update_permissions", @component, current_user) do
27
27
  transaction do
28
+ permissions_with_changes_in_ephemeral_handlers
28
29
  update_permissions
30
+ raise ActiveRecord::Rollback unless clean_ephemeral_authorizations
31
+
29
32
  run_hooks
30
33
  end
31
34
  end
@@ -44,7 +47,36 @@ module Decidim
44
47
  end
45
48
 
46
49
  def update_permissions
47
- permissions = configured_permissions.inject({}) do |result, (key, value)|
50
+ if resource
51
+ resource_permissions.update!(permissions: permissions_with_differences(component.permissions, selected_permissions))
52
+ else
53
+ component.update!(permissions: selected_permissions)
54
+ end
55
+ end
56
+
57
+ def clean_ephemeral_authorizations
58
+ handler_names = permissions_with_changes_in_ephemeral_handlers.values.map { |config| config["authorization_handlers"].keys }.flatten.uniq
59
+ ephemeral_handler_names = handler_names.select { |handler_name| Decidim::Verifications::Adapter.from_element(handler_name).ephemeral? }
60
+
61
+ ephemeral_handler_names.each do |name|
62
+ Decidim::Verifications::RevokeByNameAuthorizations.call(current_user.organization, name, current_user) do
63
+ on(:ok) do
64
+ return true
65
+ end
66
+
67
+ on(:invalid) do
68
+ return false
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def run_hooks
75
+ component.manifest.run_hooks(:permission_update, component:, resource:)
76
+ end
77
+
78
+ def selected_permissions
79
+ @selected_permissions ||= configured_permissions.inject({}) do |result, (key, value)|
48
80
  handlers_content = {}
49
81
 
50
82
  selected_handlers(value).each do |handler_key|
@@ -58,27 +90,35 @@ module Decidim
58
90
 
59
91
  result.update(key => selected_handlers(value).any? ? serialized : {})
60
92
  end
61
-
62
- if resource
63
- resource_permissions.update!(permissions: different_from_component_permissions(permissions))
64
- else
65
- component.update!(permissions:)
66
- end
67
93
  end
68
94
 
69
- def run_hooks
70
- component.manifest.run_hooks(:permission_update, component:, resource:)
95
+ def permissions_with_changes_in_ephemeral_handlers
96
+ @permissions_with_changes_in_ephemeral_handlers ||= begin
97
+ old_permissions = ((resource.present? ? resource_permissions.permissions : component.permissions) || {}).deep_stringify_keys
98
+
99
+ selected_permissions.deep_stringify_keys.reject do |action, config|
100
+ old_config = old_permissions[action] || { "authorization_handlers" => {} }
101
+ Hashdiff.diff(config, old_config).none? do |_, key, _|
102
+ handler_name = key.split(".")[1]
103
+ next if handler_name.blank?
104
+
105
+ Decidim::Verifications::Adapter.from_element(handler_name).ephemeral? && config["authorization_handlers"].keys.include?(handler_name)
106
+ end
107
+ end
108
+ end
71
109
  end
72
110
 
73
111
  def resource_permissions
74
112
  @resource_permissions ||= resource.resource_permission || resource.build_resource_permission
75
113
  end
76
114
 
77
- def different_from_component_permissions(permissions)
78
- return permissions unless component.permissions
115
+ def permissions_with_differences(old_permissions, new_permissions)
116
+ return new_permissions unless old_permissions
117
+
118
+ old_permissions = old_permissions.deep_stringify_keys
79
119
 
80
- permissions.deep_stringify_keys.reject do |action, config|
81
- Hashdiff.diff(config, component.permissions[action]).empty?
120
+ new_permissions.deep_stringify_keys.reject do |action, config|
121
+ Hashdiff.diff(old_permissions[action], config).empty?
82
122
  end
83
123
  end
84
124
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic when updating a participatory space
6
+ # private user.
7
+ class UpdateParticipatorySpacePrivateUser < Decidim::Commands::UpdateResource
8
+ fetch_form_attributes :role, :published
9
+ end
10
+ end
11
+ 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 update a share token.
6
+ # This command is called from the controller.
7
+ class UpdateShareToken < Decidim::Commands::UpdateResource
8
+ fetch_form_attributes :expires_at, :registered_only
9
+
10
+ delegate :participatory_space, :component, to: :resource
11
+
12
+ def extra_params
13
+ {
14
+ participatory_space: {
15
+ title: participatory_space&.title
16
+ },
17
+ resource: {
18
+ title: component&.name
19
+ }
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command to update a taxonomy.
6
+ class UpdateTaxonomy < Decidim::Commands::UpdateResource
7
+ fetch_form_attributes :name, :parent_id
8
+
9
+ protected
10
+
11
+ def extra_params
12
+ {
13
+ extra: {
14
+ parent_name: resource.parent.try(:name)
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
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 UpdateTaxonomyFilter < Decidim::Commands::UpdateResource
8
+ fetch_form_attributes :filter_items, :internal_name, :name, :participatory_space_manifests
9
+
10
+ protected
11
+
12
+ def resource_class = Decidim::TaxonomyFilter
13
+
14
+ def run_before_hooks
15
+ resource.filter_items.destroy_all
16
+ end
17
+
18
+ def extra_params
19
+ {
20
+ extra: {
21
+ taxonomy_name: resource.root_taxonomy.name,
22
+ filter_items_count: form.filter_items.count
23
+ }
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module ComponentTaxonomiesHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ helper_method :current_component_taxonomy_filters
10
+ end
11
+
12
+ def current_component_taxonomy_filters
13
+ @current_component_taxonomy_filters ||= TaxonomyFilter.for(current_organization)
14
+ .for_manifest(current_participatory_space.manifest.name)
15
+ .where(id: current_component.settings.taxonomy_filters)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -30,8 +30,9 @@ module Decidim
30
30
  :search_field_predicate,
31
31
  :adjacent_items
32
32
 
33
- delegate :categories, to: :current_component
34
- delegate :scopes, to: :current_organization
33
+ delegate :taxonomies, to: :current_organization
34
+ delegate :available_root_taxonomies, to: :current_component
35
+ delegate :available_taxonomy_ids, to: :current_component
35
36
 
36
37
  def query
37
38
  @query ||= base_query.ransack(ransack_params, search_context: :admin, auth_object: current_user)
@@ -188,36 +189,32 @@ module Decidim
188
189
  query.klass.model_name.human(count: 2)
189
190
  end
190
191
 
191
- # A tree of Category IDs. Leaves are `nil`.
192
- def category_ids_hash(categories)
193
- categories.each_with_object({}) do |category, hash|
194
- hash[category.id] = category.subcategories.any? ? category_ids_hash(category.subcategories) : nil
195
- end
192
+ def taxonomy_order_or_search?
193
+ ransack_params[:taxonomies_part_of_contains].present? || ransack_params[:s]&.include?("taxonomies_name")
196
194
  end
197
195
 
198
- # A tree of Scope IDs. Leaves are `nil`.
199
- def scope_ids_hash(scopes)
200
- scopes.each_with_object({}) do |scope, hash|
201
- hash[scope.id] = scope.children.any? ? scope_ids_hash(scope.children) : nil
196
+ # A tree of Taxonomy IDs. Leaves are `nil`.
197
+ def taxonomy_ids_hash(taxonomies)
198
+ filtered_taxonomies = taxonomies.roots.or(taxonomies.where(id: available_taxonomy_ids))
199
+ return nil if filtered_taxonomies.blank?
200
+
201
+ filtered_taxonomies.each_with_object({}) do |taxonomy, hash|
202
+ hash[taxonomy.id] = taxonomy_ids_hash(taxonomy.children)
202
203
  end
203
204
  end
204
205
 
205
206
  # Array<Symbol> of filters that implement a method to find translations.
206
207
  # Useful when translations cannot be found in i18n or come from a Model.
207
208
  def dynamically_translated_filters
208
- [:scope_id_eq, :category_id_eq]
209
+ [:taxonomies_part_of_contains]
209
210
  end
210
211
 
211
212
  def find_dynamic_translation(filter, value)
212
213
  send("translated_#{filter}", value) if filter.in?(dynamically_translated_filters)
213
214
  end
214
215
 
215
- def translated_scope_id_eq(id)
216
- translated_attribute(scopes.find_by(id:).name)
217
- end
218
-
219
- def translated_category_id_eq(id)
220
- translated_attribute(categories.find_by(id:).name)
216
+ def translated_taxonomies_part_of_contains(id)
217
+ translated_attribute(taxonomies.find_by(id:).name)
221
218
  end
222
219
  end
223
220
  end