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
@@ -7,7 +7,7 @@ module Decidim
7
7
  include Decidim::NewslettersHelper
8
8
  include Decidim::Admin::NewslettersHelper
9
9
  include Paginable
10
- helper_method :newsletter, :recipients_count_query, :content_block
10
+ helper_method :newsletter, :recipients_count_query, :content_block, :selected_options, :newsletter_params
11
11
 
12
12
  def index
13
13
  enforce_permission_to :index, :newsletter
@@ -103,20 +103,22 @@ module Decidim
103
103
 
104
104
  def select_recipients_to_deliver
105
105
  enforce_permission_to(:update, :newsletter, newsletter:)
106
- @form = form(SelectiveNewsletterForm).from_model(newsletter)
107
- @form.send_to_all_users = current_user.admin?
106
+
107
+ @form = if newsletter_params.present?
108
+ form(SelectiveNewsletterForm).from_params(newsletter_params)
109
+ else
110
+ form(SelectiveNewsletterForm).from_model(newsletter)
111
+ end
108
112
  end
109
113
 
110
114
  def recipients_count
111
- data = params.permit(newsletter: {}).to_h[:newsletter]
112
-
113
- @form = form(SelectiveNewsletterForm).from_params(data)
115
+ @form = form(SelectiveNewsletterForm).from_params(newsletter_params)
114
116
  render plain: recipients_count_query
115
117
  end
116
118
 
117
119
  def deliver
118
120
  enforce_permission_to(:update, :newsletter, newsletter:)
119
- @form = form(SelectiveNewsletterForm).from_params(params)
121
+ @form = form(SelectiveNewsletterForm).from_params(newsletter_params)
120
122
 
121
123
  DeliverNewsletter.call(newsletter, @form) do
122
124
  on(:ok) do
@@ -136,8 +138,49 @@ module Decidim
136
138
  end
137
139
  end
138
140
 
141
+ def confirm_recipients
142
+ enforce_permission_to(:update, :newsletter, newsletter:)
143
+ @form = form(SelectiveNewsletterForm).from_params(newsletter_params)
144
+ @recipients = NewsletterRecipients.for(@form).order(:email)
145
+ @recipients = paginate(@recipients)
146
+
147
+ render :confirm_recipients
148
+ end
149
+
139
150
  private
140
151
 
152
+ def newsletter_params
153
+ params.fetch(:newsletter, {}).permit(
154
+ :send_to_all_users,
155
+ :send_to_verified_users,
156
+ :send_to_followers,
157
+ :send_to_participants,
158
+ :send_to_private_members,
159
+ verification_types: [],
160
+ participatory_space_types: {
161
+ assemblies: [:manifest_name, { ids: [] }],
162
+ conferences: [:manifest_name, { ids: [] }],
163
+ initiatives: [:manifest_name, { ids: [] }],
164
+ participatory_processes: [:manifest_name, { ids: [] }]
165
+ }
166
+ )
167
+ end
168
+
169
+ def selected_options(key)
170
+ @selected_options ||= {}
171
+ @selected_options[key] ||= extract_selected_ids(params[:newsletter], key)
172
+ end
173
+
174
+ def extract_selected_ids(newsletter_params, key)
175
+ return {} unless newsletter_params.present? && newsletter_params[key].present?
176
+
177
+ if newsletter_params[key].is_a?(Array)
178
+ { key => newsletter_params[key].map(&:to_s) }
179
+ else
180
+ (newsletter_params[key] || {}).transform_values { |space| space["ids"] || [] }
181
+ end
182
+ end
183
+
141
184
  def collection
142
185
  @collection ||= Newsletter.where(organization: current_organization)
143
186
  end
@@ -87,7 +87,7 @@ module Decidim
87
87
  end
88
88
 
89
89
  def permissions
90
- @permissions ||= (resource&.permissions || {})
90
+ @permissions ||= resource&.permissions || {}
91
91
  end
92
92
 
93
93
  def authorizations_for(action)
@@ -6,6 +6,7 @@ module Decidim
6
6
  #
7
7
  class ScopesController < Decidim::Admin::ApplicationController
8
8
  include Decidim::Admin::Concerns::HasTabbedMenu
9
+ helper Decidim::Admin::ScopesHelper
9
10
 
10
11
  layout "decidim/admin/settings"
11
12
 
@@ -2,11 +2,66 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
+ # This is an abstract controller allows sharing unpublished things.
6
+ # Final implementation must inherit from this controller and implement the `resource` method.
5
7
  class ShareTokensController < Decidim::Admin::ApplicationController
8
+ include Decidim::Admin::Filterable
9
+
10
+ helper_method :current_token, :resource, :resource_title, :share_tokens_path
11
+
12
+ def index
13
+ enforce_permission_to :read, :share_tokens
14
+ @share_tokens = filtered_collection
15
+ end
16
+
17
+ def new
18
+ enforce_permission_to :create, :share_tokens
19
+ @form = form(ShareTokenForm).instance
20
+ end
21
+
22
+ def create
23
+ enforce_permission_to :create, :share_tokens
24
+ @form = form(ShareTokenForm).from_params(params, resource:)
25
+
26
+ CreateShareToken.call(@form) do
27
+ on(:ok) do
28
+ flash[:notice] = I18n.t("share_tokens.create.success", scope: "decidim.admin")
29
+ redirect_to share_tokens_path
30
+ end
31
+
32
+ on(:invalid) do
33
+ flash.now[:alert] = I18n.t("share_tokens.create.invalid", scope: "decidim.admin")
34
+ render action: "new"
35
+ end
36
+ end
37
+ end
38
+
39
+ def edit
40
+ enforce_permission_to(:update, :share_tokens, share_token: current_token)
41
+ @form = form(ShareTokenForm).from_model(current_token)
42
+ end
43
+
44
+ def update
45
+ enforce_permission_to(:update, :share_tokens, share_token: current_token)
46
+ @form = form(ShareTokenForm).from_params(params, resource:)
47
+
48
+ UpdateShareToken.call(@form, current_token) do
49
+ on(:ok) do
50
+ flash[:notice] = I18n.t("share_tokens.update.success", scope: "decidim.admin")
51
+ redirect_to share_tokens_path
52
+ end
53
+
54
+ on(:invalid) do
55
+ flash.now[:alert] = I18n.t("share_tokens.update.error", scope: "decidim.admin")
56
+ render :edit
57
+ end
58
+ end
59
+ end
60
+
6
61
  def destroy
7
- enforce_permission_to(:destroy, :share_token, share_token:)
62
+ enforce_permission_to(:destroy, :share_tokens, share_token: current_token)
8
63
 
9
- Decidim::Commands::DestroyResource.call(share_token, current_user) do
64
+ DestroyShareToken.call(current_token, current_user) do
10
65
  on(:ok) do
11
66
  flash[:notice] = I18n.t("share_tokens.destroy.success", scope: "decidim.admin")
12
67
  end
@@ -15,15 +70,62 @@ module Decidim
15
70
  end
16
71
  end
17
72
 
18
- redirect_back(fallback_location: root_path)
73
+ redirect_to share_tokens_path
19
74
  end
20
75
 
21
76
  private
22
77
 
23
- def share_token
24
- @share_token ||= Decidim::ShareToken.where(
25
- organization: current_organization
26
- ).find(params[:id])
78
+ # override this method in the destination controller to specify the resource associated with the shared token (ie: a component)
79
+ def resource
80
+ raise NotImplementedError
81
+ end
82
+
83
+ # Override also this method if resource does not respond to a translatable name or title
84
+ def resource_title
85
+ translated_attribute(resource.try(:name) || resource.title)
86
+ end
87
+
88
+ # sets the prefix for the route helper methods (this may vary depending on the resource type)
89
+ # This setup works fine for participatory spaces and components, override if needed
90
+ def route_name
91
+ @route_name ||= "#{resource.manifest.route_name}_"
92
+ end
93
+
94
+ def route_proxy
95
+ @route_proxy ||= EngineRouter.admin_proxy(resource.try(:participatory_space) || resource)
96
+ end
97
+
98
+ # returns the proper path for managing a share token according to the resource
99
+ # this works fine for components and participatory spaces, override if needed
100
+ def share_tokens_path(method = :index, options = {})
101
+ args = resource.is_a?(Decidim::Component) ? [resource, options] : [options]
102
+
103
+ case method
104
+ when :index, :create
105
+ route_proxy.send("#{route_name}share_tokens_path", *args)
106
+ when :new
107
+ route_proxy.send("new_#{route_name}share_token_path", *args)
108
+ when :update, :destroy
109
+ route_proxy.send("#{route_name}share_token_path", *args)
110
+ when :edit
111
+ route_proxy.send("edit_#{route_name}share_token_path", *args)
112
+ end
113
+ end
114
+
115
+ def base_query
116
+ collection
117
+ end
118
+
119
+ def collection
120
+ @collection ||= Decidim::ShareToken.where(organization: current_organization, token_for: resource)
121
+ end
122
+
123
+ def filters
124
+ []
125
+ end
126
+
127
+ def current_token
128
+ @current_token ||= collection.find(params[:id])
27
129
  end
28
130
  end
29
131
  end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class TaxonomiesController < Decidim::Admin::ApplicationController
6
+ include Decidim::Admin::Taxonomies::Filterable
7
+
8
+ layout "decidim/admin/settings"
9
+
10
+ before_action :set_taxonomies_breadcrumb_item
11
+ before_action only: :edit do
12
+ redirect_to edit_taxonomy_path(taxonomy.parent) unless taxonomy && taxonomy.root?
13
+ end
14
+
15
+ helper_method :collection, :parent_options, :taxonomy
16
+
17
+ def index
18
+ enforce_permission_to :index, :taxonomy
19
+ @taxonomies = filtered_collection
20
+ end
21
+
22
+ def new
23
+ enforce_permission_to :create, :taxonomy
24
+ add_breadcrumb_item :new, decidim_admin.new_taxonomy_path
25
+
26
+ @form = form(Decidim::Admin::TaxonomyForm).instance
27
+ end
28
+
29
+ def create
30
+ enforce_permission_to :create, :taxonomy
31
+ add_breadcrumb_item :new, decidim_admin.new_taxonomy_path
32
+
33
+ @form = form(Decidim::Admin::TaxonomyForm).from_params(params)
34
+ CreateTaxonomy.call(@form) do
35
+ on(:ok) do
36
+ flash[:notice] = I18n.t("create.success", scope: "decidim.admin.taxonomies")
37
+ redirect_to taxonomies_path
38
+ end
39
+
40
+ on(:invalid) do
41
+ flash.now[:alert] = I18n.t("create.invalid", scope: "decidim.admin.taxonomies")
42
+ render action: "new"
43
+ end
44
+ end
45
+ end
46
+
47
+ def edit
48
+ enforce_permission_to(:update, :taxonomy, taxonomy:)
49
+ add_breadcrumb_item :edit, decidim_admin.edit_taxonomy_path(taxonomy)
50
+
51
+ @form = form(Decidim::Admin::TaxonomyForm).from_model(taxonomy)
52
+ @taxonomies = filtered_collection
53
+ end
54
+
55
+ def update
56
+ enforce_permission_to(:update, :taxonomy, taxonomy:)
57
+ add_breadcrumb_item :edit, decidim_admin.edit_taxonomy_path(taxonomy)
58
+
59
+ @form = form(Decidim::Admin::TaxonomyForm).from_params(params)
60
+
61
+ UpdateTaxonomy.call(@form, taxonomy) do
62
+ on(:ok) do
63
+ flash[:notice] = I18n.t("update.success", scope: "decidim.admin.taxonomies")
64
+ redirect_to taxonomies_path
65
+ end
66
+
67
+ on(:invalid) do
68
+ flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.admin.taxonomies")
69
+ render action: "edit"
70
+ end
71
+ end
72
+ end
73
+
74
+ def destroy
75
+ enforce_permission_to(:destroy, :taxonomy, taxonomy:)
76
+
77
+ DestroyTaxonomy.call(taxonomy, current_user) do
78
+ on(:ok) do
79
+ flash[:notice] = I18n.t("destroy.success", scope: "decidim.admin.taxonomies")
80
+ end
81
+
82
+ on(:invalid) do
83
+ flash.now[:alert] = I18n.t("destroy.invalid", scope: "decidim.admin.taxonomies")
84
+ end
85
+ end
86
+ redirect_back(fallback_location: taxonomies_path)
87
+ end
88
+
89
+ def reorder
90
+ enforce_permission_to :update, :taxonomy
91
+
92
+ ReorderTaxonomies.call(current_organization, params[:ids_order], page_offset) do
93
+ on(:ok) do
94
+ head :ok
95
+ end
96
+
97
+ on(:invalid) do
98
+ head :bad_request
99
+ end
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def collection
106
+ @collection ||= taxonomy ? taxonomy.children : root_taxonomies
107
+ end
108
+
109
+ def root_taxonomies
110
+ @root_taxonomies ||= current_organization.taxonomies.roots
111
+ end
112
+
113
+ def taxonomy
114
+ @taxonomy ||= current_organization.taxonomies.find_by(id: params[:id])
115
+ end
116
+
117
+ def set_taxonomies_breadcrumb_item
118
+ add_breadcrumb_item I18n.t("menu.taxonomies", scope: "decidim.admin"), decidim_admin.taxonomies_path
119
+ end
120
+
121
+ def add_breadcrumb_item(key, url)
122
+ controller_breadcrumb_items << {
123
+ label: I18n.t(key, scope: "decidim.admin.taxonomies.breadcrumb", default: key),
124
+ url:
125
+ }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class TaxonomyFiltersController < Decidim::Admin::ApplicationController
6
+ include Decidim::Admin::Taxonomies::Filterable
7
+
8
+ layout "decidim/admin/settings"
9
+
10
+ before_action :set_taxonomies_breadcrumb_item
11
+ before_action only: :edit do
12
+ redirect_to taxonomy_filters_path(root_taxonomy) unless taxonomy_filter && root_taxonomy == taxonomy_filter.root_taxonomy
13
+ end
14
+
15
+ helper_method :collection, :root_taxonomy, :taxonomy_filter
16
+
17
+ # Returns non-layout views of for use in selecting filters for components or other places using a drawer.
18
+ def show
19
+ enforce_permission_to :show, :taxonomy_filter
20
+ end
21
+
22
+ def index
23
+ enforce_permission_to :index, :taxonomy_filter
24
+ end
25
+
26
+ def new
27
+ enforce_permission_to :create, :taxonomy_filter
28
+ add_breadcrumb_item :new, decidim_admin.new_taxonomy_filter_path
29
+ @form = form(Decidim::Admin::TaxonomyFilterForm).from_params(root_taxonomy_id: params[:taxonomy_id])
30
+ end
31
+
32
+ def create
33
+ enforce_permission_to :create, :taxonomy_filter
34
+ add_breadcrumb_item :new, decidim_admin.new_taxonomy_filter_path
35
+ @form = form(Decidim::Admin::TaxonomyFilterForm).from_params(params)
36
+ CreateTaxonomyFilter.call(@form) do
37
+ on(:ok) do
38
+ flash[:notice] = I18n.t("create.success", scope: "decidim.admin.taxonomy_filters")
39
+ redirect_to decidim_admin.taxonomy_filters_path(root_taxonomy)
40
+ end
41
+
42
+ on(:invalid) do
43
+ flash.now[:alert] = I18n.t("create.error", scope: "decidim.admin.taxonomy_filters")
44
+ render :new
45
+ end
46
+ end
47
+ end
48
+
49
+ def edit
50
+ enforce_permission_to(:update, :taxonomy_filter, taxonomy_filter:)
51
+ add_breadcrumb_item :edit, decidim_admin.edit_taxonomy_filter_path
52
+ @form = form(Decidim::Admin::TaxonomyFilterForm).from_model(taxonomy_filter)
53
+ end
54
+
55
+ def update
56
+ enforce_permission_to(:update, :taxonomy_filter, taxonomy_filter:)
57
+ add_breadcrumb_item :edit, decidim_admin.edit_taxonomy_filter_path
58
+ @form = form(Decidim::Admin::TaxonomyFilterForm).from_params(params)
59
+ UpdateTaxonomyFilter.call(@form, taxonomy_filter) do
60
+ on(:ok) do
61
+ flash[:notice] = I18n.t("update.success", scope: "decidim.admin.taxonomy_filters")
62
+ redirect_to decidim_admin.taxonomy_filters_path(root_taxonomy)
63
+ end
64
+ on(:invalid) do
65
+ flash.now[:alert] = I18n.t("update.error", scope: "decidim.admin.taxonomy_filters")
66
+ render :edit
67
+ end
68
+ end
69
+ end
70
+
71
+ def destroy
72
+ enforce_permission_to(:destroy, :taxonomy_filter, taxonomy_filter:)
73
+ DestroyTaxonomyFilter.call(taxonomy_filter, current_user) do
74
+ on(:ok) do
75
+ flash[:notice] = I18n.t("destroy.success", scope: "decidim.admin.taxonomy_filters")
76
+ end
77
+ on(:invalid) do
78
+ flash[:alert] = I18n.t("destroy.error", scope: "decidim.admin.taxonomy_filters")
79
+ end
80
+ end
81
+ redirect_back(fallback_location: decidim_admin.taxonomy_filters_path(root_taxonomy))
82
+ end
83
+
84
+ private
85
+
86
+ def collection
87
+ @collection ||= root_taxonomy.taxonomy_filters
88
+ end
89
+
90
+ def root_taxonomy
91
+ @root_taxonomy ||= Taxonomy.roots.find(params[:taxonomy_id])
92
+ end
93
+
94
+ def taxonomy_filter
95
+ @taxonomy_filter ||= TaxonomyFilter.find_by(id: params[:id])
96
+ end
97
+
98
+ def set_taxonomies_breadcrumb_item
99
+ add_breadcrumb_item I18n.t("menu.taxonomies", scope: "decidim.admin"), decidim_admin.taxonomies_path
100
+ add_breadcrumb_item root_taxonomy.name, decidim_admin.taxonomy_filters_path(root_taxonomy)
101
+ add_breadcrumb_item :filters, decidim_admin.taxonomy_filters_path(root_taxonomy)
102
+ end
103
+
104
+ def add_breadcrumb_item(key, url)
105
+ controller_breadcrumb_items << {
106
+ label: I18n.t(key, scope: "decidim.admin.taxonomy_filters.breadcrumb", default: key),
107
+ url:
108
+ }
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class TaxonomyFiltersSelectorController < Decidim::Admin::ApplicationController
6
+ layout "decidim/admin/taxonomy_filters_selector"
7
+
8
+ helper_method :root_taxonomy, :taxonomy_filter, :component, :field_name
9
+
10
+ # ensure component is valid
11
+ before_action do
12
+ raise Decidim::ActionForbidden unless component && component.organization == current_organization
13
+ end
14
+
15
+ before_action except: :index do
16
+ redirect_to taxonomy_filters_selector_index_path(component_id: params[:component_id]) if root_taxonomy.nil?
17
+ end
18
+
19
+ before_action except: [:index, :new, :destroy] do
20
+ redirect_to new_taxonomy_filters_selector_path(component_id: params[:component_id], taxonomy_id: params[:taxonomy_id]) if taxonomy_filter.nil?
21
+ end
22
+
23
+ # Renders "choose the taxonomy" step
24
+ def index
25
+ enforce_permission_to :index, :taxonomy_filter
26
+ end
27
+
28
+ # Renders "choose the taxonomy filter" step
29
+ def new
30
+ enforce_permission_to :create, :taxonomy_filter
31
+ end
32
+
33
+ # Updates the component with the selected taxonomy filter
34
+ def create
35
+ enforce_permission_to :create, :taxonomy_filter
36
+
37
+ update_filters!(component.settings.taxonomy_filters + [taxonomy_filter.id.to_s])
38
+
39
+ render partial: "decidim/admin/taxonomy_filters_selector/component_table"
40
+ end
41
+
42
+ # Renders the component with the selected taxonomy filter
43
+ def show
44
+ enforce_permission_to :show, :taxonomy_filter
45
+ end
46
+
47
+ # Removes the selected taxonomy filter from the component
48
+ def destroy
49
+ enforce_permission_to :destroy, :taxonomy_filter
50
+
51
+ update_filters!(component.settings.taxonomy_filters - [taxonomy_filter.id.to_s]) if taxonomy_filter
52
+
53
+ render partial: "decidim/admin/taxonomy_filters_selector/component_table"
54
+ end
55
+
56
+ private
57
+
58
+ def update_filters!(filter_ids)
59
+ Decidim.traceability.perform_action!("update_filters", component, current_user) do
60
+ component.update!(settings: { taxonomy_filters: filter_ids.map(&:to_s).uniq })
61
+ end
62
+ end
63
+
64
+ def field_name
65
+ "component[settings][taxonomy_filters][]"
66
+ end
67
+
68
+ def component
69
+ @component ||= Component.find_by(id: params[:component_id])
70
+ end
71
+
72
+ def root_taxonomy
73
+ @root_taxonomy ||= current_organization.taxonomies.roots.find_by(id: params[:taxonomy_id])
74
+ end
75
+
76
+ def taxonomy_filter
77
+ @taxonomy_filter ||= root_taxonomy.taxonomy_filters.find_by(id: params[:taxonomy_filter_id])
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class TaxonomyItemsController < Decidim::Admin::ApplicationController
6
+ layout false
7
+
8
+ helper_method :taxonomy, :taxonomy_item, :parent_options, :selected_parent_id
9
+ before_action do
10
+ if taxonomy_item && taxonomy_item.parent_ids.exclude?(taxonomy.id)
11
+ flash[:alert] = I18n.t("update.invalid", scope: "decidim.admin.taxonomies")
12
+ render plain: I18n.t("update.invalid", scope: "decidim.admin.taxonomies"), status: :unprocessable_entity
13
+ end
14
+ end
15
+
16
+ def new
17
+ enforce_permission_to :create, :taxonomy_item
18
+ @form = form(Decidim::Admin::TaxonomyItemForm).instance
19
+ end
20
+
21
+ def create
22
+ enforce_permission_to :create, :taxonomy_item
23
+ @form = form(Decidim::Admin::TaxonomyItemForm).from_params(params)
24
+ CreateTaxonomy.call(@form) do
25
+ on(:ok) do
26
+ flash[:notice] = I18n.t("create.success", scope: "decidim.admin.taxonomies")
27
+ redirect_to edit_taxonomy_path(taxonomy)
28
+ end
29
+
30
+ on(:invalid) do
31
+ flash.now[:alert] = I18n.t("create.invalid", scope: "decidim.admin.taxonomies")
32
+ render action: "new"
33
+ end
34
+ end
35
+ end
36
+
37
+ def edit
38
+ enforce_permission_to :update, :taxonomy_item, taxonomy: taxonomy_item
39
+ @form = form(Decidim::Admin::TaxonomyItemForm).from_model(taxonomy_item)
40
+ end
41
+
42
+ def update
43
+ enforce_permission_to :update, :taxonomy_item, taxonomy: taxonomy_item
44
+ @form = form(Decidim::Admin::TaxonomyItemForm).from_params(params)
45
+ UpdateTaxonomy.call(@form, taxonomy_item) do
46
+ on(:ok) do
47
+ flash[:notice] = I18n.t("update.success", scope: "decidim.admin.taxonomies")
48
+ redirect_to edit_taxonomy_path(taxonomy)
49
+ end
50
+
51
+ on(:invalid) do
52
+ flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.admin.taxonomies")
53
+ render action: "edit"
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def taxonomy
61
+ @taxonomy ||= Decidim::Taxonomy.find_by(organization: current_organization, id: params[:taxonomy_id])
62
+ end
63
+
64
+ def taxonomy_item
65
+ @taxonomy_item ||= Decidim::Taxonomy.find_by(organization: current_organization, id: params[:id])
66
+ end
67
+
68
+ def selected_parent_id
69
+ @selected_parent_id ||= taxonomy_item&.parent_id || taxonomy.id
70
+ end
71
+
72
+ def parent_options
73
+ @parent_options ||= begin
74
+ options = [[I18n.t("new.none", scope: "decidim.admin.taxonomy_items"), taxonomy.id]]
75
+ taxonomy.children.each do |child|
76
+ next if child.id == taxonomy_item&.id
77
+
78
+ options << [translated_attribute(child.name).to_s, child.id]
79
+ # add children to the list with indentation
80
+ child.children.each do |grandchild|
81
+ next if grandchild.id == taxonomy_item&.id
82
+
83
+ options << ["&nbsp;&nbsp;&nbsp;#{translated_attribute(grandchild.name)}".html_safe, grandchild.id]
84
+ end
85
+ end
86
+ options
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end