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
Avoid const_get for filters in cost reports
Oliver Güntherd92810ad5e22
diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rbindex 2884f4d0eae..e2c5a6eecde 100644--- a/modules/reporting/app/controllers/cost_reports_controller.rb+++ b/modules/reporting/app/controllers/cost_reports_controller.rb@@ -188,7 +188,7 @@ class CostReportsController < ApplicationControllerreturn unless name- f_cls = report_engine::Filter.const_get(name.to_s.camelcase)+ f_cls = get_filter_class(name)filter = f_cls.new.tap do |f|f.values = JSON.parse(params[:values].gsub("'", '"')) if params[:values].present? && params[:values]end@@ -397,6 +397,16 @@ class CostReportsController < ApplicationController@current_user = User.current || User.anonymousend+ def get_filter_class(name)+ filter = report_engine::Filter+ .all+ .detect { |cls| cls.to_s.demodulize.underscore == name.to_s }++ raise ArgumentError.new("Filter with name #{name} does not exist.") unless filter++ filter+ end+### Determine the available values for the specified filter and return them as# json, if that was requested. This will be executed INSTEAD of the actual action@@ -417,7 +427,7 @@ class CostReportsController < ApplicationControllervalues = values.map { |value| value.nil? ? [::I18n.t(:label_none), '<<null>>'] : value }# try to find corresponding labels to the given valuesvalues = values.map do |value|- filter = report_engine::Filter.const_get(dependent.camelcase.to_sym)+ filter = get_filter_class(dependent)filter_value = filter.label_for_value valueif filter_value && filter_value.first.is_a?(Symbol)[::I18n.t(filter_value.first), filter_value.second]