Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Standardize the way resources are being listed ...' to v0.27 #12533

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section class="section row collapse highlighted_results">
<h3 class="section-heading">
<%= translated_attribute(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_results.see_all", count: results_count) %></a>
<%= decidim_escape_translated(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_results.see_all", count: results_count) %></a>
</h3>

<div class="row">
Expand Down
11 changes: 11 additions & 0 deletions decidim-admin/app/events/decidim/component_published_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@

module Decidim
class ComponentPublishedEvent < Decidim::Events::SimpleEvent
# Public: The Hash of options to pass to the I18.t method.
def i18n_options
default_i18n_options.merge(event_interpolations)
end

def resource_title
return unless resource

title = decidim_sanitize_translated(resource.name)
Decidim::ContentProcessor.render_without_format(title, links: false).html_safe
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Admin
# This module includes helpers to show Admin Terms of Use
module AdminTermsHelper
def admin_terms_of_use_body
current_organization.admin_terms_of_use_body.symbolize_keys[I18n.locale].html_safe
decidim_sanitize_admin(translated_attribute(current_organization.admin_terms_of_use_body)).html_safe
end

def announcement_body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
let(:resource) { create(:component) }
let(:participatory_space) { resource.participatory_space }
let(:resource_path) { main_component_path(resource) }
let(:email_subject) { "An update to #{participatory_space.title["en"]}" }
let(:email_intro) { "The #{resource.name["en"]} component is now active for #{participatory_space.title["en"]}. You can see it from this page:" }
let(:email_outro) { "You have received this notification because you are following #{participatory_space.title["en"]}. You can stop receiving notifications following the previous link." }
let(:notification_title) { "The #{resource.name["en"]} component is now active for <a href=\"#{resource_path}\">#{participatory_space.title["en"]}</a>" }
let(:email_subject) { "An update to #{participatory_space_title}" }
let(:resource_title) { decidim_sanitize_translated(resource.name) }
let(:email_intro) { "The #{resource_title} component is now active for #{participatory_space_title}. You can see it from this page:" }
let(:email_outro) { "You have received this notification because you are following #{participatory_space_title}. You can stop receiving notifications following the previous link." }
let(:notification_title) { "The #{resource_title} component is now active for <a href=\"#{resource_path}\">#{participatory_space_title}</a>" }

it_behaves_like "a simple event"
it_behaves_like "a simple event email"
Expand Down
2 changes: 1 addition & 1 deletion decidim-assemblies/lib/decidim/assemblies/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AdminEngine < ::Rails::Engine
initializer "decidim_assemblies.admin_assemblies_components_menu" do
Decidim.menu :admin_assemblies_components_menu do |menu|
current_participatory_space.components.each do |component|
caption = translated_attribute(component.name)
caption = decidim_escape_translated(component.name)
if component.primary_stat.present?
caption += content_tag(:span, component.primary_stat, class: component.primary_stat.zero? ? "component-counter component-counter--off" : "component-counter")
end
Expand Down
3 changes: 3 additions & 0 deletions decidim-assemblies/lib/decidim/assemblies/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
end

factory :assembly, class: "Decidim::Assembly" do
transient do
skip_injection { false }
end
title { generate_localized_title }
slug { generate(:assembly_slug) }
subtitle { generate_localized_title }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ module Decidim::Budgets
end

it "includes the budget title" do
expect(mail.body.encoded).to include(translated(budget.title))
expect(mail.body.encoded).to include(decidim_escape_translated(budget.title))
end

it "includes the participatory space title" do
expect(mail.body).to include(translated(space.title))
expect(mail.body).to include(decidim_escape_translated(space.title))
end

it "includes the projects names" do
order.projects.each do |project|
expect(mail.body).to include(translated(project.title))
expect(mail.body).to include(decidim_escape_translated(project.title))
end
end
end
Expand All @@ -51,7 +51,7 @@ module Decidim::Budgets

it "includes the scope name and scope type name" do
expect(mail.body.encoded).to include(translated(scope.name))
expect(mail.body.encoded).to include(translated(scope.scope_type.name))
expect(mail.body.encoded).to include(decidim_escape_translated(scope.scope_type.name))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def image_big
end

def title
translated_attribute model.title
decidim_escape_translated model.title
end

def short_description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AdminEngine < ::Rails::Engine
initializer "decidim_conferences.admin_conferences_components_menu" do
Decidim.menu :admin_conferences_components_menu do |menu|
current_participatory_space.components.each do |component|
caption = translated_attribute(component.name)
caption = decidim_escape_translated(component.name)
if component.primary_stat.present?
caption += content_tag(:span, component.primary_stat, class: component.primary_stat.zero? ? "component-counter component-counter--off" : "component-counter")
end
Expand Down
6 changes: 3 additions & 3 deletions decidim-conferences/spec/system/media_spec.rb
alecslupu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def visit_conference
it "shows them" do
within "div.wrapper .conference-media" do
expect(page).to have_content("MEDIA AND LINKS")
expect(page).to have_content(/#{translated(media_link.title, locale: :en)}/i)
expect(page).to have_content(translated(media_link.title))
expect(page).to have_css(".media-links a")
end
end
Expand All @@ -65,7 +65,7 @@ def visit_conference

it "shows them" do
within "div.wrapper .documents" do
expect(page).to have_content(/#{translated(document.title, locale: :en)}/i)
expect(page).to have_content(translated(document.title))
end

within "div.wrapper .images" do
Expand All @@ -86,7 +86,7 @@ def visit_conference

it "shows them ordered" do
within "div.wrapper .documents" do
expect(translated(first_document.title, locale: :en)).to appear_before(translated(last_document.title, locale: :en))
expect(decidim_escape_translated(first_document.title).gsub("&quot;", "\"")).to appear_before(decidim_escape_translated(last_document.title).gsub("&quot;", "\""))
end

within "div.wrapper .images" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class AdminEngine < ::Rails::Engine
initializer "decidim_consultations.admin_consultation_components_menu" do
Decidim.menu :admin_consultation_components_menu do |menu|
current_participatory_space.components.each do |component|
caption = translated_attribute(component.name)
caption = decidim_escape_translated(component.name)
if component.primary_stat.present?
caption += content_tag(:span, component.primary_stat, class: component.primary_stat.zero? ? "component-counter component-counter--off" : "component-counter")
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="picker-values">
<%- scopes.each do |scope, params| %>
<div><%= link_to params[:text], params[:url], data: { picker_value: scope.id } %></div>
<div><%= link_to decidim_html_escape(params[:text]), params[:url], data: { picker_value: scope.id } %></div>
<% end %>
</div>
9 changes: 9 additions & 0 deletions decidim-core/app/helpers/decidim/sanitize_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module SanitizeHelper
def self.included(base)
base.include ActionView::Helpers::SanitizeHelper
base.include ActionView::Helpers::TagHelper
base.include Decidim::TranslatableAttributes
end

# Public: It sanitizes a user-inputted string with the
Expand Down Expand Up @@ -53,6 +54,14 @@ def decidim_url_escape(text)
decidim_html_escape(text).sub(/^javascript:/, "")
end

def decidim_sanitize_translated(text)
decidim_sanitize(translated_attribute(text))
end

def decidim_escape_translated(text)
decidim_html_escape(translated_attribute(text))
end

private

# Maintains the paragraphs and lists separations with their bullet points and
Expand Down