From f66aa7642b5e6f9392f1cbfad48372a69606bf7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Wed, 31 Jan 2024 17:55:45 +0100 Subject: [PATCH] remove addional helper --- .../decidim/proposals/application_helper.rb | 33 +++++++++++++++++- .../proposals/proposal_presenter_helper.rb | 34 ------------------- .../decidim/proposals/diff_renderer.rb | 2 +- 3 files changed, 33 insertions(+), 36 deletions(-) delete mode 100644 decidim-proposals/app/helpers/decidim/proposals/proposal_presenter_helper.rb diff --git a/decidim-proposals/app/helpers/decidim/proposals/application_helper.rb b/decidim-proposals/app/helpers/decidim/proposals/application_helper.rb index 560c3b755979..09294badb203 100644 --- a/decidim-proposals/app/helpers/decidim/proposals/application_helper.rb +++ b/decidim-proposals/app/helpers/decidim/proposals/application_helper.rb @@ -8,7 +8,6 @@ module ApplicationHelper include Decidim::Comments::CommentsHelper include PaginateHelper include ProposalVotesHelper - include ProposalPresenterHelper include ::Decidim::EndorsableHelper include ::Decidim::FollowableHelper include Decidim::MapHelper @@ -83,6 +82,38 @@ def minimum_votes_per_user_enabled? minimum_votes_per_user.positive? end + def not_from_collaborative_draft(proposal) + proposal.linked_resources(:proposals, "created_from_collaborative_draft").empty? + end + + def not_from_participatory_text(proposal) + proposal.participatory_text_level.nil? + end + + # If the proposal is official or the rich text editor is enabled on the + # frontend, the proposal body is considered as safe content; that's unless + # the proposal comes from a collaborative_draft or a participatory_text. + def safe_content? + (rich_text_editor_in_public_views? && not_from_collaborative_draft(@proposal)) || + safe_content_admin? + end + + # For admin entered content, the proposal body can contain certain extra + # tags, such as iframes. + def safe_content_admin? + (@proposal.official? || @proposal.official_meeting?) && not_from_participatory_text(@proposal) + end + + # If the content is safe, HTML tags are sanitized, otherwise, they are stripped. + def render_proposal_body(proposal) + sanitized = render_sanitized_content(proposal, :body) + if safe_content? + Decidim::ContentProcessor.render_without_format(sanitized).html_safe + else + Decidim::ContentProcessor.render(sanitized, "div") + end + end + # Returns :text_area or :editor based on the organization' settings. def text_editor_for_proposal_body(form) options = { diff --git a/decidim-proposals/app/helpers/decidim/proposals/proposal_presenter_helper.rb b/decidim-proposals/app/helpers/decidim/proposals/proposal_presenter_helper.rb deleted file mode 100644 index 26726cf19b64..000000000000 --- a/decidim-proposals/app/helpers/decidim/proposals/proposal_presenter_helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Proposals - module ProposalPresenterHelper - include Decidim::ApplicationHelper - - def not_from_collaborative_draft(proposal) - proposal.linked_resources(:proposals, "created_from_collaborative_draft").empty? - end - - def not_from_participatory_text(proposal) - proposal.participatory_text_level.nil? - end - - # If the proposal is official or the rich text editor is enabled on the - # frontend, the proposal body is considered as safe content; that's unless - # the proposal comes from a collaborative_draft or a participatory_text. - def safe_content? - (rich_text_editor_in_public_views? && not_from_collaborative_draft(@proposal)) || - ((@proposal.official? || @proposal.official_meeting?) && not_from_participatory_text(@proposal)) - end - - def render_proposal_title(proposal) - Decidim::Proposals::ProposalPresenter.new(proposal).title(links: true, html_escape: true) - end - - # If the content is safe, HTML tags are sanitized, otherwise, they are stripped. - def render_proposal_body(proposal) - Decidim::ContentProcessor.render(render_sanitized_content(proposal, :body), "div") - end - end - end -end diff --git a/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb b/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb index 9ca60f57dddf..ad222b669c12 100644 --- a/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb +++ b/decidim-proposals/app/services/decidim/proposals/diff_renderer.rb @@ -5,7 +5,7 @@ module Proposals class DiffRenderer < BaseDiffRenderer include ActionView::Helpers::TextHelper include ActionView::Helpers::TagHelper - include ProposalPresenterHelper + include ApplicationHelper include SanitizeHelper delegate :organization, to: :proposal, prefix: :current