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

extract CustomFieldFormat#for_class_name?

Ivan Kuchindb98c7a71b9d
diff --git a/lib/open_project/custom_field_format.rb b/lib/open_project/custom_field_format.rb
index c4c2cafbc67..0c69f8ec27e 100644
--- a/lib/open_project/custom_field_format.rb
+++ b/lib/open_project/custom_field_format.rb
@@ -34,7 +34,7 @@ module OpenProject
class_attribute :registered_by_name, default: {}
- attr_reader :name, :order, :label, :edit_as, :class_names
+ attr_reader :name, :order, :label, :edit_as
def initialize(name,
label:,
@@ -81,6 +81,10 @@ module OpenProject
!@enterprise_feature || EnterpriseToken.allows_to?(@enterprise_feature)
end
+ def for_class_name?(class_name)
+ @class_names.nil? || @class_names.include?(class_name)
+ end
+
class << self
def registered = registered_by_name.values
@@ -109,9 +113,8 @@ module OpenProject
def available_for_class_name(class_name)
available
- .select { |field| field.class_names.nil? || field.class_names.include?(class_name) }
+ .select { |format| format.for_class_name?(class_name) && !format.label.nil? }
.sort_by(&:order)
- .reject { |format| format.label.nil? }
end
def disabled_formats