decidim-core 0.31.7 → 0.31.9
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.
- checksums.yaml +4 -4
- data/app/cells/decidim/address_cell.rb +7 -3
- data/app/cells/decidim/card_metadata_cell.rb +3 -1
- data/app/cells/decidim/content_blocks/participatory_space_main_data/title.erb +1 -14
- data/app/cells/decidim/date_range/show.erb +6 -6
- data/app/cells/decidim/date_range_cell.rb +7 -2
- data/app/cells/decidim/following_cell.rb +1 -1
- data/app/cells/decidim/nav_links/show.erb +3 -1
- data/app/cells/decidim/participatory_space_private_user/show.erb +1 -1
- data/app/cells/decidim/share_text_widget/modal.erb +1 -0
- data/app/cells/decidim/share_widget/modal.erb +1 -0
- data/app/cells/decidim/share_widget/qr_code_modal.erb +2 -4
- data/app/commands/decidim/create_follow.rb +3 -7
- data/app/commands/decidim/create_omniauth_registration.rb +19 -7
- data/app/commands/decidim/create_user_report.rb +1 -1
- data/app/commands/decidim/destroy_account.rb +6 -6
- data/app/commands/decidim/destroy_ephemeral_user.rb +2 -0
- data/app/commands/decidim/invite_user.rb +1 -1
- data/app/commands/decidim/multiple_attachments_methods.rb +17 -3
- data/app/commands/decidim/update_resources_taxonomies.rb +2 -1
- data/app/controllers/concerns/decidim/devise_authentication_methods.rb +4 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +4 -0
- data/app/controllers/concerns/decidim/direct_upload.rb +12 -6
- data/app/controllers/concerns/decidim/disable_redirection_to_external_host.rb +2 -0
- data/app/controllers/concerns/decidim/filter_resource.rb +2 -0
- data/app/controllers/concerns/decidim/impersonate_users.rb +4 -4
- data/app/controllers/concerns/decidim/locale_switcher.rb +62 -11
- data/app/controllers/concerns/decidim/needs_organization.rb +15 -0
- data/app/controllers/concerns/decidim/needs_permission.rb +22 -10
- data/app/controllers/concerns/decidim/onboarding_action_methods.rb +2 -0
- data/app/controllers/concerns/decidim/paginable.rb +7 -3
- data/app/controllers/concerns/decidim/payload_info.rb +2 -0
- data/app/controllers/concerns/decidim/resource_versions_concern.rb +14 -0
- data/app/controllers/decidim/amendments_controller.rb +34 -6
- data/app/controllers/decidim/application_controller.rb +2 -6
- data/app/controllers/decidim/authorization_modals_controller.rb +3 -1
- data/app/controllers/decidim/components/base_controller.rb +2 -0
- data/app/controllers/decidim/devise/passwords_controller.rb +8 -0
- data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +10 -4
- data/app/controllers/decidim/doorkeeper/credentials_controller.rb +6 -1
- data/app/controllers/decidim/favicon_controller.rb +9 -0
- data/app/controllers/decidim/free_resource_authorization_modals_controller.rb +2 -0
- data/app/controllers/decidim/gamification/badges_controller.rb +2 -0
- data/app/controllers/decidim/homepage_controller.rb +4 -1
- data/app/controllers/decidim/likes_controller.rb +1 -1
- data/app/controllers/decidim/links_controller.rb +2 -0
- data/app/controllers/decidim/manifests_controller.rb +2 -0
- data/app/controllers/decidim/messaging/conversations_controller.rb +11 -5
- data/app/controllers/decidim/newsletters_controller.rb +4 -0
- data/app/controllers/decidim/notifications_subscriptions_controller.rb +4 -0
- data/app/controllers/decidim/offline_controller.rb +5 -1
- data/app/controllers/decidim/open_data_controller.rb +5 -1
- data/app/controllers/decidim/pages_controller.rb +31 -3
- data/app/controllers/decidim/private_downloads_controller.rb +2 -0
- data/app/controllers/decidim/profiles_controller.rb +11 -1
- data/app/controllers/decidim/qr_controller.rb +3 -1
- data/app/controllers/decidim/resource_autocomplete_controller.rb +2 -0
- data/app/controllers/decidim/searches_controller.rb +2 -0
- data/app/controllers/decidim/short_links_controller.rb +4 -0
- data/app/controllers/decidim/static_map_controller.rb +2 -0
- data/app/controllers/decidim/timeouts_controller.rb +4 -0
- data/app/controllers/decidim/tos_controller.rb +2 -0
- data/app/controllers/decidim/upload_validations_controller.rb +4 -2
- data/app/controllers/decidim/user_activities_controller.rb +2 -0
- data/app/forms/decidim/upload_validation_form.rb +16 -10
- data/app/helpers/concerns/decidim/user_role_checker.rb +35 -10
- data/app/helpers/decidim/cells_paginate_helper.rb +0 -5
- data/app/helpers/decidim/layout_helper.rb +1 -0
- data/app/helpers/decidim/orders_helper.rb +8 -6
- data/app/helpers/decidim/paginate_helper.rb +27 -2
- data/app/helpers/decidim/sanitize_helper.rb +11 -1
- data/app/helpers/decidim/url_helper.rb +35 -0
- data/app/jobs/decidim/application_job.rb +4 -0
- data/app/jobs/decidim/open_data_job.rb +21 -5
- data/app/models/decidim/action_log.rb +7 -1
- data/app/models/decidim/authorization.rb +24 -0
- data/app/models/decidim/component.rb +10 -0
- data/app/models/decidim/like.rb +1 -1
- data/app/models/decidim/oauth_application.rb +1 -0
- data/app/models/decidim/user.rb +1 -0
- data/app/models/decidim/user_base_entity.rb +1 -1
- data/app/packs/src/decidim/callout.js +10 -0
- data/app/packs/src/decidim/callout.test.js +32 -0
- data/app/packs/src/decidim/controllers/accordion/accordion.test.js +64 -0
- data/app/packs/src/decidim/controllers/accordion/controller.js +43 -0
- data/app/packs/src/decidim/datepicker/datepicker_functions.js +54 -30
- data/app/packs/src/decidim/datepicker/form_datepicker.js +18 -2
- data/app/packs/src/decidim/datepicker/generate_datepicker.js +16 -8
- data/app/packs/src/decidim/datepicker/generate_timepicker.js +5 -3
- data/app/packs/src/decidim/datepicker/test/date.test.js +8 -0
- data/app/packs/src/decidim/datepicker/test/time.test.js +39 -24
- data/app/packs/src/decidim/utilities/dom.js +2 -2
- data/app/packs/stylesheets/decidim/_content_blocks.scss +4 -10
- data/app/packs/stylesheets/decidim/_conversations.scss +0 -8
- data/app/packs/stylesheets/decidim/_datepicker.scss +3 -3
- data/app/packs/stylesheets/decidim/_modal.scss +16 -8
- data/app/packs/stylesheets/decidim/_modal_share.scss +0 -22
- data/app/packs/stylesheets/decidim/_participatory_spaces.scss +11 -1
- data/app/packs/stylesheets/decidim/_rich_text.scss +12 -9
- data/app/packs/stylesheets/decidim/_spinner.scss +16 -0
- data/app/packs/stylesheets/decidim/_tom_select.scss +1 -1
- data/app/packs/stylesheets/decidim/_typography.scss +5 -2
- data/app/packs/stylesheets/decidim/legacy/email.scss +0 -5
- data/app/permissions/decidim/permissions.rb +20 -0
- data/app/presenters/decidim/admin_log/component_presenter.rb +1 -1
- data/app/presenters/decidim/log/base_presenter.rb +20 -2
- data/app/presenters/decidim/log/user_presenter.rb +2 -2
- data/app/serializers/decidim/exporters/open_data_blocked_user_serializer.rb +11 -2
- data/app/serializers/decidim/exporters/open_data_moderation_serializer.rb +25 -1
- data/app/services/decidim/action_logger.rb +97 -29
- data/app/services/decidim/svg_content_validator.rb +889 -0
- data/app/uploaders/decidim/application_uploader.rb +2 -2
- data/app/validators/uploader_image_content_validator.rb +282 -0
- data/app/views/decidim/application/_radio_accordion.html.erb +1 -5
- data/app/views/decidim/manifests/show.json.erb +25 -22
- data/app/views/decidim/messaging/conversations/create.js.erb +1 -3
- data/app/views/decidim/shared/_login_modal.html.erb +12 -14
- data/app/views/decidim/shared/_results_per_page.html.erb +1 -1
- data/app/views/layouts/decidim/_mailer_logo.html.erb +1 -1
- data/config/initializers/rack_attack.rb +10 -0
- data/config/locales/bg.yml +1 -4
- data/config/locales/ca-IT.yml +8 -4
- data/config/locales/ca.yml +10 -6
- data/config/locales/cs.yml +16 -4
- data/config/locales/de.yml +62 -6
- data/config/locales/en.yml +8 -4
- data/config/locales/es-MX.yml +8 -4
- data/config/locales/es-PY.yml +8 -4
- data/config/locales/es.yml +14 -10
- data/config/locales/eu.yml +165 -164
- data/config/locales/fi-plain.yml +3 -3
- data/config/locales/fi.yml +3 -3
- data/config/locales/fr-CA.yml +8 -4
- data/config/locales/fr.yml +8 -4
- data/config/locales/gl.yml +1440 -33
- data/config/locales/hu.yml +0 -1
- data/config/locales/it.yml +0 -2
- data/config/locales/ja.yml +4 -4
- data/config/locales/pl.yml +1 -4
- data/config/locales/pt-BR.yml +1 -4
- data/config/locales/ro-RO.yml +0 -3
- data/config/locales/sk.yml +51 -4
- data/config/locales/sv.yml +50 -13
- data/config/locales/tr-TR.yml +1 -3
- data/db/migrate/20250523104311_move_cta_to_hero_content_block.rb +1 -1
- data/db/migrate/20250527122040_move_highlighted_content_banner_settings_to_content_block.rb +3 -0
- data/db/migrate/20260909000000_add_failed_attempts_and_locked_at_to_decidim_authorizations.rb +8 -0
- data/db/migrate/20261007090000_make_user_optional_in_action_logs.rb +12 -0
- data/decidim-core.gemspec +1 -1
- data/lib/decidim/content_renderers/mention_resource_renderer.rb +6 -3
- data/lib/decidim/core/test/factories.rb +2 -2
- data/lib/decidim/core/test/shared_examples/participatory_space_members_page_examples.rb +77 -0
- data/lib/decidim/core/test/shared_examples/participatory_space_members_shared_examples.rb +85 -6
- data/lib/decidim/core/test/shared_examples/versions_controller_examples.rb +23 -1
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/core.rb +10 -1
- data/lib/decidim/has_upload_validations.rb +1 -0
- data/lib/decidim/legacy_form_builder.rb +4 -0
- data/lib/decidim/maintenance/import_models/scope.rb +2 -1
- data/lib/decidim/maintenance/taxonomy_importer.rb +4 -1
- data/lib/decidim/query_extensions.rb +2 -0
- data/lib/decidim/view_model.rb +1 -0
- data/lib/tasks/decidim_open_data_tasks.rake +7 -0
- metadata +22 -10
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
.title-decorator {
|
|
30
|
-
@apply h2 md:h1 decorator;
|
|
30
|
+
@apply h2 md:h1 decorator break-normal;
|
|
31
|
+
|
|
32
|
+
hyphens: auto;
|
|
33
|
+
overflow-wrap: anywhere;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
.text-with-links {
|
|
@@ -38,7 +41,7 @@
|
|
|
38
41
|
|
|
39
42
|
/* default styles for those dynamic text blocks */
|
|
40
43
|
.editor-content {
|
|
41
|
-
@apply prose max-w-full text-gray-2 text-lg prose-a:text-secondary break-words prose-ul:pl-
|
|
44
|
+
@apply prose max-w-full text-gray-2 text-lg prose-a:text-secondary break-words prose-ul:pl-8 prose-ol:pl-8;
|
|
42
45
|
|
|
43
46
|
iframe {
|
|
44
47
|
@apply w-full block max-w-[600px] max-h-[70vh] h-[450px] my-10 mx-auto;
|
|
@@ -1725,7 +1725,6 @@ body.outlook p {
|
|
|
1725
1725
|
table.body th.decidim-bar,
|
|
1726
1726
|
table.body td.decidim-bar {
|
|
1727
1727
|
padding: 10px 0;
|
|
1728
|
-
background-color: #1a181d;
|
|
1729
1728
|
}
|
|
1730
1729
|
|
|
1731
1730
|
table.body {
|
|
@@ -1742,10 +1741,6 @@ table.body {
|
|
|
1742
1741
|
height: 30px;
|
|
1743
1742
|
}
|
|
1744
1743
|
|
|
1745
|
-
.cityhall-bar {
|
|
1746
|
-
background-color: #2c2930;
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
1744
|
.cityhall-logo {
|
|
1750
1745
|
width: 150px;
|
|
1751
1746
|
margin-top: 16px;
|
|
@@ -9,6 +9,7 @@ module Decidim
|
|
|
9
9
|
locales_action?
|
|
10
10
|
component_public_action?
|
|
11
11
|
search_scope_action?
|
|
12
|
+
public_content_action?
|
|
12
13
|
|
|
13
14
|
public_report_content_action?
|
|
14
15
|
|
|
@@ -66,6 +67,23 @@ module Decidim
|
|
|
66
67
|
toggle_allow([:search, :pick].include?(permission_action.action))
|
|
67
68
|
end
|
|
68
69
|
|
|
70
|
+
# Public, non-resource content that any visitor is allowed to reach. The
|
|
71
|
+
# controllers using these subjects enforce the actual data visibility
|
|
72
|
+
# themselves (profile publication, private download tokens, newsletter
|
|
73
|
+
# tokens, etc.).
|
|
74
|
+
def public_content_action?
|
|
75
|
+
case permission_action.subject
|
|
76
|
+
when :open_data, :search, :profile, :private_download, :short_link,
|
|
77
|
+
:calendar, :badges, :static_map, :qr_code, :homepage, :manifest,
|
|
78
|
+
:offline, :link, :authorization, :error, :timeout, :page
|
|
79
|
+
allow! if permission_action.action == :read
|
|
80
|
+
when :newsletter
|
|
81
|
+
allow! if [:read, :unsubscribe].include?(permission_action.action)
|
|
82
|
+
when :upload_validation
|
|
83
|
+
allow! if permission_action.action == :create
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
69
87
|
def manage_self_user_action?
|
|
70
88
|
return unless permission_action.subject == :user
|
|
71
89
|
|
|
@@ -78,6 +96,8 @@ module Decidim
|
|
|
78
96
|
authorization = context.fetch(:authorization, nil)
|
|
79
97
|
|
|
80
98
|
case permission_action.action
|
|
99
|
+
when :read
|
|
100
|
+
allow!
|
|
81
101
|
when :create
|
|
82
102
|
toggle_allow(authorization.user == user && not_already_active?(authorization))
|
|
83
103
|
when :update, :destroy
|
|
@@ -29,7 +29,7 @@ module Decidim
|
|
|
29
29
|
|
|
30
30
|
def action_string
|
|
31
31
|
case action
|
|
32
|
-
when "export_component", "soft_delete", "restore"
|
|
32
|
+
when "export_component", "soft_delete", "restore", "menu_hidden"
|
|
33
33
|
"decidim.admin_log.component.#{action}"
|
|
34
34
|
when "create", "delete", "publish", "unpublish", "update_permissions", "update_filters"
|
|
35
35
|
generate_action_string(action)
|
|
@@ -111,9 +111,18 @@ module Decidim
|
|
|
111
111
|
# Returns an HTML-safe String.
|
|
112
112
|
def present_explanation
|
|
113
113
|
h.content_tag(:div, class: "logs__log__explanation") do
|
|
114
|
+
escaped_params = i18n_params.transform_values do |value|
|
|
115
|
+
if value.is_a?(String) && !value.html_safe?
|
|
116
|
+
ERB::Util.html_escape(value)
|
|
117
|
+
else
|
|
118
|
+
value
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
114
122
|
I18n.t(
|
|
115
123
|
action_string,
|
|
116
|
-
|
|
124
|
+
escape: false,
|
|
125
|
+
**escaped_params
|
|
117
126
|
).html_safe
|
|
118
127
|
end
|
|
119
128
|
end
|
|
@@ -196,12 +205,21 @@ module Decidim
|
|
|
196
205
|
# Returns a Hash.
|
|
197
206
|
def i18n_params
|
|
198
207
|
{
|
|
199
|
-
user_name: user_presenter.present,
|
|
208
|
+
user_name: system_action? ? nil : user_presenter.present,
|
|
200
209
|
resource_name: resource_presenter.try(:present),
|
|
201
210
|
space_name: space_presenter.present
|
|
202
211
|
}
|
|
203
212
|
end
|
|
204
213
|
|
|
214
|
+
# Private: Whether the action was performed by the system rather than a
|
|
215
|
+
# user. A deleted user still leaves its reference in the log, so this
|
|
216
|
+
# cannot be based on the loaded `user` association.
|
|
217
|
+
#
|
|
218
|
+
# Returns a Boolean.
|
|
219
|
+
def system_action?
|
|
220
|
+
action_log.user_id.blank? && action_log.user_type.blank?
|
|
221
|
+
end
|
|
222
|
+
|
|
205
223
|
# Private: Calculates if the diff has to be shown or not.
|
|
206
224
|
#
|
|
207
225
|
# Returns a Boolean.
|
|
@@ -66,9 +66,9 @@ module Decidim
|
|
|
66
66
|
|
|
67
67
|
# Private: Presents the nickname of the user performing the action.
|
|
68
68
|
#
|
|
69
|
-
# Returns
|
|
69
|
+
# Returns a String.
|
|
70
70
|
def present_user_nickname
|
|
71
|
-
extra["nickname"]
|
|
71
|
+
extra["nickname"]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# Private: Calculates the path for the user. Returns the path of the
|
|
@@ -16,10 +16,19 @@ module Decidim
|
|
|
16
16
|
about: resource.user.about,
|
|
17
17
|
reasons: resource.reports.map(&:reason),
|
|
18
18
|
details: resource.reports.map(&:details),
|
|
19
|
-
block_reasons:
|
|
20
|
-
blocking_user:
|
|
19
|
+
block_reasons: blocking&.justification,
|
|
20
|
+
blocking_user: blocking_user&.presenter&.name
|
|
21
21
|
}
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# The collection filters on `decidim_users.blocked_at`, but this
|
|
27
|
+
# association is resolved through `decidim_users.block_id`. The two can
|
|
28
|
+
# disagree, in which case there is no block to read the details from.
|
|
29
|
+
def blocking = resource.blocking
|
|
30
|
+
|
|
31
|
+
def blocking_user = blocking&.blocking_user
|
|
23
32
|
end
|
|
24
33
|
end
|
|
25
34
|
end
|
|
@@ -14,7 +14,7 @@ module Decidim
|
|
|
14
14
|
id: resource.id,
|
|
15
15
|
hidden_at: resource.hidden_at,
|
|
16
16
|
report_count: resource.report_count,
|
|
17
|
-
reported_url
|
|
17
|
+
reported_url:,
|
|
18
18
|
reportable_type: resource.decidim_reportable_type,
|
|
19
19
|
reportable_id: resource.decidim_reportable_id,
|
|
20
20
|
reported_content: resource.reported_content,
|
|
@@ -25,6 +25,30 @@ module Decidim
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# `Decidim::Moderation#reportable` is polymorphic, so the database cannot
|
|
32
|
+
# enforce the reference, and the moderation row outlives the resource it
|
|
33
|
+
# points at. Both of the cases below leave the moderation in the export
|
|
34
|
+
# collection with no URL to build.
|
|
35
|
+
def reported_url
|
|
36
|
+
reportable = resource.reportable
|
|
37
|
+
|
|
38
|
+
# The resource is gone. Reportables such as proposals and meetings are
|
|
39
|
+
# soft-deletable while `belongs_to :reportable` does not use
|
|
40
|
+
# `with_deleted`, so moving one to the trash is enough for this.
|
|
41
|
+
return if reportable.nil?
|
|
42
|
+
|
|
43
|
+
# The component is gone but the resource is not: trashing a component
|
|
44
|
+
# does not trash its contents. `ResourceLocatorPresenter#route_proxy`
|
|
45
|
+
# falls back to the resource itself when `component` is nil, and
|
|
46
|
+
# `EngineRouter.main_proxy` then calls `mounted_engine` on it, which
|
|
47
|
+
# only components and participatory spaces respond to.
|
|
48
|
+
return if reportable.is_a?(Decidim::HasComponent) && reportable.component.nil?
|
|
49
|
+
|
|
50
|
+
reportable.reported_content_url
|
|
51
|
+
end
|
|
28
52
|
end
|
|
29
53
|
end
|
|
30
54
|
end
|
|
@@ -5,31 +5,65 @@ module Decidim
|
|
|
5
5
|
# use this class directly, but rather use `Decidim.traceability` instead.
|
|
6
6
|
# Check the docs on `Decidim::Traceability` for more info.
|
|
7
7
|
#
|
|
8
|
-
#
|
|
8
|
+
# @example Log an action performed by a user
|
|
9
|
+
# Decidim::ActionLogger.log(:create, user, new_proposal, version_id, extra_data)
|
|
9
10
|
#
|
|
10
|
-
#
|
|
11
|
+
# @example Log an action performed by the system
|
|
12
|
+
# Decidim::ActionLogger.log_system(:create, new_proposal, visibility: "public-only")
|
|
13
|
+
#
|
|
14
|
+
# @see Decidim::Traceability
|
|
11
15
|
class ActionLogger
|
|
12
|
-
#
|
|
16
|
+
# Logs the given `action` by the given `user` on the given `resource`.
|
|
13
17
|
# Delegates the work to the instance method.
|
|
14
18
|
#
|
|
15
|
-
# action
|
|
16
|
-
# user
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
19
|
+
# @param action [String, Symbol] the name of the action performed
|
|
20
|
+
# @param user [Decidim::User, Decidim::Api::ApiUser] the user that
|
|
21
|
+
# performed the action
|
|
22
|
+
# @param resource [ActiveRecord::Base] the resource on which the action was
|
|
23
|
+
# performed
|
|
24
|
+
# @param version_id [Integer, nil] the ID of the `PaperTrail::Version` that
|
|
25
|
+
# was created by the action
|
|
26
|
+
# @param resource_extra [Hash] extra information to be recorded in the
|
|
27
|
+
# action log. It may include the `:visibility` key to set the visibility
|
|
28
|
+
# of the action log.
|
|
29
|
+
#
|
|
30
|
+
# @return [Decidim::ActionLog] the newly created action log
|
|
20
31
|
#
|
|
21
|
-
#
|
|
32
|
+
# @raise [ArgumentError] if `user` is `nil`. Use {.log_system} for actions
|
|
33
|
+
# performed by the system.
|
|
22
34
|
def self.log(action, user, resource, version_id, resource_extra = {})
|
|
23
|
-
|
|
35
|
+
raise ArgumentError, "ActionLogger.log requires a user. Use ActionLogger.log_system for actions performed by the system." if user.nil?
|
|
36
|
+
|
|
37
|
+
new(action, user, resource, version_id, resource_extra).send(:log!)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Logs the given `action` performed by the system (i.e. without a user) on
|
|
41
|
+
# the given `resource`.
|
|
42
|
+
#
|
|
43
|
+
# @param action [String, Symbol] the name of the action performed
|
|
44
|
+
# @param resource [ActiveRecord::Base] the resource on which the action was
|
|
45
|
+
# performed
|
|
46
|
+
# @param resource_extra [Hash] keyword arguments with extra information to
|
|
47
|
+
# be recorded in the action log. It may include the `:visibility` key to
|
|
48
|
+
# set the visibility of the action log.
|
|
49
|
+
#
|
|
50
|
+
# @return [Decidim::ActionLog] the newly created action log
|
|
51
|
+
def self.log_system(action, resource, **resource_extra)
|
|
52
|
+
new(action, nil, resource, nil, resource_extra).send(:log!)
|
|
24
53
|
end
|
|
25
54
|
|
|
26
|
-
#
|
|
55
|
+
# Initializes the instance.
|
|
27
56
|
#
|
|
28
|
-
# action
|
|
29
|
-
# user
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
57
|
+
# @param action [String, Symbol] the name of the action performed
|
|
58
|
+
# @param user [Decidim::User, Decidim::Api::ApiUser, nil] the user that
|
|
59
|
+
# performed the action, or `nil` for actions performed by the system
|
|
60
|
+
# @param resource [ActiveRecord::Base] the resource on which the action was
|
|
61
|
+
# performed
|
|
62
|
+
# @param version_id [Integer, nil] the ID of the `PaperTrail::Version` that
|
|
63
|
+
# was created by the action
|
|
64
|
+
# @param resource_extra [Hash] extra information to be recorded in the
|
|
65
|
+
# action log. It may include the `:visibility` key to set the visibility
|
|
66
|
+
# of the action log, which defaults to `"admin-only"`.
|
|
33
67
|
def initialize(action, user, resource, version_id = nil, resource_extra = {})
|
|
34
68
|
@action = action
|
|
35
69
|
@user = user
|
|
@@ -39,14 +73,17 @@ module Decidim
|
|
|
39
73
|
@visibility = resource_extra.delete(:visibility).presence || "admin-only"
|
|
40
74
|
end
|
|
41
75
|
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
# Logs the given `action` by the given `user` on the given `resource`.
|
|
79
|
+
#
|
|
80
|
+
# @return [Decidim::ActionLog] the newly created action log
|
|
44
81
|
#
|
|
45
|
-
#
|
|
82
|
+
# @raise [ActiveRecord::RecordInvalid] if the action log is not valid
|
|
46
83
|
def log!
|
|
47
84
|
Decidim::ActionLog.create!(
|
|
48
|
-
user_id: user
|
|
49
|
-
user_type: user
|
|
85
|
+
user_id: user&.id,
|
|
86
|
+
user_type: user&.class&.name,
|
|
50
87
|
organization:,
|
|
51
88
|
action:,
|
|
52
89
|
resource:,
|
|
@@ -62,44 +99,75 @@ module Decidim
|
|
|
62
99
|
)
|
|
63
100
|
end
|
|
64
101
|
|
|
65
|
-
|
|
66
|
-
|
|
102
|
+
# The values given to the logger when it was initialized.
|
|
67
103
|
attr_reader :action, :user, :resource, :resource_extra, :version_id, :visibility
|
|
68
104
|
|
|
105
|
+
# Finds the organization related to the action log.
|
|
106
|
+
#
|
|
107
|
+
# @return [Decidim::Organization, nil] the organization of the user, the
|
|
108
|
+
# participatory space, or the resource, whichever is found first
|
|
69
109
|
def organization
|
|
70
|
-
user.organization
|
|
110
|
+
user&.organization || participatory_space&.organization || resource.try(:organization)
|
|
71
111
|
end
|
|
72
112
|
|
|
113
|
+
# Finds the component related to the resource.
|
|
114
|
+
#
|
|
115
|
+
# @return [Decidim::Component, nil] the component of the resource, if the
|
|
116
|
+
# resource responds to `component`
|
|
73
117
|
def component
|
|
74
118
|
resource.component if resource.respond_to?(:component)
|
|
75
119
|
end
|
|
76
120
|
|
|
121
|
+
# Finds the participatory space related to the resource.
|
|
122
|
+
#
|
|
123
|
+
# @return [ActiveRecord::Base, nil] the participatory space of the
|
|
124
|
+
# component, of the resource, or `nil` if it cannot be found
|
|
77
125
|
def participatory_space
|
|
78
126
|
return component.participatory_space if component.respond_to?(:participatory_space)
|
|
79
127
|
|
|
80
128
|
resource.participatory_space if resource.respond_to?(:participatory_space)
|
|
81
129
|
end
|
|
82
130
|
|
|
131
|
+
# Finds the area related to the resource or its participatory space.
|
|
132
|
+
#
|
|
133
|
+
# @return [Decidim::Area, nil] the area of the resource or the
|
|
134
|
+
# participatory space, or `nil` if it cannot be found
|
|
83
135
|
def area
|
|
84
136
|
resource.try(:area) || participatory_space.try(:area)
|
|
85
137
|
end
|
|
86
138
|
|
|
139
|
+
# Finds the scope related to the resource or its participatory space.
|
|
140
|
+
#
|
|
141
|
+
# @return [Decidim::Scope, nil] the scope of the resource or the
|
|
142
|
+
# participatory space, or `nil` if it cannot be found
|
|
87
143
|
def scope
|
|
88
144
|
resource.try(:scope) || participatory_space.try(:scope)
|
|
89
145
|
end
|
|
90
146
|
|
|
147
|
+
# Finds a human-readable title for the given resource.
|
|
148
|
+
#
|
|
149
|
+
# @param resource [Object, nil] an object that may respond to `title`,
|
|
150
|
+
# `name`, or `subject`
|
|
151
|
+
# @return [String, nil] the title, name, or subject of the resource, or
|
|
152
|
+
# `nil` if none of them is available
|
|
91
153
|
def title_for(resource)
|
|
92
154
|
resource.try(:title) || resource.try(:name) || resource.try(:subject)
|
|
93
155
|
end
|
|
94
156
|
|
|
157
|
+
# Finds the manifest name of the participatory space.
|
|
158
|
+
#
|
|
159
|
+
# @return [Symbol, nil] the manifest name of the participatory space, or
|
|
160
|
+
# `nil` if it cannot be found
|
|
95
161
|
def participatory_space_manifest_name
|
|
96
162
|
participatory_space.try(:class).try(:participatory_space_manifest).try(:name)
|
|
97
163
|
end
|
|
98
164
|
|
|
99
|
-
#
|
|
165
|
+
# Defines some extra data that will be saved in the action log `extra`
|
|
100
166
|
# field.
|
|
101
167
|
#
|
|
102
|
-
#
|
|
168
|
+
# @return [Hash] the extra data with information about the component, the
|
|
169
|
+
# participatory space, the resource, and the user, merged with the
|
|
170
|
+
# `resource_extra` information
|
|
103
171
|
def extra_data
|
|
104
172
|
{
|
|
105
173
|
component: {
|
|
@@ -114,9 +182,9 @@ module Decidim
|
|
|
114
182
|
title: title_for(resource)
|
|
115
183
|
}.compact,
|
|
116
184
|
user: {
|
|
117
|
-
ip: user
|
|
118
|
-
name: user
|
|
119
|
-
nickname: user
|
|
185
|
+
ip: user&.current_sign_in_ip,
|
|
186
|
+
name: user&.name,
|
|
187
|
+
nickname: user&.nickname
|
|
120
188
|
}.compact
|
|
121
189
|
}.deep_merge(resource_extra)
|
|
122
190
|
end
|