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
[#60585] PDF Gantt export potentially exports huge date ranges
as-op802f06a0f1e6
diff --git a/app/models/exports/pdf/components/gantt/gantt_builder.rb b/app/models/exports/pdf/components/gantt/gantt_builder.rbindex 039837e448f..a8fc2de2a26 100644--- a/app/models/exports/pdf/components/gantt/gantt_builder.rb+++ b/app/models/exports/pdf/components/gantt/gantt_builder.rb@@ -29,8 +29,11 @@#++module Exports::PDF::Components::Gantt+ class InvalidDateRangeError < StandardError; end+class GanttBuilderinclude Redmine::I18n+BAR_CELL_PADDING = 5.to_fTEXT_CELL_PADDING_H = 3.to_fTEXT_CELL_PADDING_V = 1.to_f@@ -39,6 +42,7 @@ module Exports::PDF::Components::GanttDEFAULT_TEXT_COLUMN_DIVIDER = 4TEXT_COLUMN_MAX_WIDTH = 250.to_fLINE_STEP = 5.to_f+ MAX_YEAR_RANGE = 10def initialize(pdf, title, column_width)@pdf = pdf@@ -843,6 +847,11 @@ module Exports::PDF::Components::Gantt# @return [Array<Date>]def collect_column_dates(work_packages)wp_dates = collect_work_packages_dates(work_packages)+ years = ((wp_dates.last - wp_dates.first) / 365).floor+ if years > MAX_YEAR_RANGE+ raise InvalidDateRangeError, I18n.t(:error_pdf_date_range_too_long, years: MAX_YEAR_RANGE)+ end+build_column_dates_range(wp_dates.first..wp_dates.last)enddiff --git a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb b/app/models/work_package/pdf_export/work_package_list_to_pdf.rbindex cc727755572..0d6fab6f733 100644--- a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb+++ b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb@@ -87,6 +87,8 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Querysuccess(file)rescue Prawn::Errors::CannotFiterror(I18n.t(:error_pdf_export_too_many_columns))+ rescue Exports::PDF::Components::Gantt::InvalidDateRangeError => e+ error(e.message)rescue StandardError => eRails.logger.error "Failed to generate PDF export: #{e.message}:\n#{e.backtrace.join("\n")}"error(I18n.t(:error_pdf_failed_to_export, error: e.message))diff --git a/config/locales/en.yml b/config/locales/en.ymlindex a17e1c17a8b..b0b3dd129d9 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2463,6 +2463,7 @@ en:error_invalid_selected_value: "Invalid selected value."error_journal_attribute_not_present: "Journal does not contain attribute %{attribute}."error_pdf_export_too_many_columns: "Too many columns selected for the PDF export. Please reduce the number of columns."+ error_pdf_date_range_too_long: "The selected work package date range exceeds the allowable limit for PDF export. Please condense the range to a maximum of %{years} years."error_pdf_failed_to_export: "The PDF export could not be saved: %{error}"error_token_authenticity: "Unable to verify Cross-Site Request Forgery token. Did you try to submit data on multiple browsers or tabs? Please close all tabs and try again."error_reminder_not_found: "The reminder was not found or was already notified about."