decidim-admin 0.32.1 → 0.32.3

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/admin/results_per_page_cell.rb +1 -1
  3. data/app/commands/decidim/admin/block_user.rb +1 -1
  4. data/app/commands/decidim/admin/bulk_block_users.rb +1 -1
  5. data/app/commands/decidim/admin/close_session_managed_user.rb +1 -1
  6. data/app/commands/decidim/admin/participatory_space/create_admin.rb +1 -1
  7. data/app/commands/decidim/admin/participatory_space/create_member.rb +2 -2
  8. data/app/commands/decidim/admin/promote_managed_user.rb +1 -1
  9. data/app/commands/decidim/admin/reorder_taxonomies.rb +2 -2
  10. data/app/commands/decidim/admin/update_help_sections.rb +2 -2
  11. data/app/controllers/concerns/decidim/admin/content_blocks/landing_page.rb +5 -5
  12. data/app/controllers/concerns/decidim/admin/filterable.rb +2 -0
  13. data/app/controllers/concerns/decidim/admin/global_moderation_context.rb +2 -0
  14. data/app/controllers/concerns/decidim/admin/participatory_space_admin_context.rb +2 -0
  15. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +2 -0
  16. data/app/controllers/decidim/admin/admin_terms_controller.rb +1 -0
  17. data/app/controllers/decidim/admin/application_controller.rb +4 -0
  18. data/app/controllers/decidim/admin/block_user_controller.rb +2 -0
  19. data/app/controllers/decidim/admin/components/base_controller.rb +2 -0
  20. data/app/controllers/decidim/admin/components_controller.rb +3 -2
  21. data/app/controllers/decidim/admin/concerns/has_attachment_collections.rb +2 -0
  22. data/app/controllers/decidim/admin/concerns/has_attachments.rb +2 -0
  23. data/app/controllers/decidim/admin/concerns/has_breadcrumb_items.rb +4 -0
  24. data/app/controllers/decidim/admin/conflicts_controller.rb +5 -5
  25. data/app/controllers/decidim/admin/global_moderations/reports_controller.rb +2 -0
  26. data/app/controllers/decidim/admin/global_moderations_controller.rb +2 -0
  27. data/app/controllers/decidim/admin/help_sections_controller.rb +3 -3
  28. data/app/controllers/decidim/admin/impersonations_controller.rb +2 -1
  29. data/app/controllers/decidim/admin/managed_users/impersonation_logs_controller.rb +1 -1
  30. data/app/controllers/decidim/admin/moderated_users_controller.rb +3 -0
  31. data/app/controllers/decidim/admin/moderations_controller.rb +4 -0
  32. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +4 -1
  33. data/app/controllers/decidim/admin/newsletters_controller.rb +3 -0
  34. data/app/controllers/decidim/admin/organization_homepage_controller.rb +7 -3
  35. data/app/controllers/decidim/admin/participatory_space/concerns/has_members.rb +4 -0
  36. data/app/controllers/decidim/admin/participatory_space/concerns/has_members_csv_import.rb +4 -0
  37. data/app/controllers/decidim/admin/resource_permissions_controller.rb +4 -0
  38. data/app/controllers/decidim/admin/static_pages_controller.rb +27 -25
  39. data/app/controllers/decidim/admin/taxonomy_filters_controller.rb +2 -2
  40. data/app/controllers/decidim/admin/taxonomy_filters_selector_controller.rb +1 -1
  41. data/app/controllers/decidim/admin/taxonomy_items_controller.rb +5 -2
  42. data/app/helpers/decidim/admin/search_form_helper.rb +2 -2
  43. data/app/jobs/decidim/admin/newsletter_job.rb +0 -1
  44. data/app/packs/entrypoints/decidim_admin.js +0 -1
  45. data/app/packs/src/decidim/admin/officializations.js +11 -2
  46. data/app/packs/stylesheets/decidim/admin/_proposal_status.scss +28 -0
  47. data/app/packs/stylesheets/decidim/admin/_select_picker.scss +1 -1
  48. data/app/packs/stylesheets/decidim/admin/_sidebar-menu.scss +3 -1
  49. data/app/permissions/decidim/admin/permissions.rb +16 -0
  50. data/app/views/decidim/admin/organization/form/_extra_features.html.erb +18 -2
  51. data/app/views/layouts/decidim/admin/_js_configuration.html.erb +1 -0
  52. data/config/locales/bg.yml +2 -0
  53. data/config/locales/ca-IT.yml +4 -0
  54. data/config/locales/ca.yml +7 -3
  55. data/config/locales/cs.yml +5 -0
  56. data/config/locales/de.yml +37 -1
  57. data/config/locales/en.yml +4 -0
  58. data/config/locales/es-MX.yml +4 -0
  59. data/config/locales/es-PY.yml +4 -0
  60. data/config/locales/es.yml +4 -0
  61. data/config/locales/eu.yml +55 -51
  62. data/config/locales/fi-plain.yml +4 -0
  63. data/config/locales/fi.yml +4 -0
  64. data/config/locales/fr-CA.yml +4 -0
  65. data/config/locales/fr.yml +4 -0
  66. data/config/locales/gl.yml +691 -48
  67. data/config/locales/ja.yml +4 -0
  68. data/config/locales/sk.yml +16 -0
  69. data/config/locales/sv.yml +72 -2
  70. data/config/routes.rb +0 -1
  71. data/decidim-admin.gemspec +1 -1
  72. data/lib/decidim/admin/import/readers.rb +5 -2
  73. data/lib/decidim/admin/menu.rb +0 -1
  74. data/lib/decidim/admin/version.rb +1 -1
  75. metadata +7 -9
  76. data/app/controllers/decidim/admin/organization_appearance_controller.rb +0 -34
  77. data/app/packs/src/decidim/admin/tab_focus.js +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a90920d105b666ce847ed0d99808d90d024a223c0a93f1bf19830faadb54aae
4
- data.tar.gz: df11befe78e45801e6dd398383cb66b8b50f80a90a54dcf169910f21b8efea09
3
+ metadata.gz: df67bc80dec1db89cad13df7a602640a4736b88f71f2665ba2c95ec20f4aa7dc
4
+ data.tar.gz: bec7f7c5099b309760b5d513e2cce94779a0406490dccd9088a0f9fe876acec1
5
5
  SHA512:
6
- metadata.gz: 571e1c659b6bf02c4d3b7587eca36cfb92597210bcc0267a7e2f917f2e57370fa418ec937fd9be16900d26b81b68067dc3d88eeff950d0b89e294f2435c3b82a
7
- data.tar.gz: d442beed22e818bb00757c92359a9cc582cc21257c2b5927167af3e4cabb9f5ff64049f04accc12047e2809e2d323ec06fd788cf23a1044c1609b081dbc87394
6
+ metadata.gz: 82db9865de6bee8c2a79c5092695ed0f2f2d0388a48e26b8a8339fc435a904910f6c57ddcf207ee9d4ace2360b260f4e1658317bb59cc472f6b787ddc3546fc9
7
+ data.tar.gz: 8179e898ee956b8426a8e82c5a2957eb5779886a341e7a19e7754a11e4ce49ee8a4f07d606ee1286b4e99ce032a3d8041e2b6d41241d74a058dc57ed0a967d05
@@ -5,7 +5,7 @@ module Decidim
5
5
  class ResultsPerPageCell < Decidim::ViewModel
6
6
  property :per_page, :per_page_range
7
7
  def path_for_num_per_page(num_per_page = per_page_range.first)
8
- controller.url_for(params.to_unsafe_h.merge(per_page: num_per_page))
8
+ controller.url_for(decidim_url_params(params, per_page: num_per_page))
9
9
  end
10
10
  end
11
11
  end
@@ -45,7 +45,7 @@ module Decidim
45
45
  end
46
46
 
47
47
  def find_or_create_moderation!
48
- Decidim::UserModeration.find_or_create_by!(user: form.user)
48
+ Decidim::UserModeration.find_or_create_by!(user: form.user) # rubocop:disable Decidim/OrganizationScopedFinder -- form.user is scoped to the current organization
49
49
  end
50
50
 
51
51
  def register_justification!
@@ -49,7 +49,7 @@ module Decidim
49
49
  def block_all_users!
50
50
  form.users.each do |user|
51
51
  transaction do
52
- Decidim::UserModeration.find_or_create_by!(user:)
52
+ Decidim::UserModeration.find_or_create_by!(user:) # rubocop:disable Decidim/OrganizationScopedFinder -- form.users is scoped to the current organization
53
53
 
54
54
  @current_blocking = UserBlock.create!(
55
55
  justification: form.justification,
@@ -32,7 +32,7 @@ module Decidim
32
32
  private
33
33
 
34
34
  def impersonation_log
35
- @impersonation_log ||= Decidim::ImpersonationLog.where(admin: current_user, user:).active.first
35
+ @impersonation_log ||= Decidim::ImpersonationLog.where(admin: current_user, user:).active.first # rubocop:disable Decidim/OrganizationScopedFinder -- admin and user are the current session users
36
36
  end
37
37
 
38
38
  def close_session
@@ -120,7 +120,7 @@ module Decidim
120
120
  def existing_user
121
121
  return @existing_user if defined?(@existing_user)
122
122
 
123
- @existing_user = User.find_by(email: form.email, organization: participatory_space.organization)
123
+ @existing_user = User.find_by(email: form.email, organization: participatory_space.organization) # rubocop:disable Decidim/OrganizationScopedFinder -- organization is the participatory space's organization
124
124
 
125
125
  InviteUserAgain.call(@existing_user, invitation_instructions) if @existing_user&.invitation_pending?
126
126
 
@@ -53,7 +53,7 @@ module Decidim
53
53
  title: user.name
54
54
  }
55
55
  ) do
56
- member = Decidim::ParticipatorySpace::Member.where(user:, participatory_space: @member_to).first_or_initialize
56
+ member = Decidim::ParticipatorySpace::Member.where(user:, participatory_space: @member_to).first_or_initialize # rubocop:disable Decidim/OrganizationScopedFinder -- user and participatory_space are scoped to the current invitation
57
57
  member.role = form.role
58
58
  member.published = form.published
59
59
  member.save!
@@ -62,7 +62,7 @@ module Decidim
62
62
  end
63
63
 
64
64
  def existing_user
65
- @existing_user ||= User.find_by(
65
+ @existing_user ||= User.find_by( # rubocop:disable Decidim/OrganizationScopedFinder -- organization is the member's participatory space organization
66
66
  email: form.email.downcase,
67
67
  organization: member_to.organization
68
68
  )
@@ -49,7 +49,7 @@ module Decidim
49
49
  end
50
50
 
51
51
  def email_already_exists?
52
- Decidim::User.where(email: form.email.downcase).any?
52
+ form.current_organization.users.where(email: form.email.downcase).any?
53
53
  end
54
54
 
55
55
  def create_action_log
@@ -65,11 +65,11 @@ module Decidim
65
65
  end
66
66
 
67
67
  def collection
68
- @collection ||= Decidim::Taxonomy.where(organization:, parent_id: first_item.parent_id)
68
+ @collection ||= organization.taxonomies.where(parent_id: first_item.parent_id)
69
69
  end
70
70
 
71
71
  def first_item
72
- @first_item ||= Decidim::Taxonomy.where(organization:).find(order.first)
72
+ @first_item ||= organization.taxonomies.find(order.first)
73
73
  end
74
74
  end
75
75
  end
@@ -21,7 +21,7 @@ module Decidim
21
21
 
22
22
  Decidim.traceability.perform_action!("update", ContextualHelpSection, current_user, { "resource" => { "title" => section.id.humanize } }) do
23
23
  ContextualHelpSection.set_content(@organization, section.id, section.content)
24
- ContextualHelpSection.find_by(organization: @organization, section_id: section.id)
24
+ ContextualHelpSection.find_by(organization: @organization, section_id: section.id) # rubocop:disable Decidim/OrganizationScopedFinder -- scoped to the given organization and section
25
25
  end
26
26
  end
27
27
  end
@@ -34,7 +34,7 @@ module Decidim
34
34
  attr_reader :form
35
35
 
36
36
  def content_has_changed?(section)
37
- return if ContextualHelpSection.find_by(organization: @organization, section_id: section.id).nil? && section.content.compact_blank.blank?
37
+ return if ContextualHelpSection.find_by(organization: @organization, section_id: section.id).nil? && section.content.compact_blank.blank? # rubocop:disable Decidim/OrganizationScopedFinder -- scoped to the given organization and section
38
38
 
39
39
  section.content != ContextualHelpSection.find_content(@organization, section.id).except("machine_translations")
40
40
  end
@@ -10,7 +10,7 @@ module Decidim
10
10
  helper_method :active_blocks, :active_content_blocks_title, :add_content_block_text, :available_manifests,
11
11
  :content_block_destroy_confirmation_text, :content_blocks_title, :inactive_blocks,
12
12
  :inactive_content_blocks_title, :resource_content_block_cell, :resource_create_url,
13
- :resource_sort_url
13
+ :resource_sort_url, :scoped_resource
14
14
  def edit
15
15
  enforce_permission_to_update_resource
16
16
 
@@ -30,10 +30,6 @@ module Decidim
30
30
  end
31
31
  end
32
32
 
33
- # Method that specifies the i18n scope for this controller. This can be overwritten in your controller.
34
- # so that you can pass a different scope to the i18n methods.
35
- def i18n_scope = "decidim.admin.content_blocks"
36
-
37
33
  # Method to be implemented at the controller. Returns a string
38
34
  # with the text for the title of content blocks
39
35
  #
@@ -71,6 +67,10 @@ module Decidim
71
67
 
72
68
  private
73
69
 
70
+ # Method that specifies the i18n scope for this controller. This can be overwritten in your controller.
71
+ # so that you can pass a different scope to the i18n methods.
72
+ def i18n_scope = "decidim.admin.content_blocks"
73
+
74
74
  # Method to be implemented at the controller. You need to
75
75
  # return a symbol that defines the content block scope.
76
76
  # Examples of scopes could be `:homepage` or `:landing_page`.
@@ -195,7 +195,9 @@ module Decidim
195
195
 
196
196
  # A tree of Taxonomy IDs. Leaves are `nil`.
197
197
  def taxonomy_ids_hash(taxonomies)
198
+ # rubocop:disable Decidim/OrganizationScopedFinder -- taxonomies is scoped to current_organization through available_root_taxonomies
198
199
  filtered_taxonomies = taxonomies.roots.or(taxonomies.where(id: available_taxonomy_ids))
200
+ # rubocop:enable Decidim/OrganizationScopedFinder
199
201
  return nil if filtered_taxonomies.blank?
200
202
 
201
203
  filtered_taxonomies.to_h do |taxonomy|
@@ -8,6 +8,8 @@ module Decidim
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
+ protected
12
+
11
13
  # Private: Overwrites the method from the parent controller so that the
12
14
  # permission system does not overwrite permissions.
13
15
  def authorization_scope
@@ -8,6 +8,8 @@ module Decidim
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  class_methods do
11
+ protected
12
+
11
13
  # Public: Called on a controller, it sets up all the surrounding methods to render a
12
14
  # participatory space's admin template. It expects the method `current_participatory_space`
13
15
  # to be defined, from which it will extract the participatory manifest.
@@ -22,6 +22,8 @@ module Decidim
22
22
 
23
23
  # Public: To be implemented at the controller. You need to
24
24
  # return the space that will be exported.
25
+ protected
26
+
25
27
  def exportable_space
26
28
  raise NotImplementedError
27
29
  end
@@ -6,6 +6,7 @@ module Decidim
6
6
  # Terms of service agreement.
7
7
  class AdminTermsController < Decidim::Admin::ApplicationController
8
8
  def accept
9
+ enforce_permission_to :accept, :admin_terms
9
10
  current_user.admin_terms_accepted_at = Time.current
10
11
  if current_user.save!
11
12
  flash[:notice] = t("accept.success", scope: "decidim.admin.admin_terms_of_service")
@@ -19,6 +19,7 @@ module Decidim
19
19
  include DisableRedirectionToExternalHost
20
20
  include Decidim::Admin::Concerns::HasBreadcrumbItems
21
21
  include ActiveStorage::SetCurrent
22
+ include Decidim::UrlHelper
22
23
 
23
24
  helper Decidim::Admin::ApplicationHelper
24
25
  helper Decidim::Admin::AttributesDisplayHelper
@@ -34,6 +35,7 @@ module Decidim
34
35
  helper Decidim::ComponentPathHelper
35
36
  helper Decidim::SanitizeHelper
36
37
  helper Decidim::BreadcrumbHelper
38
+ helper Decidim::UrlHelper
37
39
 
38
40
  helper Decidim::Templates::Admin::ApplicationHelper if Decidim.module_installed?(:templates) && defined?(Decidim::Templates::Admin::ApplicationHelper)
39
41
 
@@ -44,6 +46,8 @@ module Decidim
44
46
  register_permissions(::Decidim::Admin::ApplicationController,
45
47
  ::Decidim::Admin::Permissions)
46
48
 
49
+ protected
50
+
47
51
  def user_has_no_permission_path
48
52
  decidim_admin.root_path
49
53
  end
@@ -57,6 +57,7 @@ module Decidim
57
57
  end
58
58
 
59
59
  def bulk_create
60
+ enforce_permission_to :block, :admin_user
60
61
  @form = form(BlockUsersForm).from_params(params)
61
62
 
62
63
  Admin::BulkBlockUsers.call(@form) do
@@ -73,6 +74,7 @@ module Decidim
73
74
  end
74
75
 
75
76
  def bulk_destroy
77
+ enforce_permission_to :block, :admin_user
76
78
  Admin::BulkUnblockUsers.call(blocked_users, current_user) do
77
79
  on(:ok) do
78
80
  flash[:notice] = I18n.t("officializations.bulk_action.unblock.success", scope: "decidim.admin")
@@ -72,6 +72,8 @@ module Decidim
72
72
  end
73
73
  end
74
74
 
75
+ protected
76
+
75
77
  def set_breadcrumb_items
76
78
  context_breadcrumb_items << {
77
79
  label: t("components", scope: "decidim.admin.menu"),
@@ -87,7 +87,7 @@ module Decidim
87
87
 
88
88
  Decidim::Commands::SoftDeleteResource.call(trashable_deleted_resource, current_user) do
89
89
  on(:ok) do
90
- Decidim::Reminder.where(component: resource).destroy_all
90
+ Decidim::Reminder.where(component: resource).destroy_all # rubocop:disable Decidim/OrganizationScopedFinder -- resource is the soft-deleted component, already scoped to current_participatory_space via query_scope
91
91
  flash[:notice] = I18n.t("soft_delete.success", scope: trashable_i18n_scope, resource_name: human_readable_resource_name.capitalize)
92
92
  redirect_to_resource_index
93
93
  end
@@ -136,7 +136,8 @@ module Decidim
136
136
  end
137
137
 
138
138
  def share
139
- @component = query_scope.find(params[:id])
139
+ enforce_permission_to :share, :component
140
+ @component = query_scope.find(params.expect(:id))
140
141
  share_token = @component.share_tokens.create!(user: current_user, organization: current_organization)
141
142
 
142
143
  redirect_to share_token.url
@@ -82,6 +82,8 @@ module Decidim
82
82
  redirect_to after_destroy_path
83
83
  end
84
84
 
85
+ protected
86
+
85
87
  # Public: Returns a String or Object that will be passed to `redirect_to` after
86
88
  # destroying an attachment collection. By default it redirects to the object
87
89
  # that holds the attachment collection.
@@ -82,6 +82,8 @@ module Decidim
82
82
  redirect_to after_destroy_path
83
83
  end
84
84
 
85
+ protected
86
+
85
87
  # Public: Returns a String or Object that will be passed to `redirect_to` after
86
88
  # destroying an attachment. By default it redirects to the attached_to.
87
89
  #
@@ -7,12 +7,16 @@ module Decidim
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  class_methods do
10
+ protected
11
+
10
12
  def add_breadcrumb_item_from_menu(target_menu, opts = {})
11
13
  before_action -> { secondary_breadcrumb_menus << target_menu }, opts
12
14
  end
13
15
  end
14
16
 
15
17
  included do
18
+ protected
19
+
16
20
  def secondary_breadcrumb_menus
17
21
  @secondary_breadcrumb_menus ||= []
18
22
  end
@@ -18,8 +18,6 @@ module Decidim
18
18
  def edit
19
19
  enforce_permission_to :index, :impersonatable_user
20
20
 
21
- conflict = Decidim::Verifications::Conflict.find(params[:id])
22
-
23
21
  @form = form(TransferUserForm).from_params(
24
22
  user: conflict.current_user,
25
23
  managed_user: conflict.managed_user,
@@ -30,8 +28,6 @@ module Decidim
30
28
  def update
31
29
  enforce_permission_to :index, :impersonatable_user
32
30
 
33
- conflict = Decidim::Verifications::Conflict.find(params[:id])
34
-
35
31
  @form = form(TransferUserForm).from_params(
36
32
  current_user:,
37
33
  conflict:,
@@ -54,6 +50,10 @@ module Decidim
54
50
 
55
51
  private
56
52
 
53
+ def conflict
54
+ @conflict ||= collection.find(params.expect(:id))
55
+ end
56
+
57
57
  def context_breadcrumb_items
58
58
  @context_breadcrumb_items ||= [impersonations_breadcrumb_item]
59
59
  end
@@ -67,7 +67,7 @@ module Decidim
67
67
 
68
68
  def collection
69
69
  @collection ||= Decidim::Verifications::Conflict.joins(:current_user).where(
70
- decidim_users: { decidim_organization_id: current_organization.id }
70
+ decidim_users: { organization: current_organization }
71
71
  )
72
72
  end
73
73
 
@@ -9,6 +9,8 @@ module Decidim
9
9
 
10
10
  include Decidim::Admin::GlobalModerationContext
11
11
 
12
+ protected
13
+
12
14
  def moderation
13
15
  @moderation ||= moderations_for_user.find(params[:moderation_id])
14
16
  end
@@ -9,6 +9,8 @@ module Decidim
9
9
 
10
10
  include Decidim::Admin::GlobalModerationContext
11
11
 
12
+ protected
13
+
12
14
  # Private: This method is used by the `Filterable` concern as the base query
13
15
  # without applying filtering and/or sorting options.
14
16
  def collection
@@ -12,17 +12,17 @@ module Decidim
12
12
 
13
13
  helper_method :sections
14
14
 
15
- before_action do
15
+ def show
16
16
  enforce_permission_to :update, :help_sections
17
- end
18
17
 
19
- def show
20
18
  @form = form(HelpSectionsForm).from_model(
21
19
  OpenStruct.new(sections:)
22
20
  )
23
21
  end
24
22
 
25
23
  def update
24
+ enforce_permission_to :update, :help_sections
25
+
26
26
  @form = form(HelpSectionsForm).from_params(
27
27
  params[:help_sections]
28
28
  )
@@ -52,6 +52,7 @@ module Decidim
52
52
  end
53
53
 
54
54
  def close_session
55
+ enforce_permission_to :close_session, :managed_user
55
56
  CloseSessionManagedUser.call(user, current_user) do
56
57
  on(:ok) do
57
58
  flash[:notice] = I18n.t("impersonations.close_session.success", scope: "decidim.admin")
@@ -82,7 +83,7 @@ module Decidim
82
83
  )
83
84
  return nil unless handler.unique_id
84
85
 
85
- existing_authorization = Authorization.find_by(
86
+ existing_authorization = Authorization.find_by( # rubocop:disable Decidim/OrganizationScopedFinder -- user: subquery scopes to current_organization
86
87
  user: User.where(organization: current_organization),
87
88
  name: handler_name,
88
89
  unique_id: handler.unique_id
@@ -11,7 +11,7 @@ module Decidim
11
11
  def index
12
12
  enforce_permission_to :index, :impersonatable_user
13
13
 
14
- @impersonation_logs = Decidim::ImpersonationLog.where(user:).order(started_at: :desc).page(params[:page]).per(15)
14
+ @impersonation_logs = user.impersonation_logs.order(started_at: :desc).page(params[:page]).per(15)
15
15
  end
16
16
 
17
17
  private
@@ -34,6 +34,7 @@ module Decidim
34
34
  end
35
35
 
36
36
  def bulk_unreport
37
+ enforce_permission_to :unreport, :moderate_users
37
38
  Admin::BulkUnreportUsers.call(current_user, reportables) do
38
39
  on(:ok) do
39
40
  flash[:notice] = I18n.t("reportable.bulk_action.ignore.success", scope: "decidim.moderations.admin")
@@ -67,6 +68,8 @@ module Decidim
67
68
  Decidim::Admin::ModerationStats.new(current_user).user_reports
68
69
  end
69
70
 
71
+ protected
72
+
70
73
  def collection
71
74
  @collection ||= if params[:blocked]
72
75
  base_query_finder.blocked
@@ -73,6 +73,8 @@ module Decidim
73
73
  end
74
74
 
75
75
  def bulk_action
76
+ enforce_permission_to :bulk_action, authorization_scope
77
+
76
78
  Admin::BulkAction.call(current_user, params[:bulk_action], selected_moderations) do
77
79
  on(:ok) do |ok, ko|
78
80
  flash[:notice] = I18n.t("reportable.bulk_action.#{params[:bulk_action]}.success", scope: "decidim.moderations.admin", count_ok: ok.count) if ok.count.positive?
@@ -92,6 +94,8 @@ module Decidim
92
94
  query_params[:q] || { s: "created_at desc" }
93
95
  end
94
96
 
97
+ protected
98
+
95
99
  # Private: This method is used by the `Filterable` concern as the base query
96
100
  # without applying filtering and/or sorting options.
97
101
  def collection
@@ -12,9 +12,12 @@ module Decidim
12
12
  enforce_permission_to :index, :newsletter
13
13
  end
14
14
 
15
- def show; end
15
+ def show
16
+ enforce_permission_to :index, :newsletter
17
+ end
16
18
 
17
19
  def preview
20
+ enforce_permission_to :index, :newsletter
18
21
  email = NewsletterMailer.newsletter(current_user, fake_newsletter, true)
19
22
  Premailer::Rails::Hook.perform(email)
20
23
  render html: email.html_part.body.decoded.html_safe
@@ -114,6 +114,7 @@ module Decidim
114
114
  end
115
115
 
116
116
  def recipients_count
117
+ enforce_permission_to :read, :newsletter, newsletter:
117
118
  @form = form(SelectiveNewsletterForm).from_params(newsletter_params)
118
119
  render plain: recipients_count_query
119
120
  end
@@ -183,6 +184,8 @@ module Decidim
183
184
  end
184
185
  end
185
186
 
187
+ protected
188
+
186
189
  def collection
187
190
  @collection ||= Newsletter.where(organization: current_organization)
188
191
  end
@@ -10,14 +10,18 @@ module Decidim
10
10
 
11
11
  add_breadcrumb_item_from_menu :admin_settings_menu
12
12
 
13
- def content_block_scope
14
- :homepage
15
- end
13
+ helper_method :scoped_resource
16
14
 
17
15
  def scoped_resource
18
16
  nil
19
17
  end
20
18
 
19
+ protected
20
+
21
+ def content_block_scope
22
+ :homepage
23
+ end
24
+
21
25
  def enforce_permission_to_update_resource
22
26
  enforce_permission_to :update, :organization, organization: current_organization
23
27
  end
@@ -107,6 +107,7 @@ module Decidim
107
107
  end
108
108
 
109
109
  def publish_all
110
+ enforce_permission_to :publish_all, :space_member
110
111
  PublishAllMembers.call(current_participatory_space, current_user) do
111
112
  on(:ok) do
112
113
  flash[:notice] = I18n.t("members.publish_all.success", scope: "decidim.admin")
@@ -121,6 +122,7 @@ module Decidim
121
122
  end
122
123
 
123
124
  def unpublish_all
125
+ enforce_permission_to :unpublish_all, :space_member
124
126
  UnpublishAllMembers.call(current_participatory_space, current_user) do
125
127
  on(:ok) do
126
128
  flash[:notice] = I18n.t("members.unpublish_all.success", scope: "decidim.admin")
@@ -134,6 +136,8 @@ module Decidim
134
136
  end
135
137
  end
136
138
 
139
+ protected
140
+
137
141
  # Public: Returns a String or Object that will be passed to `redirect_to` after
138
142
  # destroying a member. By default it redirects to the participatory_space.
139
143
  #
@@ -42,10 +42,14 @@ module Decidim
42
42
 
43
43
  def destroy_all
44
44
  enforce_permission_to :csv_import, :space_member
45
+ # rubocop:disable Decidim/OrganizationScopedFinder -- by_participatory_space scopes to the current participatory space
45
46
  Decidim::ParticipatorySpace::Member.by_participatory_space(participatory_space).delete_all
47
+ # rubocop:enable Decidim/OrganizationScopedFinder
46
48
  redirect_to new_members_csv_imports_path
47
49
  end
48
50
 
51
+ protected
52
+
49
53
  # Public: Returns a String or Object that will be passed to `redirect_to` after
50
54
  # importing members. By default it redirects to the participatory_space.
51
55
  #
@@ -10,12 +10,16 @@ module Decidim
10
10
  helper_method :authorizations, :other_authorizations_for, :resource_params, :resource
11
11
 
12
12
  def edit
13
+ enforce_permission_to :update, :resource_permission, resource:
14
+
13
15
  @permissions_form = PermissionsForm.new(
14
16
  permissions: permission_forms
15
17
  )
16
18
  end
17
19
 
18
20
  def update
21
+ enforce_permission_to :update, :resource_permission, resource:
22
+
19
23
  @permissions_form = PermissionsForm.from_params(params).with_context(current_organization:)
20
24
 
21
25
  UpdateResourcePermissions.call(@permissions_form, resource) do
@@ -11,34 +11,10 @@ module Decidim
11
11
 
12
12
  before_action :tos_version_formatted, only: [:index, :edit]
13
13
 
14
- helper_method :topics
14
+ helper_method :topics, :scoped_resource
15
15
 
16
16
  alias update_content_blocks update
17
17
 
18
- def content_block_scope
19
- :static_page
20
- end
21
-
22
- def scoped_resource
23
- @scoped_resource ||= collection.find_by(slug: params[:id])
24
- end
25
-
26
- def enforce_permission_to_update_resource
27
- enforce_permission_to :update, :static_page, static_page: scoped_resource
28
- end
29
-
30
- def resource_sort_url
31
- update_content_blocks_static_page_path(scoped_resource)
32
- end
33
-
34
- def resource_create_url(manifest_name)
35
- static_page_content_blocks_path(scoped_resource, manifest_name:)
36
- end
37
-
38
- def resource_content_block_cell
39
- "decidim/admin/static_page_content_block"
40
- end
41
-
42
18
  def index
43
19
  enforce_permission_to :read, :static_page
44
20
  @topics = Decidim::StaticPageTopic.where(organization: current_organization)
@@ -101,8 +77,32 @@ module Decidim
101
77
  end
102
78
  end
103
79
 
80
+ def scoped_resource
81
+ @scoped_resource ||= collection.find_by(slug: params[:id])
82
+ end
83
+
104
84
  private
105
85
 
86
+ def content_block_scope
87
+ :static_page
88
+ end
89
+
90
+ def enforce_permission_to_update_resource
91
+ enforce_permission_to :update, :static_page, static_page: scoped_resource
92
+ end
93
+
94
+ def resource_sort_url
95
+ update_content_blocks_static_page_path(scoped_resource)
96
+ end
97
+
98
+ def resource_create_url(manifest_name)
99
+ static_page_content_blocks_path(scoped_resource, manifest_name:)
100
+ end
101
+
102
+ def resource_content_block_cell
103
+ "decidim/admin/static_page_content_block"
104
+ end
105
+
106
106
  def tab_menu_name = :admin_static_pages_menu
107
107
 
108
108
  def form_params
@@ -121,6 +121,8 @@ module Decidim
121
121
  @page ||= scoped_resource
122
122
  end
123
123
 
124
+ protected
125
+
124
126
  def collection
125
127
  current_organization.static_pages
126
128
  end