decidim-admin 0.23.5 → 0.24.2

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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_admin_manifest.js +1 -0
  3. data/app/assets/javascripts/decidim/admin/application.js.es6 +4 -1
  4. data/app/assets/javascripts/decidim/admin/budget_rule_toggler.component.js.es6 +23 -20
  5. data/app/assets/javascripts/decidim/admin/bundle.js +10 -17
  6. data/app/assets/javascripts/decidim/admin/bundle.js.map +1 -1
  7. data/app/assets/javascripts/decidim/admin/form.js.es6 +1 -0
  8. data/app/assets/javascripts/decidim/admin/import_guidance.js.es6 +29 -0
  9. data/app/assets/javascripts/decidim/admin/moderations.js.es6 +24 -0
  10. data/app/assets/javascripts/decidim/admin/proposal_infinite_edit.js.es6 +20 -0
  11. data/app/assets/javascripts/decidim/admin/subform_multi_toggler.component.js.es6 +2 -2
  12. data/app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6 +2 -2
  13. data/app/assets/javascripts/decidim/admin/user_moderations.js +2 -0
  14. data/app/assets/stylesheets/decidim/admin/_variables.scss +9 -0
  15. data/app/assets/stylesheets/decidim/admin/components/_dropdown-menu.scss +3 -0
  16. data/app/assets/stylesheets/decidim/admin/extra/_action-icon.scss +13 -0
  17. data/app/assets/stylesheets/decidim/admin/extra/_block_user.scss +5 -0
  18. data/app/assets/stylesheets/decidim/admin/extra/_title_bar.scss +1 -0
  19. data/app/assets/stylesheets/decidim/admin/modules/_moderations.scss +39 -0
  20. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +2 -0
  21. data/app/assets/stylesheets/decidim/admin/modules/_reveal.scss +5 -0
  22. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +6 -3
  23. data/app/assets/stylesheets/decidim/admin/modules/_user-login.scss +2 -2
  24. data/app/assets/stylesheets/decidim/admin/user_moderations.scss +3 -0
  25. data/app/assets/stylesheets/decidim/admin/utils/_settings.scss +1 -0
  26. data/app/cells/decidim/admin/content_block/show.erb +1 -1
  27. data/app/cells/decidim/admin/content_block_cell.rb +4 -0
  28. data/app/commands/decidim/admin/block_user.rb +70 -0
  29. data/app/commands/decidim/admin/create_import.rb +29 -0
  30. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +1 -1
  31. data/app/commands/decidim/admin/create_static_page.rb +2 -1
  32. data/app/commands/decidim/admin/hide_resource.rb +21 -0
  33. data/app/commands/decidim/admin/impersonate_user.rb +17 -1
  34. data/app/commands/decidim/admin/promote_managed_user.rb +10 -0
  35. data/app/commands/decidim/admin/reorder_content_blocks.rb +6 -3
  36. data/app/commands/decidim/admin/transfer_user.rb +78 -0
  37. data/app/commands/decidim/admin/unblock_user.rb +48 -0
  38. data/app/commands/decidim/admin/unreport_user.rb +46 -0
  39. data/app/commands/decidim/admin/update_organization_appearance.rb +12 -4
  40. data/app/commands/decidim/admin/update_static_page.rb +2 -1
  41. data/app/commands/decidim/admin/verify_user_group.rb +1 -1
  42. data/app/controllers/concerns/decidim/admin/filterable.rb +1 -1
  43. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +47 -0
  44. data/app/controllers/concerns/decidim/admin/landing_page.rb +105 -0
  45. data/app/controllers/concerns/decidim/admin/landing_page_content_blocks.rb +118 -0
  46. data/app/controllers/concerns/decidim/moderations/admin/filterable.rb +54 -0
  47. data/app/controllers/decidim/admin/block_user_controller.rb +60 -0
  48. data/app/controllers/decidim/admin/components/base_controller.rb +1 -0
  49. data/app/controllers/decidim/admin/conflicts_controller.rb +46 -0
  50. data/app/controllers/decidim/admin/exports_controller.rb +1 -2
  51. data/app/controllers/decidim/admin/global_moderations/reports_controller.rb +18 -0
  52. data/app/controllers/decidim/admin/global_moderations_controller.rb +32 -0
  53. data/app/controllers/decidim/admin/impersonations_controller.rb +1 -1
  54. data/app/controllers/decidim/admin/imports_controller.rb +52 -0
  55. data/app/controllers/decidim/admin/moderated_users_controller.rb +44 -0
  56. data/app/controllers/decidim/admin/moderations/reports_controller.rb +39 -0
  57. data/app/controllers/decidim/admin/moderations_controller.rb +31 -7
  58. data/app/controllers/decidim/admin/officializations_controller.rb +3 -3
  59. data/app/controllers/decidim/admin/organization_homepage_controller.rb +6 -2
  60. data/app/controllers/decidim/admin/static_pages_controller.rb +7 -0
  61. data/app/events/decidim/resource_hidden_event.rb +37 -0
  62. data/app/forms/decidim/admin/block_user_form.rb +25 -0
  63. data/app/forms/decidim/admin/import_form.rb +85 -0
  64. data/app/forms/decidim/admin/organization_appearance_form.rb +1 -2
  65. data/app/forms/decidim/admin/static_page_form.rb +6 -1
  66. data/app/forms/decidim/admin/transfer_user_form.rb +19 -0
  67. data/app/helpers/decidim/admin/admin_terms_helper.rb +0 -7
  68. data/app/helpers/decidim/admin/application_helper.rb +5 -4
  69. data/app/helpers/decidim/admin/exports_helper.rb +2 -2
  70. data/app/helpers/decidim/admin/filterable_helper.rb +3 -2
  71. data/app/helpers/decidim/admin/imports_helper.rb +43 -0
  72. data/app/helpers/decidim/admin/menu_helper.rb +10 -0
  73. data/app/helpers/decidim/admin/moderations/reports_helper.rb +40 -0
  74. data/app/helpers/decidim/admin/moderations_helper.rb +36 -0
  75. data/app/helpers/decidim/admin/newsletters_helper.rb +4 -10
  76. data/app/helpers/decidim/admin/settings_helper.rb +2 -1
  77. data/app/helpers/decidim/admin/sidebar_menu_helper.rb +13 -0
  78. data/app/helpers/decidim/admin/user_moderations_helper.rb +6 -0
  79. data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +1 -1
  80. data/app/jobs/decidim/admin/verify_user_group_from_csv_job.rb +1 -1
  81. data/app/permissions/decidim/admin/permissions.rb +7 -6
  82. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +1 -1
  83. data/app/presenters/decidim/admin/secondary_menu_presenter.rb +26 -0
  84. data/app/queries/decidim/admin/active_users_counter.rb +1 -2
  85. data/app/queries/decidim/admin/user_filter.rb +1 -2
  86. data/app/views/decidim/admin/admin_terms/show.html.erb +1 -1
  87. data/app/views/decidim/admin/area_types/index.html.erb +2 -2
  88. data/app/views/decidim/admin/areas/index.html.erb +1 -1
  89. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  90. data/app/views/decidim/admin/attachments/index.html.erb +1 -1
  91. data/app/views/decidim/admin/block_user/new.html.erb +22 -0
  92. data/app/views/decidim/admin/categories/index.html.erb +1 -1
  93. data/app/views/decidim/admin/components/_component.html.erb +12 -0
  94. data/app/views/decidim/admin/conflicts/edit.html.erb +46 -0
  95. data/app/views/decidim/admin/conflicts/index.html.erb +34 -0
  96. data/app/views/decidim/admin/dashboard/show.html.erb +2 -1
  97. data/app/views/decidim/admin/exports/_dropdown.html.erb +1 -1
  98. data/app/views/decidim/admin/imports/_dropdown.html.erb +9 -0
  99. data/app/views/decidim/admin/imports/new.html.erb +57 -0
  100. data/app/views/decidim/admin/moderated_users/_report.html.erb +10 -0
  101. data/app/views/decidim/admin/moderated_users/index.html.erb +78 -0
  102. data/app/views/decidim/admin/moderations/_report.html.erb +1 -1
  103. data/app/views/decidim/admin/moderations/index.html.erb +28 -9
  104. data/app/views/decidim/admin/moderations/reports/index.html.erb +102 -0
  105. data/app/views/decidim/admin/moderations/reports/show.html.erb +62 -0
  106. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  107. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +3 -3
  108. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  109. data/app/views/decidim/admin/officializations/index.html.erb +13 -4
  110. data/app/views/decidim/admin/organization_appearance/_form.html.erb +0 -4
  111. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +1 -1
  112. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +4 -4
  113. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  114. data/app/views/decidim/admin/scopes/index.html.erb +1 -1
  115. data/app/views/decidim/admin/shared/landing_page/edit.html.erb +47 -0
  116. data/app/views/decidim/admin/shared/landing_page_content_blocks/edit.html.erb +15 -0
  117. data/app/views/decidim/admin/static_pages/_form.html.erb +6 -0
  118. data/app/views/decidim/admin/static_pages/_topic.html.erb +3 -3
  119. data/app/views/decidim/admin/users/index.html.erb +2 -2
  120. data/app/views/layouts/decidim/admin/_application.html.erb +6 -1
  121. data/app/views/layouts/decidim/admin/_js_configuration.html.erb +26 -0
  122. data/app/views/layouts/decidim/admin/_title_bar.html.erb +2 -2
  123. data/app/views/layouts/decidim/admin/global_moderations.html.erb +7 -0
  124. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  125. data/app/views/layouts/decidim/admin/pages.html.erb +2 -2
  126. data/app/views/layouts/decidim/admin/settings.html.erb +2 -33
  127. data/app/views/layouts/decidim/admin/users.html.erb +11 -0
  128. data/config/locales/ar.yml +0 -5
  129. data/config/locales/bg.yml +0 -1
  130. data/config/locales/ca.yml +150 -4
  131. data/config/locales/cs.yml +151 -5
  132. data/config/locales/de.yml +150 -5
  133. data/config/locales/el.yml +55 -5
  134. data/config/locales/en.yml +151 -5
  135. data/config/locales/es-MX.yml +149 -3
  136. data/config/locales/es-PY.yml +149 -3
  137. data/config/locales/es.yml +149 -3
  138. data/config/locales/eu.yml +0 -3
  139. data/config/locales/fi-plain.yml +149 -3
  140. data/config/locales/fi.yml +149 -3
  141. data/config/locales/fr-CA.yml +146 -4
  142. data/config/locales/fr.yml +146 -4
  143. data/config/locales/gl.yml +120 -5
  144. data/config/locales/hu.yml +13 -5
  145. data/config/locales/id-ID.yml +0 -3
  146. data/config/locales/is-IS.yml +19 -3
  147. data/config/locales/it.yml +59 -5
  148. data/config/locales/ja.yml +59 -5
  149. data/config/locales/lv.yml +0 -5
  150. data/config/locales/nl.yml +113 -4
  151. data/config/locales/no.yml +11 -5
  152. data/config/locales/pl.yml +150 -5
  153. data/config/locales/pt-BR.yml +0 -3
  154. data/config/locales/pt.yml +0 -5
  155. data/config/locales/ro-RO.yml +102 -5
  156. data/config/locales/ru.yml +0 -3
  157. data/config/locales/sk.yml +0 -5
  158. data/config/locales/sl.yml +0 -1
  159. data/config/locales/sr-CS.yml +0 -3
  160. data/config/locales/sv.yml +149 -4
  161. data/config/locales/tr-TR.yml +81 -4
  162. data/config/locales/uk.yml +0 -3
  163. data/config/locales/zh-CN.yml +0 -5
  164. data/config/routes.rb +21 -1
  165. data/lib/decidim/admin.rb +6 -0
  166. data/lib/decidim/admin/engine.rb +76 -1
  167. data/lib/decidim/admin/import.rb +12 -0
  168. data/lib/decidim/admin/import/creator.rb +82 -0
  169. data/lib/decidim/admin/import/importer.rb +82 -0
  170. data/lib/decidim/admin/import/importer_factory.rb +17 -0
  171. data/lib/decidim/admin/import/readers.rb +39 -0
  172. data/lib/decidim/admin/import/readers/base.rb +31 -0
  173. data/lib/decidim/admin/import/readers/csv.rb +23 -0
  174. data/lib/decidim/admin/import/readers/json.rb +25 -0
  175. data/lib/decidim/admin/import/readers/xls.rb +25 -0
  176. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +6 -6
  177. data/lib/decidim/admin/test/commands/create_category_examples.rb +6 -6
  178. data/lib/decidim/admin/test/filterable_examples.rb +1 -8
  179. data/lib/decidim/admin/test/manage_moderations_examples.rb +68 -4
  180. data/lib/decidim/admin/version.rb +1 -1
  181. metadata +71 -15
  182. data/app/assets/javascripts/decidim/admin/gallery.js.es6 +0 -5
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object used to officialize users from the admin dashboard.
6
+ class BlockUserForm < Form
7
+ attribute :user_id, Integer
8
+ attribute :justification, String
9
+
10
+ validates :user, presence: true
11
+ validates :justification, presence: true, length: { minimum: UserBlock::MINIMUM_JUSTIFICATION_LENGTH }
12
+
13
+ def map_model(user)
14
+ self.user_id = user.id
15
+ end
16
+
17
+ def user
18
+ @user ||= Decidim::User.find_by(
19
+ id: user_id,
20
+ organization: current_organization
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class ImportForm < Form
6
+ ACCEPTED_MIME_TYPES = Decidim::Admin::Import::Readers::ACCEPTED_MIME_TYPES
7
+
8
+ attribute :creator, String, default: ->(form, _attribute) { form.creators.first[:creator].to_s }
9
+ attribute :file
10
+ attribute :user_group_id, Integer
11
+
12
+ validates :file, presence: true
13
+ validates :creator, presence: true
14
+ validate :accepted_mime_type
15
+ validate :check_invalid_lines
16
+
17
+ def check_invalid_lines
18
+ return if file.blank? || !accepted_mime_type
19
+
20
+ importer.prepare
21
+ invalid_lines = importer.invalid_lines
22
+ errors.add(:file, I18n.t("decidim.admin.imports.invalid_lines", invalid_lines: invalid_lines.join(","))) unless invalid_lines.empty?
23
+ end
24
+
25
+ def file_path
26
+ file&.path
27
+ end
28
+
29
+ def mime_type
30
+ file&.content_type
31
+ end
32
+
33
+ def accepted_mime_type
34
+ accepted_mime_types = ACCEPTED_MIME_TYPES.values
35
+ return true if accepted_mime_types.include?(mime_type)
36
+ # Avoid duplicating error messages
37
+ return false if errors[:file].present?
38
+
39
+ errors.add(
40
+ :file,
41
+ I18n.t(
42
+ "activemodel.errors.new_import.attributes.file.invalid_mime_type",
43
+ valid_mime_types: ACCEPTED_MIME_TYPES.keys.map do |m|
44
+ I18n.t("decidim.admin.new_import.accepted_mime_types.#{m}")
45
+ end.join(", ")
46
+ )
47
+ )
48
+ false
49
+ end
50
+
51
+ def creators
52
+ @creators ||= current_component.manifest.import_manifests.map do |manifest|
53
+ { creator: manifest.creator, name: manifest.creator.to_s.split("::").last.downcase }
54
+ end
55
+ end
56
+
57
+ def creator_class
58
+ return creator.constantize if creator.is_a?(String)
59
+
60
+ creator
61
+ end
62
+
63
+ def user_group
64
+ @user_group ||= Decidim::UserGroup.find_by(
65
+ organization: current_organization,
66
+ id: user_group_id.to_i
67
+ )
68
+ end
69
+
70
+ def importer
71
+ @importer ||= importer_for(file_path, mime_type)
72
+ end
73
+
74
+ def importer_for(filepath, mime_type)
75
+ context[:user_group] = user_group
76
+ Import::ImporterFactory.build(
77
+ filepath,
78
+ mime_type,
79
+ context: context,
80
+ creator: creator_class
81
+ )
82
+ end
83
+ end
84
+ end
85
+ end
@@ -20,7 +20,6 @@ module Decidim
20
20
  attribute :official_img_footer
21
21
  attribute :remove_official_img_footer
22
22
  attribute :official_url
23
- attribute :show_statistics, Boolean
24
23
  attribute :header_snippets, String
25
24
  attribute :cta_button_path, String
26
25
  attribute :highlighted_content_banner_enabled, Boolean, default: false
@@ -47,7 +46,7 @@ module Decidim
47
46
  translatable_attribute :omnipresent_banner_title, String
48
47
  translatable_attribute :omnipresent_banner_short_description, String
49
48
 
50
- validates :cta_button_path, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-\_/]+\z} }, allow_blank: true
49
+ validates :cta_button_path, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-_/]+\z} }, allow_blank: true
51
50
  validates :official_img_header,
52
51
  :official_img_footer,
53
52
  :logo,
@@ -11,6 +11,7 @@ module Decidim
11
11
  translatable_attribute :content, String
12
12
  attribute :changed_notably, Boolean
13
13
  attribute :show_in_footer, Boolean
14
+ attribute :allow_public_access, Boolean
14
15
  attribute :weight, Integer
15
16
  attribute :topic_id, Integer
16
17
 
@@ -18,7 +19,7 @@ module Decidim
18
19
 
19
20
  validates :slug, presence: true
20
21
  validates :title, :content, translatable_presence: true
21
- validates :slug, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-\_/]+\z} }, allow_blank: true
22
+ validates :slug, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-_/]+\z} }, allow_blank: true
22
23
 
23
24
  validate :slug, :slug_uniqueness
24
25
 
@@ -41,6 +42,10 @@ module Decidim
41
42
  )
42
43
  end
43
44
 
45
+ def control_public_access?
46
+ current_organization.force_users_to_authenticate_before_access_organization?
47
+ end
48
+
44
49
  private
45
50
 
46
51
  def slug_uniqueness
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object used to transfer conflicted users from the admin dashboard.
6
+ #
7
+ # This form will contain a dynamic attribute for the user authorization.
8
+ # This authorization will be selected by the admin user if more than one exists.
9
+ class TransferUserForm < Form
10
+ attribute :email, String
11
+ attribute :reason, String
12
+ attribute :current_user, Decidim::User
13
+ attribute :conflict, Decidim::Verifications::Conflict
14
+
15
+ validates :current_user, presence: true
16
+ validates :conflict, presence: true
17
+ end
18
+ end
19
+ end
@@ -8,13 +8,6 @@ module Decidim
8
8
  current_organization.admin_terms_of_use_body.symbolize_keys[I18n.locale].html_safe
9
9
  end
10
10
 
11
- def admin_terms_announcement_args
12
- {
13
- callout_class: current_user.admin_terms_accepted? ? "success" : "warning",
14
- announcement: announcement_body
15
- }
16
- end
17
-
18
11
  def announcement_body
19
12
  if current_user.admin_terms_accepted?
20
13
  t("accept.success", scope: "decidim.admin.admin_terms_of_use")
@@ -15,10 +15,6 @@ module Decidim
15
15
  include Decidim::Admin::UserRolesHelper
16
16
  include Decidim::Admin::ResourceScopeHelper
17
17
 
18
- def title
19
- current_organization.name
20
- end
21
-
22
18
  # Adds a link to the secondary navigation so admins can easily access the public page of the
23
19
  # element their working on.
24
20
  #
@@ -32,6 +28,11 @@ module Decidim
32
28
  end
33
29
  end
34
30
  end
31
+
32
+ def participatory_space_active_link?(component)
33
+ endpoints = component.manifest.admin_engine.try(:participatory_space_endpoints)
34
+ endpoints && is_active_link?(decidim_admin_participatory_processes.components_path(current_participatory_space), %r{/\d+/manage/(#{endpoints.join("|")})\b})
35
+ end
35
36
  end
36
37
  end
37
38
  end
@@ -10,8 +10,8 @@ module Decidim
10
10
  # current component.
11
11
  #
12
12
  # Returns a rendered dropdown.
13
- def export_dropdown(component = current_component)
14
- render partial: "decidim/admin/exports/dropdown", locals: { component: component }
13
+ def export_dropdown(component = current_component, resource_id = nil)
14
+ render partial: "decidim/admin/exports/dropdown", locals: { component: component, resource_id: resource_id }
15
15
  end
16
16
 
17
17
  # Routes to the correct exporter for a component.
@@ -15,9 +15,10 @@ module Decidim
15
15
 
16
16
  filters_with_values.each_with_object({}) do |(filter, values), hash|
17
17
  link = filter_link_label(filter, i18n_scope)
18
- hash[link] = if values.is_a?(Array)
18
+ hash[link] = case values
19
+ when Array
19
20
  build_submenu_options_tree_from_array(filter, values, i18n_scope)
20
- elsif values.is_a?(Hash)
21
+ when Hash
21
22
  build_submenu_options_tree_from_hash(filter, values, i18n_scope)
22
23
  end
23
24
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module ImportsHelper
6
+ # Renders an import dropdown for the provided component. Additional dropdown items
7
+ # can be given as block.
8
+ #
9
+ # component - The component to render the export dropdown for. Defaults to the
10
+ # current component.
11
+ #
12
+ # resource_id - The resource id that is passed to route.
13
+ #
14
+ # Returns a rendered dropdown.
15
+ def import_dropdown(component = current_component, resource_id = nil)
16
+ locals = { component: component, resource_id: resource_id }
17
+ locals[:block] = yield if block_given?
18
+ render partial: "decidim/admin/imports/dropdown", locals: locals
19
+ end
20
+
21
+ # Routes to the correct importer for a component.
22
+ #
23
+ # component - The component to be routed.
24
+ # options - Extra options that need to be passed to the route.
25
+ #
26
+ # Returns the path to the component importer.
27
+ def admin_imports_path(component, options)
28
+ EngineRouter.admin_proxy(component.participatory_space).new_component_import_path(options.merge(component_id: component))
29
+ end
30
+
31
+ # Public: A formatted collection of mime_type to be used in forms.
32
+ def mime_types
33
+ accepted_mime_types = Decidim::Admin::Import::Readers::ACCEPTED_MIME_TYPES.keys
34
+ accepted_mime_types.map { |mime_type| t("decidim.admin.imports.new.accepted_mime_types.#{mime_type}") }.join(", ")
35
+ end
36
+
37
+ # Returns verified user groups of current user
38
+ def user_groups
39
+ Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
40
+ end
41
+ end
42
+ end
43
+ end
@@ -4,6 +4,8 @@ module Decidim
4
4
  module Admin
5
5
  # This module includes helpers to manage menus in admin layout
6
6
  module MenuHelper
7
+ include Decidim::Admin::SidebarMenuHelper
8
+
7
9
  # Public: Returns the main menu presenter object
8
10
  def main_menu
9
11
  @main_menu ||= ::Decidim::MenuPresenter.new(
@@ -12,6 +14,14 @@ module Decidim
12
14
  active_class: "is-active"
13
15
  )
14
16
  end
17
+
18
+ def global_moderation_menu
19
+ @global_moderation_menu ||= sidebar_menu(:admin_global_moderation_menu)
20
+ end
21
+
22
+ def organization_settings_menu
23
+ @organization_settings_menu ||= sidebar_menu(:admin_settings_menu)
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module Moderations
6
+ # This module includes helpers to show moderation reports in admin
7
+ module ReportsHelper
8
+ include Decidim::Messaging::ConversationHelper
9
+
10
+ # Public: Returns the reportable's author names separated by commas.
11
+ def reportable_author_name(reportable)
12
+ reportable_authors = reportable.try(:authors) || [reportable.try(:normalized_author)]
13
+ content_tag :ul, class: "reportable-authors" do
14
+ reportable_authors.select(&:present?).map do |author|
15
+ if author.is_a? User
16
+ content_tag :li do
17
+ link_to current_or_new_conversation_path_with(author), target: "_blank", rel: "noopener" do
18
+ "#{author.name} #{icon "envelope-closed"}".html_safe
19
+ end
20
+ end
21
+ else
22
+ content_tag(:li, author.name)
23
+ end
24
+ end.join("").html_safe
25
+ end
26
+ end
27
+
28
+ # Public: Renders a small preview of the content reported.
29
+ def reported_content_for(reportable, options = {})
30
+ cell "decidim/reported_content", reportable, options
31
+ end
32
+
33
+ # Public: Whether the resource has some translated attribute or not.
34
+ def translatable_resource?(reportable)
35
+ reportable.respond_to?(:content_original_language)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This module includes helpers to show moderation in admin
6
+ module ModerationsHelper
7
+ # Public: Renders an extract of the content reported in a text format.
8
+ def reported_content_excerpt_for(reportable, options = {})
9
+ I18n.with_locale(options.fetch(:locale, I18n.locale)) do
10
+ reportable_content = reportable.reported_attributes.map do |attribute_name|
11
+ attribute_value = reportable.attributes.with_indifferent_access[attribute_name]
12
+ next translated_attribute(attribute_value) if attribute_value.is_a? Hash
13
+
14
+ attribute_value
15
+ end
16
+ reportable_content.filter(&:present?).join(". ").truncate(options.fetch(:limit, 100))
17
+ end
18
+ end
19
+
20
+ # Public: Finds the type and name of the participatory space the given
21
+ # `reportable` object is associated to.
22
+ #
23
+ # Returns a String, or `nil` if the space is not found.
24
+ def participatory_space_title_for(reportable, options = {})
25
+ space = reportable.try(:participatory_space)
26
+ return unless space
27
+
28
+ I18n.with_locale(options.fetch(:locale, I18n.locale)) do
29
+ title = translated_attribute(space.try(:title) || space.try(:name))
30
+ type = space.class.model_name.human
31
+ [type, title].compact.join(": ").truncate(options.fetch(:limit, 100))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -131,23 +131,17 @@ module Decidim
131
131
  ]
132
132
  end
133
133
 
134
- def newsletter_attention_callout_args
134
+ def newsletter_attention_callout_announcement
135
135
  {
136
- announcement: {
137
- body: t("warning", scope: "decidim.admin.newsletters.select_recipients_to_deliver").html_safe
138
- },
139
- callout_class: "warning"
136
+ body: t("warning", scope: "decidim.admin.newsletters.select_recipients_to_deliver").html_safe
140
137
  }
141
138
  end
142
139
 
143
- def newsletter_recipients_count_callout_args
140
+ def newsletter_recipients_count_callout_announcement
144
141
  spinner = "<span id='recipients_count_spinner' class='loading-spinner hide'></span>"
145
142
  body = "#{t("recipients_count", scope: "decidim.admin.newsletters.select_recipients_to_deliver", count: recipients_count_query)} #{spinner}"
146
143
  {
147
- announcement: {
148
- body: body
149
- },
150
- callout_class: "warning"
144
+ body: body
151
145
  }
152
146
  end
153
147
  end
@@ -13,7 +13,8 @@ module Decidim
13
13
  string: :text_field,
14
14
  text: :text_area,
15
15
  scope: :scope_field,
16
- enum: :collection_radio_buttons
16
+ enum: :collection_radio_buttons,
17
+ time: :datetime_field
17
18
  }.freeze
18
19
 
19
20
  # Public: Renders a form field that matches a settings attribute's
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module SidebarMenuHelper
6
+ protected
7
+
8
+ def sidebar_menu(target_menu)
9
+ ::Decidim::Admin::SecondaryMenuPresenter.new(target_menu, self, active_class: "is-active")
10
+ end
11
+ end
12
+ end
13
+ end