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

obey rubocop

as-opa1ab38967158
diff --git a/app/models/work_package/exports/macros/attributes.rb b/app/models/work_package/exports/macros/attributes.rb
index eb032a68565..b3d5c59df71 100644
--- a/app/models/work_package/exports/macros/attributes.rb
+++ b/app/models/work_package/exports/macros/attributes.rb
@@ -150,20 +150,31 @@ module WorkPackage::Exports
end
def self.resolve_value(obj, attribute, disabled_rich_text_fields)
- cf = obj.available_custom_fields.find { |pcf| pcf.name == attribute }
+ custom_field = find_custom_field(obj, attribute)
+ return msg_macro_error_rich_text if custom_field&.formattable?
- return msg_macro_error_rich_text if cf&.formattable?
+ attribute_name = convert_to_attribute_name(custom_field, attribute, obj)
+ return "" unless can_view_attribute?(custom_field, obj, attribute_name)
+ return msg_macro_error_rich_text if disabled_rich_text_fields.include?(attribute_name.to_sym)
- ar_name = if cf.nil?
- ::API::Utilities::PropertyNameConverter.to_ar_name(attribute.to_sym, context: obj)
- else
- "cf_#{cf.id}"
- end
+ format_attribute_value(attribute_name, obj.class, obj)
+ end
+
+
+ def self.can_view_attribute?(custom_field, obj, attribute_name)
+ !(custom_field.nil? && !user_allowed_view_attribute?(obj, attribute_name))
+ end
- return "" if cf.nil? && !user_allowed_view_attribute?(obj, ar_name)
- return msg_macro_error_rich_text if disabled_rich_text_fields.include?(ar_name.to_sym)
+ def self.convert_to_attribute_name(custom_field, attribute, obj)
+ if custom_field.nil?
+ ::API::Utilities::PropertyNameConverter.to_ar_name(attribute.to_sym, context: obj)
+ else
+ "cf_#{custom_field.id}"
+ end
+ end
- format_attribute_value(ar_name, obj.class, obj)
+ def self.find_custom_field(obj, attribute)
+ obj.available_custom_fields.find { |pcf| pcf.name == attribute }
end
def self.format_attribute_value(ar_name, model, obj)
diff --git a/app/models/work_package/pdf_export/export/wp/attributes.rb b/app/models/work_package/pdf_export/export/wp/attributes.rb
index 86d0f4887b4..1253d5e6ba9 100644
--- a/app/models/work_package/pdf_export/export/wp/attributes.rb
+++ b/app/models/work_package/pdf_export/export/wp/attributes.rb
@@ -140,9 +140,7 @@ module WorkPackage::PDFExport::Export::Wp::Attributes
current_part = { type: :attribute, list: [] }
parts = [current_part]
group.attributes.each do |form_key|
- if !CustomField.custom_field_attribute?(form_key) && !user_allowed_view_attribute?(work_package, form_key)
- next
- end
+ next if skip_attribute?(form_key, work_package)
if allowed_long_text_custom_field?(form_key, work_package)
cf = form_key_to_custom_field(form_key)
@@ -162,6 +160,10 @@ module WorkPackage::PDFExport::Export::Wp::Attributes
parts
end
+ def skip_attribute?(form_key, work_package)
+ !CustomField.custom_field_attribute?(form_key) && !user_allowed_view_attribute?(work_package, form_key)
+ end
+
def allowed_long_text_custom_field?(form_key, work_package)
return false unless CustomField.custom_field_attribute? form_key