OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#64591] Link CF in PDF report only partially clickable when in multiple lines
as-op9d0720bcfd61
diff --git a/Gemfile b/Gemfileindex cac0a32a5f8..92b6b0c3fb6 100644--- a/Gemfile+++ b/Gemfile@@ -158,7 +158,7 @@ gem "structured_warnings", "~> 0.5.0"gem "airbrake", "~> 13.0.0", require: falsegem "markly", "~> 0.13" # another markdown parser like commonmarker, but with AST support used in PDF export-gem "md_to_pdf", git: "https://github.com/opf/md-to-pdf", ref: "be1ab00e2c49ce2e5e08a4edb4733438081c53ab"+gem "md_to_pdf", git: "https://github.com/opf/md-to-pdf", ref: "9961752e4d1e990ec1d4bf48436de9277838763f"gem "prawn", "~> 2.4"gem "ttfunk", "~> 1.7.0" # remove after https://github.com/prawnpdf/prawn/issues/1346 resolved.diff --git a/Gemfile.lock b/Gemfile.lockindex b95b2dd53ec..c6dcf657c45 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -8,10 +8,10 @@ GITGITremote: https://github.com/opf/md-to-pdf- revision: be1ab00e2c49ce2e5e08a4edb4733438081c53ab- ref: be1ab00e2c49ce2e5e08a4edb4733438081c53ab+ revision: 9961752e4d1e990ec1d4bf48436de9277838763f+ ref: 9961752e4d1e990ec1d4bf48436de9277838763fspecs:- md_to_pdf (0.2.3)+ md_to_pdf (0.2.4)base64 (~> 0.2)bigdecimal (~> 3.1)color_conversion (~> 0.1)@@ -1760,7 +1760,7 @@ CHECKSUMSmarcel (1.0.4) sha256=0d5649feb64b8f19f3d3468b96c680bae9746335d02194270287868a661516a4markly (0.13.0) sha256=326a232c876cd95093d110b8d184be8effeadd776c3ffcefd59bdc8de7f59e0dmatrix (0.4.3) sha256=a0d5ab7ddcc1973ff690ab361b67f359acbb16958d1dc072b8b956a286564c5b- md_to_pdf (0.2.3)+ md_to_pdf (0.2.4)messagebird-rest (1.4.2) sha256=1501e16ad76c87558f20f3b26cb39d05f587b349b44b8bf8056b040e9b495301meta-tags (2.22.1) sha256=e5ae1febbd320d396c7226d7edb868e5d63466c14b9c8b06622a1a74e6dce354method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5diff --git a/app/models/exports/formatters/custom_field_pdf.rb b/app/models/exports/formatters/custom_field_pdf.rbindex 351e72e23f2..5d3c709d633 100644--- a/app/models/exports/formatters/custom_field_pdf.rb+++ b/app/models/exports/formatters/custom_field_pdf.rb@@ -35,6 +35,13 @@ module Exportsexport_format == :pdf && attribute.start_with?("cf_")end+ def format_value(value, options)+ # avoid the value transformed in to a string by the super method+ return value if value.is_a?(::Exports::Formatters::LinkFormatter)++ super+ end+### Print the value meant for PDF export.#@@ -44,6 +51,8 @@ module Exportsif custom_field.field_format == "bool"value = object.typed_custom_value_for(custom_field)value ? I18n.t(:general_text_Yes) : I18n.t(:general_text_No)+ elsif custom_field.field_format == "link"+ LinkFormatter.new(object, custom_field)elsesuperenddiff --git a/app/models/exports/formatters/link_formatter.rb b/app/models/exports/formatters/link_formatter.rbnew file mode 100644index 00000000000..2eb737bcccf--- /dev/null+++ b/app/models/exports/formatters/link_formatter.rb@@ -0,0 +1,51 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Exports+ module Formatters+ class LinkFormatter+ def initialize(object, custom_field)+ @href = object.custom_value_for(custom_field).to_s+ end++ def href+ @href+ end++ def to_html+ ApplicationController.helpers.link_to(@href, @href)+ end++ def to_s+ @href+ end+ end+ end+enddiff --git a/app/models/work_package/exports/macros/attributes.rb b/app/models/work_package/exports/macros/attributes.rbindex 2a938e8bdd3..71f7947b3d4 100644--- a/app/models/work_package/exports/macros/attributes.rb+++ b/app/models/work_package/exports/macros/attributes.rb@@ -162,6 +162,9 @@ module WorkPackage::Exportsdef self.format_attribute_value(ar_name, model, obj)formatter = Exports::Register.formatter_for(model, ar_name, :pdf)value = formatter.format(obj)+ # do NOT escape a tag for custom field link+ return value.to_html if value.is_a?(::Exports::Formatters::LinkFormatter)+# important NOT to return empty string as this could change meaning of markdown# e.g. **to_be_replaced** could be rendered as **** (horizontal line and a *)value.blank? ? " " : escape_tags(value)diff --git a/app/models/work_package/exports/macros/links.rb b/app/models/work_package/exports/macros/links.rbindex 5f3b0dcb63b..d0022fe3bf9 100644--- a/app/models/work_package/exports/macros/links.rb+++ b/app/models/work_package/exports/macros/links.rb@@ -48,10 +48,6 @@ module WorkPackage::Exports[WorkPackagesLinkHandler]end- def self.html_replacement?- true- end-# Faster inclusion check before the full regex is being applieddef self.applicable?(content)/#\d/.match(content)diff --git a/app/models/work_package/pdf_export/common/macro.rb b/app/models/work_package/pdf_export/common/macro.rbindex 8eb1fce6cef..26895f07f75 100644--- a/app/models/work_package/pdf_export/common/macro.rb+++ b/app/models/work_package/pdf_export/common/macro.rb@@ -70,17 +70,13 @@ module WorkPackage::PDFExport::Common::Macroenddef apply_macros_node_text(node, context)- formatted, applied_macros = apply_macro_text(node.string_content, context)+ formatted = apply_macro_text(node.string_content, context)return if formatted == node.string_content- if has_html_macro?(applied_macros)- fragment = Markly::Node.new(:inline_html)- fragment.string_content = formatted- node.insert_before(fragment)- node.delete- else- node.string_content = formatted- end+ fragment = Markly::Node.new(:inline_html)+ fragment.string_content = formatted+ node.insert_before(fragment)+ node.deleteenddef apply_macros_node_html(node, context)@@ -100,7 +96,7 @@ module WorkPackage::PDFExport::Common::Macromacro.process_match(Regexp.last_match, matched_string, context)endend- [text, applicable_macros]+ textenddef apply_macro_html(html, context)@@ -111,20 +107,10 @@ module WorkPackage::PDFExport::Common::Macrodoc.to_htmlend- def has_html_macro?(macros)- macros.any? { |macro| macro.respond_to?(:html_replacement?) && macro.html_replacement? }- end-def apply_macro_html_node(node, context)if node.text?- formatted, applied_macros = apply_macro_text(node.content, context)- if formatted != node.content- if has_html_macro?(applied_macros)- node.replace(formatted)- else- node.content = formatted- end- end+ formatted = apply_macro_text(node.content, context)+ node.replace(formatted) if formatted != node.contentelsif PREFORMATTED_BLOCKS.exclude?(node.name)node.children.each { |child| apply_macro_html_node(child, context) }enddiff --git a/app/models/work_package/pdf_export/export/markdown.rb b/app/models/work_package/pdf_export/export/markdown.rbindex 95d7e3a863a..da5d05213a4 100644--- a/app/models/work_package/pdf_export/export/markdown.rb+++ b/app/models/work_package/pdf_export/export/markdown.rb@@ -173,6 +173,8 @@ module WorkPackage::PDFExport::Export::Markdownenddef write_markdown!(markdown, styling_yml)+ return if markdown.blank?+markdown_writer(styling_yml).draw_markdown(markdown, pdf, ->(src) {with_images? ? attachment_image_filepath(src) : nildiff --git a/app/models/work_package/pdf_export/export/wp/attributes.rb b/app/models/work_package/pdf_export/export/wp/attributes.rbindex 255b7c1acc4..2baa34266b9 100644--- a/app/models/work_package/pdf_export/export/wp/attributes.rb+++ b/app/models/work_package/pdf_export/export/wp/attributes.rb@@ -241,8 +241,13 @@ module WorkPackage::PDFExport::Export::Wp::Attributes]end+ def get_link_cell(custom_url)+ make_link_href_cell(custom_url.href, custom_url.href)+ end+def get_column_value_cell(work_package, column_name)value = get_column_value(work_package, column_name)+ return get_link_cell(value) if value.is_a?(::Exports::Formatters::LinkFormatter)return get_id_column_cell(work_package, value) if column_name == :idreturn get_subject_column_cell(work_package, value) if column_name == :subjectdiff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rbindex 386df9a46e3..c0487b9a1c4 100644--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb@@ -47,6 +47,9 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doshared_let(:text_custom_field_b) docreate(:issue_custom_field, :text, types: [type_standard, type_bug], name: "Notes B")end+ shared_let(:link_custom_field) do+ create(:link_wp_custom_field, :link, types: [type_standard, type_bug], name: "My Link")+ endshared_let(:custom_value_first) docreate(:work_package_custom_value,custom_field: list_custom_field,@@ -57,7 +60,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf docreate(:project,name: "Foo Bla. Report No. 4/2021 with/for Case 42",types:,- work_package_custom_fields: [list_custom_field, text_custom_field_a, text_custom_field_b])+ work_package_custom_fields: [list_custom_field, text_custom_field_a, text_custom_field_b, link_custom_field])endshared_let(:user) docreate(:user,@@ -83,7 +86,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dolist_custom_field.attribute_name => [list_custom_field.value_of("Foo"),list_custom_field.value_of("Bar")- ])+ ],+ link_custom_field.attribute_name => "https://example.com")endshared_let(:work_package_child) docreate(:work_package,@@ -98,7 +102,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dodescription: "This is work package 2",text_custom_field_a.attribute_name => "Rich text 2.A",text_custom_field_b.attribute_name => "Rich text 2.B",- list_custom_field.attribute_name => list_custom_field.value_of("Foo"))+ list_custom_field.attribute_name => list_custom_field.value_of("Foo"),+ link_custom_field.attribute_name => "https://example.com")endlet(:query_attributes) { {} }let!(:query) do@@ -118,7 +123,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doexport.export!endend- let(:column_names) { %w[id subject status story_points done_ratio] }+ let(:column_names) { %W[id subject status story_points done_ratio #{link_custom_field.column_name}] }def work_packages_sumwork_package_parent.story_points + work_package_child.story_points@@ -130,7 +135,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dowork_package.subject,work_package.status.name,work_package.story_points.to_s,- work_package_done_ratio(work_package)+ work_package_done_ratio(work_package),+ "https://example.com"]end@@ -144,7 +150,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf docolumn_title(:id), work_package.id.to_s,column_title(:status), work_package.status.name,column_title(:story_points), work_package.story_points.to_s,- column_title(:done_ratio), work_package_done_ratio(work_package)+ column_title(:done_ratio), work_package_done_ratio(work_package),+ "My Link", "https://example.com"]ltfs.each do |ltf|case ltf@@ -347,49 +354,54 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doendend- describe "grouped with sums" do- let(:query_attributes) { { display_sums: true, group_by: "type" } }+ describe "grouped" do+ let(:long_text_fields) { [] }+ let(:options) { { pdf_export_type: "report", long_text_fields: "" } }- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_parent.subject,- "2.", "2", work_package_child.subject,- "1/2", export_date_formatted, query.name,- I18n.t("js.work_packages.tabs.overview"),- column_title(:type), column_title(:story_points), column_title(:done_ratio),- work_package_parent.type.name, work_package_parent.story_points.to_s, "25%",- work_package_child.type.name, work_package_child.story_points.to_s, "50%",- I18n.t("js.label_sum"), work_packages_sum.to_s, "38%",- *work_package_details(work_package_parent, "1", long_text_fields),- *work_package_details(work_package_child, "2", long_text_fields),- "2/2", export_date_formatted, query.name- ].join(" ")+ describe "by type with sums" do+ let(:query_attributes) { { display_sums: true, group_by: "type" } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_date_formatted, query.name,+ I18n.t("js.work_packages.tabs.overview"),+ column_title(:type), column_title(:story_points), column_title(:done_ratio),+ work_package_parent.type.name, work_package_parent.story_points.to_s, "25%",+ work_package_child.type.name, work_package_child.story_points.to_s, "50%",+ I18n.t("js.label_sum"), work_packages_sum.to_s, "38%",+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_date_formatted, query.name+ ].join(" ")+ endend- end-- describe "grouped by a custom field with sums" do- let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_child.subject,- "2.", "2", work_package_parent.subject,- "1/2", export_date_formatted, query.name,- I18n.t("js.work_packages.tabs.overview"),- list_custom_field.name, column_title(:story_points), column_title(:done_ratio),- "Foo", work_package_child.story_points.to_s, "50%",- "Foo, Bar", work_package_parent.story_points.to_s, "25%",- I18n.t("js.label_sum"), work_packages_sum.to_s, "38%",-- *work_package_details(work_package_child, "1", long_text_fields),- *work_package_details(work_package_parent, "2", long_text_fields),- "2/2", export_date_formatted, query.name- ].join(" ")+ describe "by a custom field with sums" do+ let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_child.subject,+ "2.", "2", work_package_parent.subject,+ "1/2", export_date_formatted, query.name,+ I18n.t("js.work_packages.tabs.overview"),+ list_custom_field.name, column_title(:story_points), column_title(:done_ratio),++ "Foo", work_package_child.story_points.to_s, "50%",+ "Foo, Bar", work_package_parent.story_points.to_s, "25%",+ I18n.t("js.label_sum"), work_packages_sum.to_s, "38%",++ *work_package_details(work_package_child, "1", long_text_fields),+ *work_package_details(work_package_parent, "2", long_text_fields),+ "2/2", export_date_formatted, query.name+ ].join(" ")+ endendendenddiff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rbindex 1f1c9ba2060..8568612fe5e 100644--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb@@ -34,7 +34,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doinclude Redmine::I18ninclude PDFExportSpecUtilslet(:type) do- create(:type_bug, custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool])+ create(:type_bug,+ custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool, cf_link])endlet(:parent_project) docreate(:project, name: "Parent project")@@ -65,10 +66,10 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doproject_custom_field_bool.id => true,project_custom_field_long_text.id => "foo"},- work_package_custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool],+ work_package_custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool, cf_link],# cf_disabled_in_project.id not included == disabled- work_package_custom_field_ids: [cf_long_text.id, cf_empty_long_text.id, cf_global_bool.id])+ work_package_custom_field_ids: [cf_long_text.id, cf_empty_long_text.id, cf_global_bool.id, cf_link.id])endlet(:forbidden_project) docreate(:project,@@ -80,10 +81,10 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dostatus_code: "on_track",active: true,parent: parent_project,- work_package_custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool],+ work_package_custom_fields: [cf_long_text, cf_empty_long_text, cf_disabled_in_project, cf_global_bool, cf_link],# cf_disabled_in_project.id not included == disabled- work_package_custom_field_ids: [cf_long_text.id, cf_empty_long_text.id, cf_global_bool.id])+ work_package_custom_field_ids: [cf_long_text.id, cf_empty_long_text.id, cf_global_bool.id, cf_link.id])endlet(:user) docreate(:user,@@ -107,6 +108,9 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf dolet(:cf_long_text) docreate(:issue_custom_field, :text, name: "Work Package Custom Field Long Text")end+ let(:cf_link) do+ create(:link_wp_custom_field, :link, name: "My Link")+ endlet(:cf_empty_long_text) docreate(:issue_custom_field, :text, name: "Empty Work Package Custom Field Long Text")end@@ -169,7 +173,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf docf_long_text.id => cf_long_text_description,cf_empty_long_text.id => cf_empty_long_text_description,cf_disabled_in_project.id => "6.25",- cf_global_bool.id => true+ cf_global_bool.id => true,+ cf_link.id => "https://example.com"}).tap do |wp|allow(wp).to receive(:attachments)@@ -230,9 +235,10 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do"Project phase","Date", "05/30/2024 - 03/13/2025","Other",- "Work Package Custom Field Boolean", "Yes",- "Empty Work Package Custom Field Long Text","Work Package Custom Field Long Text", "foo faa",+ "Empty Work Package Custom Field Long Text",+ "Work Package Custom Field Boolean", "Yes",+ "My Link", "https://example.com","Costs","Spent units", "Labor costs", "Unit costs", "Overall costs", "Budget"]@@ -339,6 +345,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do<tr><td>Custom field rich text</td><td>workPackageValue:1:"#{cf_long_text.name}"</td></tr>+ <tr><td>My link in table</td><td>workPackageValue:"#{cf_link.name}"</td></tr><tr><td>No replacement of:</td><td><code>workPackageValue:1:assignee</code><code>workPackageLabel:assignee</code>@@ -352,6 +359,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doworkPackageLabel:assignee```+ workPackageValue:"My Link"+Work package not found:workPackageValue:1234567890:assigneeAccess denied:@@ -359,6 +368,24 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doDESCRIPTIONend+ def expected_description+ [+ "Custom field boolean", I18n.t(:general_text_Yes),+ "Custom field rich text", "[#{I18n.t('export.macro.rich_text_unsupported')}]",+ "My link in table", "https://example.com",+ "No replacement of:", "workPackageValue:1:assignee", " ", "workPackageLabel:assignee",+ "workPackageValue:2:assignee workPackageLabel:assignee",+ "workPackageValue:3:assignee", "workPackageLabel:assignee",+ "https://example.com",+ "Work package not found: ",+ "[#{I18n.t('export.macro.error', message:+ I18n.t('export.macro.resource_not_found', resource: 'WorkPackage 1234567890'))}] ",+ "Access denied: ",+ "[#{I18n.t('export.macro.error', message:+ I18n.t('export.macro.resource_not_found', resource: "WorkPackage #{forbidden_work_package.id}"))}]",+ ]+ end+it "contains resolved attributes and labels" do# Joining with space for comparison since word wrapping leads to a different array for the same contentresult = pdf[:strings].join(" ")@@ -372,17 +399,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doAPI::Utilities::PropertyNameConverter.to_ar_name(embed[0].to_sym, context: work_package)), embed[1]]end,- "Custom field boolean", I18n.t(:general_text_Yes),- "Custom field rich text", "[#{I18n.t('export.macro.rich_text_unsupported')}]",- "No replacement of:", "workPackageValue:1:assignee", " ", "workPackageLabel:assignee",- "workPackageValue:2:assignee workPackageLabel:assignee",- "workPackageValue:3:assignee", "workPackageLabel:assignee",- "Work package not found: ",- "[#{I18n.t('export.macro.error', message:- I18n.t('export.macro.resource_not_found', resource: 'WorkPackage 1234567890'))}] ",- "Access denied: ",- "[#{I18n.t('export.macro.error', message:- I18n.t('export.macro.resource_not_found', resource: "WorkPackage #{forbidden_work_package.id}"))}]",+ *expected_description,"2", export_date_formatted, project.name].flatten.join(" ")expect(result).to eq(expected_result)diff --git a/spec/support/work_packages/pdf_export.rb b/spec/support/work_packages/pdf_export.rbindex dbc06880c94..407bb80721b 100644--- a/spec/support/work_packages/pdf_export.rb+++ b/spec/support/work_packages/pdf_export.rb@@ -9,6 +9,10 @@ module PDFExportSpecUtilsenddef label_title(column_name)+ if column_name.start_with?("cf_")+ id = column_name.delete_prefix("cf_").to_i+ return ::CustomField.find_by(id:).name+ endWorkPackage.human_attribute_name(column_name)endend