Skip to content

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

no 404 on AR records not found for xls export

ulfertsfe3559ae5b5c
diff --git a/modules/xls_export/lib/open_project/xls_export/xls_views.rb b/modules/xls_export/lib/open_project/xls_export/xls_views.rb
index 357ccfdd208..56a34517552 100644
--- a/modules/xls_export/lib/open_project/xls_export/xls_views.rb
+++ b/modules/xls_export/lib/open_project/xls_export/xls_views.rb
@@ -67,18 +67,27 @@ class OpenProject::XlsExport::XlsViews
end
def project_representation(value)
- value.to_i.zero? ? I18n.t(:label_none) : Project.find(value.to_i).name
+ ar_presentation(Project, value, &:name)
end
def user_representation(value)
- value.to_i.zero? ? I18n.t(:label_none) : User.find(value.to_i).name
+ ar_presentation(User, value, &:name)
end
def work_package_representation(value)
- return I18n.t(:label_none) if value.to_i.zero?
+ ar_presentation(WorkPackage, value) do |work_package|
+ "#{work_package.type} ##{work_package.id}: #{work_package.subject}"
+ end
+ end
- work_package = WorkPackage.find(value.to_i)
- "#{work_package.project.name + ' - ' if @project}#{work_package.type} ##{work_package.id}: #{work_package.subject}"
+ def ar_presentation(klass, id)
+ record = klass.find_by(id: id.to_i)
+
+ if record
+ yield record
+ else
+ I18n.t(:label_none)
+ end
end
end