decidim-admin 0.23.6 → 0.24.0.rc1

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 (177) 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 +2 -0
  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/user_moderations.js +2 -0
  12. data/app/assets/stylesheets/decidim/admin/_variables.scss +9 -0
  13. data/app/assets/stylesheets/decidim/admin/components/_dropdown-menu.scss +3 -0
  14. data/app/assets/stylesheets/decidim/admin/extra/_action-icon.scss +13 -0
  15. data/app/assets/stylesheets/decidim/admin/extra/_block_user.scss +5 -0
  16. data/app/assets/stylesheets/decidim/admin/extra/_title_bar.scss +1 -0
  17. data/app/assets/stylesheets/decidim/admin/modules/_moderations.scss +39 -0
  18. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +2 -0
  19. data/app/assets/stylesheets/decidim/admin/modules/_reveal.scss +5 -0
  20. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +6 -3
  21. data/app/assets/stylesheets/decidim/admin/modules/_user-login.scss +2 -2
  22. data/app/assets/stylesheets/decidim/admin/user_moderations.scss +3 -0
  23. data/app/assets/stylesheets/decidim/admin/utils/_settings.scss +1 -0
  24. data/app/cells/decidim/admin/content_block/show.erb +1 -1
  25. data/app/cells/decidim/admin/content_block_cell.rb +4 -0
  26. data/app/commands/decidim/admin/block_user.rb +70 -0
  27. data/app/commands/decidim/admin/create_import.rb +29 -0
  28. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +1 -1
  29. data/app/commands/decidim/admin/create_static_page.rb +2 -1
  30. data/app/commands/decidim/admin/hide_resource.rb +21 -0
  31. data/app/commands/decidim/admin/impersonate_user.rb +17 -1
  32. data/app/commands/decidim/admin/promote_managed_user.rb +10 -0
  33. data/app/commands/decidim/admin/reorder_content_blocks.rb +6 -3
  34. data/app/commands/decidim/admin/transfer_user.rb +78 -0
  35. data/app/commands/decidim/admin/unblock_user.rb +48 -0
  36. data/app/commands/decidim/admin/unreport_user.rb +46 -0
  37. data/app/commands/decidim/admin/update_organization_appearance.rb +12 -4
  38. data/app/commands/decidim/admin/update_static_page.rb +2 -1
  39. data/app/commands/decidim/admin/verify_user_group.rb +1 -1
  40. data/app/controllers/concerns/decidim/admin/filterable.rb +1 -1
  41. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +51 -0
  42. data/app/controllers/concerns/decidim/admin/landing_page.rb +105 -0
  43. data/app/controllers/concerns/decidim/admin/landing_page_content_blocks.rb +118 -0
  44. data/app/controllers/concerns/decidim/moderations/admin/filterable.rb +54 -0
  45. data/app/controllers/decidim/admin/block_user_controller.rb +60 -0
  46. data/app/controllers/decidim/admin/components/base_controller.rb +1 -0
  47. data/app/controllers/decidim/admin/conflicts_controller.rb +46 -0
  48. data/app/controllers/decidim/admin/exports_controller.rb +1 -2
  49. data/app/controllers/decidim/admin/global_moderations/reports_controller.rb +18 -0
  50. data/app/controllers/decidim/admin/global_moderations_controller.rb +32 -0
  51. data/app/controllers/decidim/admin/impersonations_controller.rb +1 -1
  52. data/app/controllers/decidim/admin/imports_controller.rb +52 -0
  53. data/app/controllers/decidim/admin/moderated_users_controller.rb +44 -0
  54. data/app/controllers/decidim/admin/moderations/reports_controller.rb +39 -0
  55. data/app/controllers/decidim/admin/moderations_controller.rb +31 -7
  56. data/app/controllers/decidim/admin/officializations_controller.rb +3 -3
  57. data/app/controllers/decidim/admin/organization_homepage_controller.rb +6 -2
  58. data/app/controllers/decidim/admin/static_pages_controller.rb +7 -0
  59. data/app/events/decidim/resource_hidden_event.rb +37 -0
  60. data/app/forms/decidim/admin/block_user_form.rb +25 -0
  61. data/app/forms/decidim/admin/import_form.rb +85 -0
  62. data/app/forms/decidim/admin/organization_appearance_form.rb +1 -2
  63. data/app/forms/decidim/admin/static_page_form.rb +6 -1
  64. data/app/forms/decidim/admin/transfer_user_form.rb +19 -0
  65. data/app/helpers/decidim/admin/application_helper.rb +5 -4
  66. data/app/helpers/decidim/admin/exports_helper.rb +2 -2
  67. data/app/helpers/decidim/admin/filterable_helper.rb +3 -2
  68. data/app/helpers/decidim/admin/imports_helper.rb +43 -0
  69. data/app/helpers/decidim/admin/menu_helper.rb +10 -0
  70. data/app/helpers/decidim/admin/moderations/reports_helper.rb +40 -0
  71. data/app/helpers/decidim/admin/moderations_helper.rb +36 -0
  72. data/app/helpers/decidim/admin/newsletters_helper.rb +4 -10
  73. data/app/helpers/decidim/admin/settings_helper.rb +2 -1
  74. data/app/helpers/decidim/admin/sidebar_menu_helper.rb +13 -0
  75. data/app/helpers/decidim/admin/user_moderations_helper.rb +6 -0
  76. data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +1 -1
  77. data/app/jobs/decidim/admin/verify_user_group_from_csv_job.rb +1 -1
  78. data/app/permissions/decidim/admin/permissions.rb +7 -6
  79. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +1 -1
  80. data/app/presenters/decidim/admin/secondary_menu_presenter.rb +26 -0
  81. data/app/queries/decidim/admin/active_users_counter.rb +1 -2
  82. data/app/queries/decidim/admin/user_filter.rb +1 -2
  83. data/app/views/decidim/admin/area_types/index.html.erb +2 -2
  84. data/app/views/decidim/admin/areas/index.html.erb +1 -1
  85. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  86. data/app/views/decidim/admin/attachments/index.html.erb +1 -1
  87. data/app/views/decidim/admin/block_user/new.html.erb +22 -0
  88. data/app/views/decidim/admin/categories/index.html.erb +1 -1
  89. data/app/views/decidim/admin/components/_component.html.erb +12 -0
  90. data/app/views/decidim/admin/components/_form.html.erb +1 -1
  91. data/app/views/decidim/admin/conflicts/edit.html.erb +46 -0
  92. data/app/views/decidim/admin/conflicts/index.html.erb +34 -0
  93. data/app/views/decidim/admin/dashboard/show.html.erb +1 -0
  94. data/app/views/decidim/admin/exports/_dropdown.html.erb +1 -1
  95. data/app/views/decidim/admin/imports/_dropdown.html.erb +9 -0
  96. data/app/views/decidim/admin/imports/new.html.erb +57 -0
  97. data/app/views/decidim/admin/moderated_users/_report.html.erb +10 -0
  98. data/app/views/decidim/admin/moderated_users/index.html.erb +78 -0
  99. data/app/views/decidim/admin/moderations/_report.html.erb +1 -1
  100. data/app/views/decidim/admin/moderations/index.html.erb +27 -9
  101. data/app/views/decidim/admin/moderations/reports/index.html.erb +102 -0
  102. data/app/views/decidim/admin/moderations/reports/show.html.erb +62 -0
  103. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  104. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +3 -3
  105. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  106. data/app/views/decidim/admin/officializations/index.html.erb +13 -4
  107. data/app/views/decidim/admin/organization_appearance/_form.html.erb +0 -4
  108. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +1 -1
  109. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +4 -4
  110. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +1 -1
  111. data/app/views/decidim/admin/scopes/index.html.erb +1 -1
  112. data/app/views/decidim/admin/shared/landing_page/edit.html.erb +47 -0
  113. data/app/views/decidim/admin/shared/landing_page_content_blocks/edit.html.erb +15 -0
  114. data/app/views/decidim/admin/static_pages/_form.html.erb +6 -0
  115. data/app/views/decidim/admin/static_pages/_topic.html.erb +3 -3
  116. data/app/views/decidim/admin/users/index.html.erb +2 -2
  117. data/app/views/layouts/decidim/admin/_application.html.erb +5 -1
  118. data/app/views/layouts/decidim/admin/_title_bar.html.erb +2 -2
  119. data/app/views/layouts/decidim/admin/global_moderations.html.erb +7 -0
  120. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  121. data/app/views/layouts/decidim/admin/pages.html.erb +2 -2
  122. data/app/views/layouts/decidim/admin/settings.html.erb +2 -33
  123. data/app/views/layouts/decidim/admin/users.html.erb +11 -0
  124. data/config/locales/ar.yml +0 -5
  125. data/config/locales/bg.yml +0 -1
  126. data/config/locales/ca.yml +33 -7
  127. data/config/locales/cs.yml +154 -9
  128. data/config/locales/de.yml +150 -5
  129. data/config/locales/el.yml +55 -5
  130. data/config/locales/en.yml +150 -5
  131. data/config/locales/es-MX.yml +42 -7
  132. data/config/locales/es-PY.yml +42 -7
  133. data/config/locales/es.yml +42 -7
  134. data/config/locales/eu.yml +0 -3
  135. data/config/locales/fi-plain.yml +148 -3
  136. data/config/locales/fi.yml +148 -3
  137. data/config/locales/fr-CA.yml +139 -4
  138. data/config/locales/fr.yml +139 -4
  139. data/config/locales/gl.yml +83 -12
  140. data/config/locales/hu.yml +13 -5
  141. data/config/locales/id-ID.yml +0 -3
  142. data/config/locales/is-IS.yml +19 -3
  143. data/config/locales/it.yml +59 -5
  144. data/config/locales/ja.yml +38 -5
  145. data/config/locales/lv.yml +0 -5
  146. data/config/locales/nl.yml +110 -4
  147. data/config/locales/no.yml +13 -7
  148. data/config/locales/pl.yml +159 -14
  149. data/config/locales/pt-BR.yml +0 -3
  150. data/config/locales/pt.yml +0 -5
  151. data/config/locales/ro-RO.yml +121 -133
  152. data/config/locales/ru.yml +0 -3
  153. data/config/locales/sk.yml +0 -5
  154. data/config/locales/sl.yml +0 -1
  155. data/config/locales/sr-CS.yml +0 -3
  156. data/config/locales/sv.yml +51 -5
  157. data/config/locales/tr-TR.yml +81 -4
  158. data/config/locales/uk.yml +0 -3
  159. data/config/locales/zh-CN.yml +0 -5
  160. data/config/routes.rb +21 -1
  161. data/lib/decidim/admin/engine.rb +76 -1
  162. data/lib/decidim/admin/import/creator.rb +82 -0
  163. data/lib/decidim/admin/import/importer.rb +82 -0
  164. data/lib/decidim/admin/import/importer_factory.rb +17 -0
  165. data/lib/decidim/admin/import/readers/base.rb +31 -0
  166. data/lib/decidim/admin/import/readers/csv.rb +23 -0
  167. data/lib/decidim/admin/import/readers/json.rb +25 -0
  168. data/lib/decidim/admin/import/readers/xls.rb +25 -0
  169. data/lib/decidim/admin/import/readers.rb +39 -0
  170. data/lib/decidim/admin/import.rb +12 -0
  171. data/lib/decidim/admin/test/commands/create_attachment_collection_examples.rb +6 -6
  172. data/lib/decidim/admin/test/commands/create_category_examples.rb +6 -6
  173. data/lib/decidim/admin/test/filterable_examples.rb +1 -8
  174. data/lib/decidim/admin/test/manage_moderations_examples.rb +49 -4
  175. data/lib/decidim/admin/version.rb +1 -1
  176. data/lib/decidim/admin.rb +6 -0
  177. metadata +72 -16
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class UnreportUser < Rectify::Command
6
+ # Public: Initializes the command.
7
+ #
8
+ # reportable - A Decidim::User - The user reported
9
+ # current_user - the user performing the action
10
+ def initialize(reportable, current_user)
11
+ @reportable = reportable
12
+ @current_user = current_user
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid, together with the resource.
18
+ # - :invalid if the resource is not reported
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) unless @reportable.reported?
23
+
24
+ unreport!
25
+ broadcast(:ok, @reportable)
26
+ end
27
+
28
+ private
29
+
30
+ def unreport!
31
+ Decidim.traceability.perform_action!(
32
+ "unreport",
33
+ @reportable.user_moderation,
34
+ @current_user,
35
+ extra: {
36
+ reportable_type: @reportable.class.name,
37
+ username: @reportable.name,
38
+ user_id: @reportable.id
39
+ }
40
+ ) do
41
+ @reportable.user_moderation.destroy!
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -10,6 +10,9 @@ module Decidim
10
10
  # organization - The Organization that will be updated.
11
11
  # form - A form object with the params.
12
12
  def initialize(organization, form)
13
+ image_fields.each do |field|
14
+ form.send("#{field}=".to_sym, organization.send(field)) if form.send(field).blank?
15
+ end
13
16
  @organization = organization
14
17
  @form = form
15
18
  end
@@ -27,14 +30,19 @@ module Decidim
27
30
  update_organization
28
31
  broadcast(:ok, organization)
29
32
  rescue ActiveRecord::RecordInvalid
30
- form.errors.add(:official_img_header, organization.errors[:official_img_header]) if organization.errors.include? :official_img_header
31
- form.errors.add(:official_img_footer, organization.errors[:official_img_footer]) if organization.errors.include? :official_img_footer
33
+ image_fields.each do |field|
34
+ form.errors.add(field, organization.errors[field]) if organization.errors.include? field
35
+ end
32
36
  broadcast(:invalid)
33
37
  end
34
38
  end
35
39
 
36
40
  private
37
41
 
42
+ def image_fields
43
+ [:highlighted_content_banner_image, :logo, :favicon, :official_img_header, :official_img_footer]
44
+ end
45
+
38
46
  attr_reader :form, :organization
39
47
 
40
48
  def update_organization
@@ -50,6 +58,7 @@ module Decidim
50
58
  .merge(highlighted_content_banner_attributes)
51
59
  .merge(omnipresent_banner_attributes)
52
60
  .merge(colors_attributes)
61
+ .delete_if { |_k, val| val.is_a?(Decidim::ApplicationUploader) }
53
62
  .tap do |attributes|
54
63
  attributes[:header_snippets] = form.header_snippets if Decidim.enable_html_header_snippets
55
64
  end
@@ -68,8 +77,7 @@ module Decidim
68
77
  remove_official_img_header: form.remove_official_img_header,
69
78
  official_img_footer: form.official_img_footer,
70
79
  remove_official_img_footer: form.remove_official_img_footer,
71
- official_url: form.official_url,
72
- show_statistics: form.show_statistics
80
+ official_url: form.official_url
73
81
  }
74
82
  end
75
83
 
@@ -46,7 +46,8 @@ module Decidim
46
46
  show_in_footer: form.show_in_footer,
47
47
  weight: form.weight,
48
48
  topic: form.topic,
49
- content: form.content
49
+ content: form.content,
50
+ allow_public_access: form.allow_public_access
50
51
  }
51
52
  end
52
53
 
@@ -8,7 +8,7 @@ module Decidim
8
8
  #
9
9
  # user_group - The user_group to verify
10
10
  # current_user - the user performing the action
11
- def initialize(user_group, current_user, via_csv = false)
11
+ def initialize(user_group, current_user, via_csv: false)
12
12
  @user_group = user_group
13
13
  @current_user = current_user
14
14
  @via_csv = via_csv
@@ -49,7 +49,7 @@ module Decidim
49
49
  end
50
50
 
51
51
  def allowed_query_params
52
- [*extra_allowed_params, q: {}]
52
+ [*extra_allowed_params, { q: {} }]
53
53
  end
54
54
 
55
55
  # Non ransack params (outside :q) to be allowed in the query links.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Admin
7
+ module GlobalModerationContext
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ # Private: Overwrites the method from the parent controller so that the
12
+ # permission system does not overwrite permissions.
13
+ def permission_resource
14
+ :global_moderation
15
+ end
16
+
17
+ # Private: Finds the participatory spaces the current user is admin to.
18
+ # This is only used for users that are "participatoy space admins", not
19
+ # organization-wide admins. This method will later be used to find out
20
+ # what moderations can the current user manage.
21
+ #
22
+ # Returns an Array.
23
+ def spaces_user_is_admin_to
24
+ @spaces_user_is_admin_to ||=
25
+ Decidim.participatory_space_manifests.flat_map do |manifest|
26
+ Decidim
27
+ .find_participatory_space_manifest(manifest.name)
28
+ .participatory_spaces
29
+ .call(current_organization)&.select do |space|
30
+ space.moderators.exists?(id: current_user.id)
31
+ end
32
+ end
33
+ end
34
+
35
+ # Private: finds the moderations the current user can manage, taking into
36
+ # account whether the user is an organization-wide admin or a
37
+ # "participatory space admin".
38
+ #
39
+ # Returns an `ActiveRecord::Relation`
40
+ def moderations_for_user
41
+ @moderations_for_user ||=
42
+ if current_user.admin?
43
+ Decidim::Moderation.all
44
+ else
45
+ Decidim::Moderation.where(participatory_space: spaces_user_is_admin_to)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module LandingPage
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ helper_method :active_blocks, :active_content_blocks_title, :inactive_blocks,
9
+ :inactive_content_blocks_title, :resource_content_block_cell,
10
+ :resource_landing_page_content_block_path, :resource_sort_url,
11
+ :scoped_resource
12
+ def edit
13
+ enforce_permission_to_update_resource
14
+
15
+ render "decidim/admin/shared/landing_page/edit"
16
+ end
17
+
18
+ def update
19
+ enforce_permission_to_update_resource
20
+
21
+ Decidim::Admin::ReorderContentBlocks.call(current_organization, content_block_scope, params[:manifests], scoped_resource.id) do
22
+ on(:ok) do
23
+ head :ok
24
+ end
25
+ on(:invalid) do
26
+ head :bad_request
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ # Method to be implemented at the controller. You need to
34
+ # return a symbol that defines the content block scope.
35
+ # Examples of scopes could be `:homepage` or `:landing_page`.
36
+ def content_block_scope
37
+ raise "#{self.class.name} is expected to implement #content_block_scope"
38
+ end
39
+
40
+ # Method to be implemented at the controller. Defines the permissions for
41
+ # edit and update actions.
42
+ # For example `enforce_permission_to :manage_landing_page, :voting, voting: current_space`.
43
+ def enforce_permission_to_update_resource
44
+ raise "#{self.class.name} is expected to implement #enforce_permission_to_update_resource"
45
+ end
46
+
47
+ # Method to be implemented at the controller. Returns the URL
48
+ # where the ordered/activated content_blocks is submitted to.
49
+ def resource_sort_url
50
+ raise "#{self.class.name} is expected to implement #resource_sort_url"
51
+ end
52
+
53
+ # Method to be implemented at the controller. Returns a string
54
+ # with the header text for the active content_block column.
55
+ #
56
+ # Example: `t("landing_page.edit.active_content_blocks", scope: "decidim.votings.admin")`
57
+ def active_content_blocks_title
58
+ raise "#{self.class.name} is expected to implement #active_content_blocks_title"
59
+ end
60
+
61
+ # Method to be implemented at the controller. Returns a string
62
+ # with the header text for the inactive content_block column.
63
+ #
64
+ # Example: `t("landing_page.edit.inactive_content_blocks", scope: "decidim.votings.admin")`
65
+ def inactive_content_blocks_title
66
+ raise "#{self.class.name} is expected to implement #inactive_content_blocks_title"
67
+ end
68
+
69
+ # Method to be implemented at the controller. Returns a string
70
+ # with the cell name to be used for the drag'n'drop for each content_block.
71
+ #
72
+ # Example: "decidim/votings/content_block"
73
+ def resource_content_block_cell
74
+ raise "#{self.class.name} is expected to implement #resource_content_block_cell"
75
+ end
76
+
77
+ # Shared methods
78
+ def content_blocks
79
+ @content_blocks ||= Decidim::ContentBlock.for_scope(
80
+ content_block_scope,
81
+ organization: current_organization
82
+ ).where(scoped_resource_id: scoped_resource.id)
83
+ end
84
+
85
+ def active_blocks
86
+ @active_blocks ||= content_blocks.published
87
+ end
88
+
89
+ def inactive_blocks
90
+ @inactive_blocks ||= content_blocks.unpublished + unused_manifests
91
+ end
92
+
93
+ def used_manifests
94
+ @used_manifests ||= content_blocks.map(&:manifest_name)
95
+ end
96
+
97
+ def unused_manifests
98
+ @unused_manifests ||= Decidim.content_blocks.for(content_block_scope).reject do |manifest|
99
+ used_manifests.include?(manifest.name.to_s)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module LandingPageContentBlocks
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ helper_method :content_block, :resource_landing_page_content_block_path,
9
+ :scoped_resource, :submit_button_text
10
+
11
+ def edit
12
+ enforce_permission_to_update_resource
13
+ @form = form(Decidim::Admin::ContentBlockForm).from_model(content_block)
14
+
15
+ render "decidim/admin/shared/landing_page_content_blocks/edit"
16
+ end
17
+
18
+ def update
19
+ enforce_permission_to_update_resource
20
+ @form = form(Decidim::Admin::ContentBlockForm).from_params(params)
21
+
22
+ Decidim::Admin::UpdateContentBlock.call(@form, content_block, content_block_scope) do
23
+ on(:ok) do
24
+ redirect_to edit_resource_landing_page_path
25
+ end
26
+ on(:invalid) do
27
+ render "decidim/admin/shared/landing_page_content_blocks/edit"
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ # Method to be implemented at the controller. You need to
35
+ # return a symbol that defines the content block scope.
36
+ # Examples of scopes could be `:homepage` or `:voting_landing_page`.
37
+ def content_block_scope
38
+ raise "#{self.class.name} is expected to implement #content_block_scope"
39
+ end
40
+
41
+ # Method to be implemented at the controller. You need to
42
+ # return an Object to filter the content blocks for the given resource.
43
+ #
44
+ # For example a `Voting` record.
45
+ def scoped_resource
46
+ raise "#{self.class.name} is expected to implement #scoped_resource"
47
+ end
48
+
49
+ # Method to be implemented at the controller. Defines the permissions for
50
+ # edit and update actions.
51
+ #
52
+ # Example: `enforce_permission_to :manage_landing_page, :voting, voting: current_space`.
53
+ def enforce_permission_to_update_resource
54
+ raise "#{self.class.name} is expected to implement #enforce_permission_to_update_resource"
55
+ end
56
+
57
+ # Method to be implemented at the controller. Returns the URL
58
+ # to the edit landing page path.
59
+ #
60
+ # Example: `edit_voting_landing_page_path(scoped_resource)`
61
+ def edit_resource_landing_page_path
62
+ raise "#{self.class.name} is expected to implement #edit_resource_landing_page_path"
63
+ end
64
+
65
+ # Method to be implemented at the controller. Returns the URL
66
+ # where the ContentBlockForm is submitted.
67
+ #
68
+ # Example: `voting_landing_page_content_block_path(scoped_resource, params[:id])`
69
+ def resource_landing_page_content_block_path
70
+ raise "#{self.class.name} is expected to implement #resource_landing_page_content_block_path"
71
+ end
72
+
73
+ # Method to be implemented at the controller. Returns a string
74
+ # with the text for the submit button of the ContentBlockForm.
75
+ #
76
+ # Example: t("landing_page.content_blocks.edit.update", scope: "decidim.votings.admin")
77
+ def submit_button_text
78
+ raise "#{self.class.name} is expected to implement #submit_button_text"
79
+ end
80
+
81
+ # Shared methods
82
+ def content_block
83
+ @content_block ||= content_blocks.find_by(manifest_name: params[:id]) || content_block_from_manifest
84
+ end
85
+
86
+ def content_block_manifest
87
+ @content_block_manifest = unused_content_block_manifests.find { |manifest| manifest.name.to_s == params[:id] }
88
+ end
89
+
90
+ def content_blocks
91
+ @content_blocks ||= Decidim::ContentBlock.for_scope(
92
+ content_block_scope,
93
+ organization: current_organization
94
+ ).where(scoped_resource_id: scoped_resource.id)
95
+ end
96
+
97
+ def used_content_block_manifests
98
+ @used_content_block_manifests ||= content_blocks.map(&:manifest_name)
99
+ end
100
+
101
+ def unused_content_block_manifests
102
+ @unused_content_block_manifests ||= Decidim.content_blocks.for(content_block_scope).reject do |manifest|
103
+ used_content_block_manifests.include?(manifest.name.to_s)
104
+ end
105
+ end
106
+
107
+ def content_block_from_manifest
108
+ Decidim::ContentBlock.create!(
109
+ organization: current_organization,
110
+ scope_name: content_block_scope,
111
+ scoped_resource_id: scoped_resource.id,
112
+ manifest_name: params[:id]
113
+ )
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Moderations
7
+ module Admin
8
+ module Filterable
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ include Decidim::Admin::Filterable
13
+
14
+ private
15
+
16
+ def base_query
17
+ collection
18
+ end
19
+
20
+ def filters
21
+ [
22
+ :reportable_type_string_eq
23
+ ]
24
+ end
25
+
26
+ def filters_with_values
27
+ {
28
+ reportable_type_string_eq: reportable_types
29
+ }
30
+ end
31
+
32
+ def dynamically_translated_filters
33
+ [:reportable_type_string_eq]
34
+ end
35
+
36
+ def translated_reportable_type_string_eq(value)
37
+ value.constantize.name.demodulize
38
+ end
39
+
40
+ # Private: the predicate used by `Ransack` to perform a search. We used `reported` instead
41
+ # of `reportable` because otherwise `Ransack` try to traverse the polymorphic
42
+ # association automatically and it fails.
43
+ def search_field_predicate
44
+ :reported_id_string_or_reported_content_cont
45
+ end
46
+
47
+ def reportable_types
48
+ collection.pluck(:decidim_reportable_type).uniq.sort
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class BlockUserController < Decidim::Admin::ApplicationController
6
+ layout "decidim/admin/users"
7
+
8
+ helper_method :user
9
+
10
+ def new
11
+ enforce_permission_to :block, :admin_user
12
+
13
+ @form = form(BlockUserForm).from_model(user)
14
+ end
15
+
16
+ def create
17
+ enforce_permission_to :block, :admin_user
18
+
19
+ @form = form(BlockUserForm).from_params(params)
20
+
21
+ BlockUser.call(@form) do
22
+ on(:ok) do
23
+ flash[:notice] = I18n.t("officializations.block.success", scope: "decidim.admin")
24
+ redirect_to officializations_path(q: { name_or_nickname_or_email_cont: user.name }), notice: notice
25
+ end
26
+
27
+ on(:invalid) do
28
+ flash[:alert] = I18n.t("officializations.block.error", scope: "decidim.admin")
29
+ render :new
30
+ end
31
+ end
32
+ end
33
+
34
+ def destroy
35
+ enforce_permission_to :block, :admin_user
36
+
37
+ UnblockUser.call(user, current_user) do
38
+ on(:ok) do
39
+ flash[:notice] = I18n.t("officializations.unblock.success", scope: "decidim.admin")
40
+ end
41
+
42
+ on(:invalid) do
43
+ flash[:alert] = I18n.t("officializations.unblock.error", scope: "decidim.admin")
44
+ end
45
+ end
46
+
47
+ redirect_to officializations_path(q: { name_or_nickname_or_email_cont: user.name }), notice: notice
48
+ end
49
+
50
+ private
51
+
52
+ def user
53
+ @user ||= Decidim::User.find_by(
54
+ id: params[:user_id],
55
+ organization: current_organization
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
@@ -14,6 +14,7 @@ module Decidim
14
14
 
15
15
  helper Decidim::ResourceHelper
16
16
  helper Decidim::Admin::ExportsHelper
17
+ helper Decidim::Admin::ImportsHelper
17
18
  helper Decidim::Admin::BulkActionsHelper
18
19
  helper Decidim::Admin::ResourcePermissionsHelper
19
20
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class ConflictsController < Decidim::Admin::ApplicationController
6
+ layout "decidim/admin/users"
7
+
8
+ def index
9
+ @conflicts = Decidim::Verifications::Conflict.all
10
+ end
11
+
12
+ def edit
13
+ conflict = Decidim::Verifications::Conflict.find(params[:id])
14
+
15
+ @form = form(TransferUserForm).from_params(
16
+ user: conflict.current_user,
17
+ managed_user: conflict.managed_user,
18
+ conflict: conflict
19
+ )
20
+ end
21
+
22
+ def update
23
+ conflict = Decidim::Verifications::Conflict.find(params[:id])
24
+
25
+ @form = form(TransferUserForm).from_params(
26
+ current_user: current_user,
27
+ conflict: conflict,
28
+ reason: params[:transfer_user][:reason],
29
+ email: params[:transfer_user][:email]
30
+ )
31
+
32
+ TransferUser.call(@form) do
33
+ on(:ok) do
34
+ flash[:notice] = I18n.t("success", scope: "decidim.admin.conflicts.transfer")
35
+ redirect_to conflicts_path
36
+ end
37
+
38
+ on(:invalid) do
39
+ flash.now[:alert] = I18n.t("error", scope: "decidim.admin.conflicts.transfer")
40
+ redirect_to decidim.root_path
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -9,8 +9,7 @@ module Decidim
9
9
  def create
10
10
  enforce_permission_to :export, :component_data, component: component
11
11
  name = params[:id]
12
-
13
- ExportJob.perform_later(current_user, component, name, params[:format] || default_format)
12
+ ExportJob.perform_later(current_user, component, name, params[:format] || default_format, params[:resource_id].presence)
14
13
 
15
14
  flash[:notice] = t("decidim.admin.exports.notice")
16
15
 
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module GlobalModerations
6
+ # This controller allows admins to manage reports in a moderation.
7
+ class ReportsController < Decidim::Admin::Moderations::ReportsController
8
+ layout "decidim/admin/global_moderations"
9
+
10
+ include Decidim::Admin::GlobalModerationContext
11
+
12
+ def moderation
13
+ @moderation ||= moderations_for_user.find(params[:moderation_id])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This controller allows admin users to manage all moderations from the
6
+ # participatory spaces they have access to.
7
+ class GlobalModerationsController < Decidim::Admin::ModerationsController
8
+ layout "decidim/admin/global_moderations"
9
+
10
+ include Decidim::Admin::GlobalModerationContext
11
+
12
+ # Private: This method is used by the `Filterable` concern as the base query
13
+ # without applying filtering and/or sorting options.
14
+ def collection
15
+ @collection ||=
16
+ if params[:hidden]
17
+ moderations_for_user.where.not(hidden_at: nil)
18
+ else
19
+ moderations_for_user.where(hidden_at: nil)
20
+ end
21
+ end
22
+
23
+ # Private: fins the reportable of the specific moderation the user is
24
+ # trying to manage.
25
+ #
26
+ # Returns a resource implementing the `Decidim::Reportable` concern.
27
+ def reportable
28
+ @reportable ||= moderations_for_user.find(params[:id]).reportable
29
+ end
30
+ end
31
+ end
32
+ end
@@ -97,7 +97,7 @@ module Decidim
97
97
  managed: true,
98
98
  name: params.dig(:impersonate_user, :name)
99
99
  ) do |u|
100
- u.nickname = UserBaseEntity.nicknamize(u.name, organization: current_organization)
100
+ u.nickname = Decidim::UserBaseEntity.nicknamize(u.name, organization: current_organization)
101
101
  u.admin = false
102
102
  u.tos_agreement = true
103
103
  end