decidim-admin 0.26.2 → 0.27.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-admin might be problematic. Click here for more details.

Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/admin/attachments_privacy_warning/show.erb +3 -0
  3. data/app/cells/decidim/admin/attachments_privacy_warning_cell.rb +19 -0
  4. data/app/commands/decidim/admin/block_user.rb +1 -1
  5. data/app/commands/decidim/admin/close_session_managed_user.rb +1 -1
  6. data/app/commands/decidim/admin/create_area.rb +1 -1
  7. data/app/commands/decidim/admin/create_area_type.rb +6 -3
  8. data/app/commands/decidim/admin/create_attachment.rb +14 -6
  9. data/app/commands/decidim/admin/create_attachment_collection.rb +13 -4
  10. data/app/commands/decidim/admin/create_category.rb +6 -4
  11. data/app/commands/decidim/admin/create_component.rb +1 -1
  12. data/app/commands/decidim/admin/create_import.rb +4 -5
  13. data/app/commands/decidim/admin/create_import_example.rb +1 -1
  14. data/app/commands/decidim/admin/create_newsletter.rb +1 -1
  15. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +1 -1
  16. data/app/commands/decidim/admin/create_scope.rb +1 -1
  17. data/app/commands/decidim/admin/create_scope_type.rb +6 -3
  18. data/app/commands/decidim/admin/create_static_page.rb +1 -1
  19. data/app/commands/decidim/admin/create_static_page_topic.rb +1 -1
  20. data/app/commands/decidim/admin/deliver_newsletter.rb +6 -6
  21. data/app/commands/decidim/admin/destroy_area.rb +1 -1
  22. data/app/commands/decidim/admin/destroy_category.rb +6 -3
  23. data/app/commands/decidim/admin/destroy_component.rb +1 -1
  24. data/app/commands/decidim/admin/destroy_newsletter.rb +1 -1
  25. data/app/commands/decidim/admin/destroy_participatory_space_private_user.rb +1 -1
  26. data/app/commands/decidim/admin/destroy_scope.rb +1 -1
  27. data/app/commands/decidim/admin/destroy_share_token.rb +1 -1
  28. data/app/commands/decidim/admin/destroy_static_page.rb +1 -1
  29. data/app/commands/decidim/admin/destroy_static_page_topic.rb +1 -1
  30. data/app/commands/decidim/admin/hide_resource.rb +2 -2
  31. data/app/commands/decidim/admin/impersonate_user.rb +1 -1
  32. data/app/commands/decidim/admin/invite_admin.rb +1 -1
  33. data/app/commands/decidim/admin/officialize_user.rb +1 -1
  34. data/app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb +7 -3
  35. data/app/commands/decidim/admin/process_user_group_verification_csv.rb +8 -4
  36. data/app/commands/decidim/admin/promote_managed_user.rb +1 -1
  37. data/app/commands/decidim/admin/publish_component.rb +1 -1
  38. data/app/commands/decidim/admin/reject_user_group.rb +1 -1
  39. data/app/commands/decidim/admin/remove_admin.rb +1 -1
  40. data/app/commands/decidim/admin/reorder_content_blocks.rb +1 -1
  41. data/app/commands/decidim/admin/transfer_user.rb +1 -1
  42. data/app/commands/decidim/admin/unblock_user.rb +1 -1
  43. data/app/commands/decidim/admin/unhide_resource.rb +1 -1
  44. data/app/commands/decidim/admin/unofficialize_user.rb +1 -1
  45. data/app/commands/decidim/admin/unpublish_component.rb +1 -1
  46. data/app/commands/decidim/admin/unreport_resource.rb +1 -1
  47. data/app/commands/decidim/admin/unreport_user.rb +1 -1
  48. data/app/commands/decidim/admin/update_area.rb +1 -1
  49. data/app/commands/decidim/admin/update_area_type.rb +8 -3
  50. data/app/commands/decidim/admin/update_attachment.rb +4 -3
  51. data/app/commands/decidim/admin/update_attachment_collection.rb +8 -3
  52. data/app/commands/decidim/admin/update_category.rb +9 -5
  53. data/app/commands/decidim/admin/update_component.rb +8 -5
  54. data/app/commands/decidim/admin/update_component_permissions.rb +9 -6
  55. data/app/commands/decidim/admin/update_content_block.rb +1 -1
  56. data/app/commands/decidim/admin/update_external_domain_whitelist.rb +6 -3
  57. data/app/commands/decidim/admin/update_help_sections.rb +17 -3
  58. data/app/commands/decidim/admin/update_newsletter.rb +1 -1
  59. data/app/commands/decidim/admin/update_organization.rb +1 -1
  60. data/app/commands/decidim/admin/update_organization_appearance.rb +1 -1
  61. data/app/commands/decidim/admin/update_organization_tos_version.rb +1 -1
  62. data/app/commands/decidim/admin/update_resource_permissions.rb +2 -2
  63. data/app/commands/decidim/admin/update_scope.rb +1 -1
  64. data/app/commands/decidim/admin/update_scope_type.rb +8 -3
  65. data/app/commands/decidim/admin/update_static_page.rb +1 -1
  66. data/app/commands/decidim/admin/update_static_page_topic.rb +1 -1
  67. data/app/commands/decidim/admin/update_user_groups.rb +1 -1
  68. data/app/commands/decidim/admin/verify_user_group.rb +1 -1
  69. data/app/controllers/concerns/decidim/admin/filterable.rb +1 -1
  70. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +3 -1
  71. data/app/controllers/decidim/admin/application_controller.rb +1 -0
  72. data/app/controllers/decidim/admin/area_types_controller.rb +6 -3
  73. data/app/controllers/decidim/admin/categories_controller.rb +3 -3
  74. data/app/controllers/decidim/admin/component_permissions_controller.rb +1 -1
  75. data/app/controllers/decidim/admin/components/base_controller.rb +1 -0
  76. data/app/controllers/decidim/admin/components_controller.rb +1 -1
  77. data/app/controllers/decidim/admin/concerns/has_attachment_collections.rb +6 -3
  78. data/app/controllers/decidim/admin/concerns/has_attachments.rb +6 -3
  79. data/app/controllers/decidim/admin/concerns/has_private_users_csv_import.rb +7 -0
  80. data/app/controllers/decidim/admin/dashboard_controller.rb +4 -3
  81. data/app/controllers/decidim/admin/exports_controller.rb +4 -1
  82. data/app/controllers/decidim/admin/help_sections_controller.rb +1 -1
  83. data/app/controllers/decidim/admin/metrics_controller.rb +2 -1
  84. data/app/controllers/decidim/admin/moderations_controller.rb +9 -7
  85. data/app/controllers/decidim/admin/organization_controller.rb +3 -3
  86. data/app/controllers/decidim/admin/organization_external_domain_whitelist_controller.rb +1 -1
  87. data/app/controllers/decidim/admin/reminders_controller.rb +61 -0
  88. data/app/controllers/decidim/admin/resource_permissions_controller.rb +3 -3
  89. data/app/controllers/decidim/admin/scope_types_controller.rb +6 -3
  90. data/app/controllers/decidim/admin/static_pages_controller.rb +1 -7
  91. data/app/forms/decidim/admin/category_form.rb +1 -2
  92. data/app/forms/decidim/admin/component_form.rb +16 -7
  93. data/app/forms/decidim/admin/import_example_form.rb +1 -5
  94. data/app/forms/decidim/admin/import_form.rb +7 -10
  95. data/app/forms/decidim/admin/managed_user_promotion_form.rb +1 -1
  96. data/app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb +7 -4
  97. data/app/forms/decidim/admin/permission_form.rb +9 -8
  98. data/app/forms/decidim/admin/permissions_form.rb +1 -10
  99. data/app/forms/decidim/admin/user_group_csv_verification_form.rb +2 -2
  100. data/app/helpers/decidim/admin/bulk_actions_helper.rb +0 -4
  101. data/app/helpers/decidim/admin/moderations/reports_helper.rb +11 -2
  102. data/app/helpers/decidim/admin/reminders_helper.rb +12 -0
  103. data/app/helpers/decidim/admin/settings_helper.rb +57 -11
  104. data/app/packs/entrypoints/decidim_admin.js +7 -2
  105. data/app/packs/src/decidim/admin/admin_autocomplete.js +86 -0
  106. data/app/packs/src/decidim/admin/application.js +0 -16
  107. data/app/packs/src/decidim/admin/choose_language.js +11 -9
  108. data/app/packs/src/decidim/admin/dynamic_fields.component.js +1 -0
  109. data/app/packs/stylesheets/decidim/admin/_decidim.scss +0 -1
  110. data/app/packs/stylesheets/decidim/admin/modules/_autocomplete.scss +5 -0
  111. data/app/packs/stylesheets/decidim/admin/modules/_forms.scss +6 -0
  112. data/app/packs/stylesheets/decidim/admin/modules/_modules.scss +2 -0
  113. data/app/packs/stylesheets/decidim/admin/modules/_upload_modal.scss +42 -0
  114. data/app/permissions/decidim/admin/permissions.rb +1 -0
  115. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +3 -1
  116. data/app/queries/decidim/admin/active_users_counter.rb +1 -1
  117. data/app/queries/decidim/admin/newsletter_recipients.rb +2 -2
  118. data/app/queries/decidim/admin/user_filter.rb +1 -1
  119. data/app/queries/decidim/admin/user_groups_evaluation.rb +1 -1
  120. data/app/views/decidim/admin/attachments/index.html.erb +1 -0
  121. data/app/views/decidim/admin/categories/_form.html.erb +0 -4
  122. data/app/views/decidim/admin/categories/show.html.erb +1 -2
  123. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +5 -4
  124. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  125. data/app/views/decidim/admin/participatory_space_private_users_csv_imports/new.html.erb +20 -1
  126. data/app/views/decidim/admin/reminders/new.html.erb +21 -0
  127. data/app/views/decidim/admin/resource_permissions/edit.html.erb +1 -1
  128. data/app/views/decidim/admin/shared/_gallery.html.erb +6 -1
  129. data/app/views/decidim/admin/shared/_js-callout.html.erb +6 -0
  130. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +2 -2
  131. data/app/views/layouts/decidim/admin/_application.html.erb +2 -0
  132. data/config/locales/ar.yml +15 -4
  133. data/config/locales/bg.yml +1 -0
  134. data/config/locales/ca.yml +22 -4
  135. data/config/locales/cs.yml +24 -4
  136. data/config/locales/de.yml +22 -4
  137. data/config/locales/el.yml +1 -5
  138. data/config/locales/en.yml +21 -4
  139. data/config/locales/eo.yml +1 -0
  140. data/config/locales/es-MX.yml +22 -4
  141. data/config/locales/es-PY.yml +22 -4
  142. data/config/locales/es.yml +22 -4
  143. data/config/locales/eu.yml +1 -5
  144. data/config/locales/fi-plain.yml +22 -4
  145. data/config/locales/fi.yml +22 -4
  146. data/config/locales/fr-CA.yml +22 -4
  147. data/config/locales/fr.yml +36 -18
  148. data/config/locales/ga-IE.yml +1 -0
  149. data/config/locales/gl.yml +16 -4
  150. data/config/locales/hu.yml +196 -3
  151. data/config/locales/id-ID.yml +1 -3
  152. data/config/locales/is-IS.yml +2 -4
  153. data/config/locales/it.yml +6 -5
  154. data/config/locales/ja.yml +21 -4
  155. data/config/locales/lb.yml +1 -5
  156. data/config/locales/lt.yml +994 -0
  157. data/config/locales/lv.yml +1 -3
  158. data/config/locales/nl.yml +83 -5
  159. data/config/locales/no.yml +27 -4
  160. data/config/locales/pl.yml +77 -5
  161. data/config/locales/pt-BR.yml +1 -5
  162. data/config/locales/pt.yml +1 -5
  163. data/config/locales/ro-RO.yml +7 -5
  164. data/config/locales/ru.yml +1 -3
  165. data/config/locales/sk.yml +1 -3
  166. data/config/locales/sl.yml +1 -0
  167. data/config/locales/sr-CS.yml +1 -2
  168. data/config/locales/sv.yml +22 -3
  169. data/config/locales/tr-TR.yml +1 -3
  170. data/config/locales/uk.yml +1 -2
  171. data/config/locales/val-ES.yml +1 -0
  172. data/config/locales/zh-CN.yml +1 -3
  173. data/lib/decidim/admin/engine.rb +0 -1
  174. data/lib/decidim/admin/import/importer.rb +9 -7
  175. data/lib/decidim/admin/import/readers/json.rb +1 -1
  176. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +15 -2
  177. data/lib/decidim/admin/test/commands/create_category_examples.rb +16 -6
  178. data/lib/decidim/admin/test/commands/destroy_category_examples.rb +29 -1
  179. data/lib/decidim/admin/test/commands/update_attachment_collection_examples.rb +15 -2
  180. data/lib/decidim/admin/test/commands/update_category_examples.rb +16 -6
  181. data/lib/decidim/admin/test/filters_participatory_space_user_roles_examples.rb +4 -4
  182. data/lib/decidim/admin/test/filters_participatory_space_users_examples.rb +4 -4
  183. data/lib/decidim/admin/test/forms/category_form_examples.rb +1 -21
  184. data/lib/decidim/admin/test/manage_attachments_examples.rb +9 -2
  185. data/lib/decidim/admin/test/manage_categories_examples.rb +0 -10
  186. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +0 -2
  187. data/lib/decidim/admin/test/manage_moderations_examples.rb +26 -0
  188. data/lib/decidim/admin/version.rb +1 -1
  189. metadata +21 -15
  190. data/app/packs/src/decidim/admin/autocomplete.component.js +0 -146
  191. data/app/packs/src/decidim/admin/autocomplete.component.test.js +0 -19
  192. data/app/packs/stylesheets/decidim/admin/components/_autocomplete_select.component.scss +0 -19
@@ -31,7 +31,7 @@ module Decidim
31
31
  enforce_permission_to :create, :attachment, attached_to: attached_to
32
32
  @form = form(::Decidim::Admin::AttachmentForm).from_params(params, attached_to: attached_to)
33
33
 
34
- CreateAttachment.call(@form, attached_to) do
34
+ CreateAttachment.call(@form, attached_to, current_user) do
35
35
  on(:ok) do
36
36
  flash[:notice] = I18n.t("attachments.create.success", scope: "decidim.admin")
37
37
  redirect_to action: :index
@@ -56,7 +56,7 @@ module Decidim
56
56
  enforce_permission_to :update, :attachment, attachment: attachment
57
57
  @form = form(::Decidim::Admin::AttachmentForm).from_params(attachment_params, attached_to: attached_to)
58
58
 
59
- UpdateAttachment.call(@attachment, @form) do
59
+ UpdateAttachment.call(@attachment, @form, current_user) do
60
60
  on(:ok) do
61
61
  flash[:notice] = I18n.t("attachments.update.success", scope: "decidim.admin")
62
62
  redirect_to action: :index
@@ -78,7 +78,10 @@ module Decidim
78
78
  def destroy
79
79
  @attachment = collection.find(params[:id])
80
80
  enforce_permission_to :destroy, :attachment, attachment: attachment
81
- @attachment.destroy!
81
+
82
+ Decidim.traceability.perform_action!("delete", @attachment, current_user) do
83
+ @attachment.destroy!
84
+ end
82
85
 
83
86
  flash[:notice] = I18n.t("attachments.destroy.success", scope: "decidim.admin")
84
87
 
@@ -18,6 +18,7 @@ module Decidim
18
18
  def new
19
19
  enforce_permission_to :csv_import, :space_private_user
20
20
  @form = form(ParticipatorySpacePrivateUserCsvImportForm).from_params({}, privatable_to: privatable_to)
21
+ @count = Decidim::ParticipatorySpacePrivateUser.by_participatory_space(privatable_to).count
21
22
  render template: "decidim/admin/participatory_space_private_users_csv_imports/new"
22
23
  end
23
24
 
@@ -38,6 +39,12 @@ module Decidim
38
39
  end
39
40
  end
40
41
 
42
+ def destroy_all
43
+ enforce_permission_to :csv_import, :space_private_user
44
+ Decidim::ParticipatorySpacePrivateUser.by_participatory_space(privatable_to).delete_all
45
+ redirect_to new_participatory_space_private_users_csv_imports_path
46
+ end
47
+
41
48
  # Public: Returns a String or Object that will be passed to `redirect_to` after
42
49
  # importing private users. By default it redirects to the privatable_to.
43
50
  #
@@ -27,7 +27,8 @@ module Decidim
27
27
  def metrics_presenter
28
28
  @metrics_presenter ||= Decidim::Admin::DashboardMetricChartsPresenter.new(
29
29
  summary: true,
30
- organization: current_organization
30
+ organization: current_organization,
31
+ view_context: view_context
31
32
  )
32
33
  end
33
34
 
@@ -37,10 +38,10 @@ module Decidim
37
38
  last_month = Time.zone.today.prev_month
38
39
 
39
40
  {
40
- total_admins_last_24: users_count(last_day, true),
41
+ total_admins_last_day: users_count(last_day, true),
41
42
  total_admins_last_week: users_count(last_week, true),
42
43
  total_admins_last_month: users_count(last_month, true),
43
- total_participants_last_24: users_count(last_day, false),
44
+ total_participants_last_day: users_count(last_day, false),
44
45
  total_participants_last_week: users_count(last_week, false),
45
46
  total_participants_last_month: users_count(last_month, false)
46
47
  }
@@ -9,7 +9,10 @@ module Decidim
9
9
  def create
10
10
  enforce_permission_to :export, :component_data, component: component
11
11
  name = params[:id]
12
- ExportJob.perform_later(current_user, component, name, params[:format] || default_format, params[:resource_id].presence)
12
+
13
+ Decidim.traceability.perform_action!("export_component", component, current_user, { name: name, format: params[:format] || default_format }) do
14
+ ExportJob.perform_later(current_user, component, name, params[:format] || default_format, params[:resource_id].presence)
15
+ end
13
16
 
14
17
  flash[:notice] = t("decidim.admin.exports.notice")
15
18
 
@@ -25,7 +25,7 @@ module Decidim
25
25
  params[:help_sections]
26
26
  )
27
27
 
28
- UpdateHelpSections.call(@form, current_organization) do
28
+ UpdateHelpSections.call(@form, current_organization, current_user) do
29
29
  on(:ok) do
30
30
  flash[:notice] = t("help_sections.success", scope: "decidim.admin")
31
31
  redirect_to action: :show
@@ -14,7 +14,8 @@ module Decidim
14
14
  def metrics_presenter
15
15
  @metrics_presenter ||= Decidim::Admin::DashboardMetricChartsPresenter.new(
16
16
  summary: false,
17
- organization: current_organization
17
+ organization: current_organization,
18
+ view_context: view_context
18
19
  )
19
20
  end
20
21
  end
@@ -67,16 +67,18 @@ module Decidim
67
67
 
68
68
  private
69
69
 
70
+ def ransack_params
71
+ query_params[:q] || { s: "created_at desc" }
72
+ end
73
+
70
74
  # Private: This method is used by the `Filterable` concern as the base query
71
75
  # without applying filtering and/or sorting options.
72
76
  def collection
73
- @collection ||= begin
74
- if params[:hidden]
75
- participatory_space_moderations.hidden
76
- else
77
- participatory_space_moderations.not_hidden
78
- end
79
- end
77
+ @collection ||= if params[:hidden]
78
+ participatory_space_moderations.hidden
79
+ else
80
+ participatory_space_moderations.not_hidden
81
+ end
80
82
  end
81
83
 
82
84
  # Private: Returns a collection of `Moderation` filtered and/or sorted by
@@ -30,11 +30,11 @@ module Decidim
30
30
  end
31
31
 
32
32
  def users
33
- search(current_organization.users)
33
+ search(current_organization.users.available)
34
34
  end
35
35
 
36
36
  def user_entities
37
- search(current_organization.user_entities)
37
+ search(current_organization.user_entities.available)
38
38
  end
39
39
 
40
40
  private
@@ -51,7 +51,7 @@ module Decidim
51
51
  query.where("email ILIKE ?", "%#{term}%")
52
52
  )
53
53
  end
54
- render json: query.all.collect { |u| { value: u.id, label: "#{u.name} (@#{u.nickname}) #{u.email}" } }
54
+ render json: query.all.collect { |u| { value: u.id, label: "#{u.name} (@#{u.nickname})" } }
55
55
  else
56
56
  render json: []
57
57
  end
@@ -16,7 +16,7 @@ module Decidim
16
16
  enforce_permission_to :update, :organization, organization: current_organization
17
17
  @form = form(OrganizationExternalDomainWhitelistForm).from_params(params)
18
18
 
19
- UpdateExternalDomainWhitelist.call(@form, current_organization) do
19
+ UpdateExternalDomainWhitelist.call(@form, current_organization, current_user) do
20
20
  on(:ok) do
21
21
  flash[:notice] = t("domain_whitelist.update.success", scope: "decidim.admin")
22
22
  redirect_to edit_organization_external_domain_whitelist_path
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class RemindersController < Admin::ApplicationController
6
+ include Decidim::ComponentPathHelper
7
+
8
+ helper_method :reminder_manifest
9
+
10
+ def new
11
+ enforce_permission_to :create, :reminder
12
+
13
+ @form = reminder_form_from_params(name: reminder_manifest.name)
14
+ render :new
15
+ end
16
+
17
+ def create
18
+ enforce_permission_to :create, :reminder
19
+
20
+ @form = reminder_form_from_params(params)
21
+
22
+ command_class.call(@form) do
23
+ on(:ok) do |reminders_queued|
24
+ flash[:notice] = t("decidim.admin.reminders.create.success", count: reminders_queued)
25
+ redirect_to manage_component_path(current_component)
26
+ end
27
+
28
+ on(:invalid) do
29
+ flash.now[:alert] = t("decidim.admin.reminders.create.error")
30
+ render :new
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def reminder_form_from_params(params)
38
+ form(reminder_manifest.form_class).from_params(
39
+ params,
40
+ current_component: current_component
41
+ )
42
+ end
43
+
44
+ def reminder_manifest
45
+ @reminder_manifest ||= Decidim.reminders_registry.for(reminder_name)
46
+ end
47
+
48
+ def reminder_name
49
+ params[:name]
50
+ end
51
+
52
+ def command_class
53
+ reminder_manifest.command_class
54
+ end
55
+
56
+ def current_component
57
+ @current_component ||= current_participatory_space.components.find(params[:component_id])
58
+ end
59
+ end
60
+ end
61
+ end
@@ -47,8 +47,8 @@ module Decidim
47
47
  def permission_forms
48
48
  actions.inject({}) do |result, action|
49
49
  form = PermissionForm.new(
50
- authorization_handlers: authorizations_for(action),
51
- authorizations_handlers_options: options_for(action)
50
+ authorization_handlers: authorizations_for(action).keys,
51
+ authorization_handlers_options: options_for(action)
52
52
  )
53
53
 
54
54
  result.update(action => form)
@@ -83,7 +83,7 @@ module Decidim
83
83
  end
84
84
 
85
85
  def manifest_name
86
- @manifest_name ||= resource.manifest.name
86
+ @manifest_name ||= resource.resource_manifest.name
87
87
  end
88
88
 
89
89
  def permissions
@@ -21,7 +21,7 @@ module Decidim
21
21
  enforce_permission_to :create, :scope_type
22
22
  @form = form(ScopeTypeForm).from_params(params)
23
23
 
24
- CreateScopeType.call(@form) do
24
+ CreateScopeType.call(@form, current_user) do
25
25
  on(:ok) do
26
26
  flash[:notice] = I18n.t("scope_types.create.success", scope: "decidim.admin")
27
27
  redirect_to scope_types_path
@@ -43,7 +43,7 @@ module Decidim
43
43
  enforce_permission_to :update, :scope_type, scope_type: scope_type
44
44
  @form = form(ScopeTypeForm).from_params(params)
45
45
 
46
- UpdateScopeType.call(scope_type, @form) do
46
+ UpdateScopeType.call(scope_type, @form, current_user) do
47
47
  on(:ok) do
48
48
  flash[:notice] = I18n.t("scope_types.update.success", scope: "decidim.admin")
49
49
  redirect_to scope_types_path
@@ -58,7 +58,10 @@ module Decidim
58
58
 
59
59
  def destroy
60
60
  enforce_permission_to :destroy, :scope_type, scope_type: scope_type
61
- scope_type.destroy!
61
+
62
+ Decidim.traceability.perform_action!("delete", scope_type, current_user) do
63
+ scope_type.destroy!
64
+ end
62
65
 
63
66
  flash[:notice] = I18n.t("scope_types.destroy.success", scope: "decidim.admin")
64
67
 
@@ -82,13 +82,7 @@ module Decidim
82
82
  form_params = params.to_unsafe_hash
83
83
  form_params["static_page"] ||= {}
84
84
  form_params["static_page"]["organization"] = current_organization
85
- form_params["static_page"]["allow_public_access"] ||= begin
86
- if page
87
- page.allow_public_access
88
- else
89
- false
90
- end
91
- end
85
+ form_params["static_page"]["allow_public_access"] ||= page ? page.allow_public_access : false
92
86
 
93
87
  return form_params unless page
94
88
 
@@ -9,12 +9,11 @@ module Decidim
9
9
 
10
10
  translatable_attribute :name, String
11
11
  attribute :weight, Integer, default: 0
12
- translatable_attribute :description, String
13
12
  attribute :parent_id, Integer
14
13
 
15
14
  mimic :category
16
15
 
17
- validates :name, :description, translatable_presence: true
16
+ validates :name, translatable_presence: true
18
17
  validates :parent_id, inclusion: { in: :parent_categories_ids }, allow_blank: true
19
18
 
20
19
  delegate :current_participatory_space, to: :context, prefix: false
@@ -21,10 +21,12 @@ module Decidim
21
21
 
22
22
  attribute :settings, Object
23
23
  attribute :default_step_settings, Object
24
- attribute :step_settings, Hash[String => Object]
24
+ attribute(:step_settings, { String => Object })
25
25
 
26
26
  attribute :share_tokens, Array[ShareToken]
27
27
 
28
+ validate :validate_settings, :validate_step_settings
29
+
28
30
  def settings?
29
31
  settings.manifest.attributes.any?
30
32
  end
@@ -39,13 +41,20 @@ module Decidim
39
41
 
40
42
  private
41
43
 
42
- # Overwrites Rectify::Form#form_attributes_valid? to validate nested `step_settings` attributes.
43
- def form_attributes_valid?
44
- return false unless errors.empty? && settings_errors_empty? # Preserves errors from custom validation methods
44
+ def validate_settings
45
+ return unless errors.empty? && settings_errors_empty? # Preserves errors from custom validation methods
46
+
47
+ attributes.each do |key, value|
48
+ next unless value.respond_to?(:valid?)
49
+
50
+ errors.add(key, :invalid) unless value.valid?
51
+ end
52
+ end
53
+
54
+ def validate_step_settings
55
+ return unless step_settings.respond_to?(:attributes)
45
56
 
46
- attributes_that_respond_to(:valid?).concat(
47
- step_settings.each_value.select { |attribute| attribute.respond_to?(:valid?) }
48
- ).all?(&:valid?)
57
+ errors.add(:step_settings, :invalid) unless step_settings.attributes.values.all? { |v| !v.respond_to?(:valid?) || v.valid? }
49
58
  end
50
59
 
51
60
  def settings_errors_empty?
@@ -35,11 +35,7 @@ module Decidim
35
35
  end
36
36
 
37
37
  def reader
38
- @reader ||= begin
39
- return unless reader_klass
40
-
41
- reader_klass.new("/dev/null")
42
- end
38
+ @reader ||= reader_klass ? reader_klass.new("/dev/null") : nil
43
39
  end
44
40
 
45
41
  def reader_klass
@@ -5,9 +5,10 @@ module Decidim
5
5
  class ImportForm < Form
6
6
  ACCEPTED_MIME_TYPES = Decidim::Admin::Import::Readers::ACCEPTED_MIME_TYPES
7
7
  include Decidim::HasUploadValidations
8
+ include Decidim::ProcessesFileLocally
8
9
 
9
10
  attribute :name, String
10
- attribute :file
11
+ attribute :file, Decidim::Attributes::Blob
11
12
 
12
13
  validates :file, presence: true
13
14
  validates :name, presence: true
@@ -16,7 +17,7 @@ module Decidim
16
17
  validate :verify_import, if: -> { file.present? && accepted_mime_type? && !importer.invalid_file? }
17
18
 
18
19
  def importer
19
- @importer ||= importer_for(file_path, mime_type)
20
+ @importer ||= importer_for(file, mime_type)
20
21
  end
21
22
 
22
23
  private
@@ -44,15 +45,11 @@ module Decidim
44
45
  def verify_import
45
46
  return if importer.verify
46
47
 
47
- importer.errors.each do |_col, message|
48
- errors.add(:file, message)
48
+ importer.errors.each do |error|
49
+ errors.add(:file, error.message)
49
50
  end
50
51
  end
51
52
 
52
- def file_path
53
- file&.path
54
- end
55
-
56
53
  def mime_type
57
54
  file&.content_type
58
55
  end
@@ -61,9 +58,9 @@ module Decidim
61
58
  manifest.creator
62
59
  end
63
60
 
64
- def importer_for(filepath, mime_type)
61
+ def importer_for(path, mime_type)
65
62
  Import::ImporterFactory.build(
66
- filepath,
63
+ path,
67
64
  mime_type,
68
65
  context: importer_context,
69
66
  creator: creator_class
@@ -7,7 +7,7 @@ module Decidim
7
7
  class ManagedUserPromotionForm < Form
8
8
  attribute :email, String
9
9
 
10
- validates :email, presence: true, 'valid_email_2/email': { disposable: true }
10
+ validates :email, presence: true, "valid_email_2/email": { disposable: true }
11
11
  validate :unique_email
12
12
 
13
13
  private
@@ -8,19 +8,22 @@ module Decidim
8
8
  #
9
9
  class ParticipatorySpacePrivateUserCsvImportForm < Form
10
10
  include Decidim::HasUploadValidations
11
+ include Decidim::ProcessesFileLocally
11
12
 
12
- attribute :file
13
+ attribute :file, Decidim::Attributes::Blob
13
14
  attribute :user_name, String
14
15
  attribute :email, String
15
16
 
16
- validates :file, presence: true
17
+ validates :file, presence: true, file_content_type: { allow: ["text/csv"] }
17
18
  validate :validate_csv
18
19
 
19
20
  def validate_csv
20
21
  return if file.blank?
21
22
 
22
- CSV.foreach(file.path) do |_email, user_name|
23
- errors.add(:user_name, :invalid) unless user_name.match?(UserBaseEntity::REGEXP_NAME)
23
+ process_file_locally(file) do |file_path|
24
+ CSV.foreach(file_path) do |_email, user_name|
25
+ errors.add(:user_name, :invalid) unless user_name.match?(UserBaseEntity::REGEXP_NAME)
26
+ end
24
27
  end
25
28
  end
26
29
  end
@@ -4,15 +4,21 @@ module Decidim
4
4
  module Admin
5
5
  # This form handles permissions for a particular action in the admin panel.
6
6
  class PermissionForm < Form
7
- attribute :authorization_handlers, Hash
8
- attribute :authorization_handlers_options, Hash
7
+ attribute :authorization_handlers, Array[String]
8
+ attribute(:authorization_handlers_options, { String => Object })
9
+
10
+ def authorization_handlers
11
+ handlers = super || []
12
+
13
+ handlers.index_with { |name| { "options" => authorization_handler_options(name) } }
14
+ end
9
15
 
10
16
  def authorization_handlers_names
11
17
  authorization_handlers.keys.map(&:to_s)
12
18
  end
13
19
 
14
20
  def authorization_handler_options(handler_name)
15
- find_handler(handler_name)&.dig("options") || {}
21
+ authorization_handlers_options&.dig(handler_name.to_s) || {}
16
22
  end
17
23
 
18
24
  def manifest(handler_name)
@@ -33,11 +39,6 @@ module Decidim
33
39
  def options_manifest(handler_name)
34
40
  manifest(handler_name).options
35
41
  end
36
-
37
- def find_handler(handler_name)
38
- authorization_handlers[handler_name.to_s] ||
39
- authorization_handlers[handler_name.to_sym]
40
- end
41
42
  end
42
43
  end
43
44
  end
@@ -7,16 +7,7 @@ module Decidim
7
7
  class PermissionsForm < Form
8
8
  mimic :component_permissions
9
9
 
10
- attribute :permissions, Hash[String => PermissionForm]
11
-
12
- private
13
-
14
- # Overriding Rectify::Form#form_attributes_valid? to preserve errors from custom method validations.
15
- def form_attributes_valid?
16
- return false unless errors.empty? && permissions.each_value.map(&:errors).all?(&:empty?)
17
-
18
- super && permissions.values.all?(&:valid?)
19
- end
10
+ attribute(:permissions, { String => PermissionForm })
20
11
  end
21
12
  end
22
13
  end
@@ -7,9 +7,9 @@ module Decidim
7
7
  class UserGroupCsvVerificationForm < Form
8
8
  include Decidim::HasUploadValidations
9
9
 
10
- attribute :file
10
+ attribute :file, Decidim::Attributes::Blob
11
11
 
12
- validates :file, presence: true
12
+ validates :file, presence: true, file_content_type: { allow: ["text/csv"] }
13
13
  end
14
14
  end
15
15
  end
@@ -3,10 +3,6 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  module BulkActionsHelper
6
- def proposal_find(id)
7
- Decidim::Proposals::Proposal.find(id)
8
- end
9
-
10
6
  # Public: Generates a select field with the categories. Only leaf categories can be set as selected.
11
7
  #
12
8
  # categories - A collection of categories.
@@ -6,22 +6,31 @@ module Decidim
6
6
  # This module includes helpers to show moderation reports in admin
7
7
  module ReportsHelper
8
8
  include Decidim::Messaging::ConversationHelper
9
+ include Decidim::ResourceHelper
10
+ include Decidim::TranslationsHelper
9
11
 
10
12
  # Public: Returns the reportable's author names separated by commas.
11
13
  def reportable_author_name(reportable)
12
14
  reportable_authors = reportable.try(:authors) || [reportable.try(:normalized_author)]
13
15
  content_tag :ul, class: "reportable-authors" do
14
16
  reportable_authors.select(&:present?).map do |author|
15
- if author.is_a? User
17
+ case author
18
+ when User
16
19
  content_tag :li do
17
20
  link_to current_or_new_conversation_path_with(author), target: "_blank", rel: "noopener" do
18
21
  "#{author.name} #{icon "envelope-closed"}".html_safe
19
22
  end
20
23
  end
24
+ when Decidim::Meetings::Meeting
25
+ content_tag :li do
26
+ link_to resource_locator(author).path, target: "_blank", rel: "noopener" do
27
+ translated_attribute(author.title)
28
+ end
29
+ end
21
30
  else
22
31
  content_tag(:li, author.name)
23
32
  end
24
- end.join("").html_safe
33
+ end.join.html_safe
25
34
  end
26
35
  end
27
36
 
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module RemindersHelper
6
+ # Route to the correct reminder for a component.
7
+ def admin_reminders_path(component, options = {})
8
+ EngineRouter.admin_proxy(component.participatory_space).new_component_reminder_path(options.merge(component_id: component))
9
+ end
10
+ end
11
+ end
12
+ end