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

[#64348] Avoid circular reference, only offer visible fields

Tobias Dillmann45f7bb19d7c8
diff --git a/app/forms/custom_fields/calculated_values/details_form.rb b/app/forms/custom_fields/calculated_values/details_form.rb
index 0b4c886e92a..e565ed10c7a 100644
--- a/app/forms/custom_fields/calculated_values/details_form.rb
+++ b/app/forms/custom_fields/calculated_values/details_form.rb
@@ -84,9 +84,7 @@ module CustomFields
# in too much visual clutter. We still want to offer autocompletion for them.
operators = CustomField::CalculatedValue::OPERATORS.map { |op| { key: op, label: op, insert_as_text: true } }
- custom_fields = ProjectCustomField
- .where(field_format: CustomField::CalculatedValue::FIELD_FORMATS_FOR_FORMULA)
- .map do |cf|
+ custom_fields = model.usable_custom_field_references_for_formula.map do |cf|
{ key: "cf_#{cf.id}", label: cf.name }
end
diff --git a/app/models/custom_field/calculated_value.rb b/app/models/custom_field/calculated_value.rb
index b2480a17834..8182a2f6ba2 100644
--- a/app/models/custom_field/calculated_value.rb
+++ b/app/models/custom_field/calculated_value.rb
@@ -81,6 +81,16 @@ module CustomField::CalculatedValue
formula ? formula.fetch("formula", "") : ""
end
+ def usable_custom_field_references_for_formula
+ scope = type == "ProjectCustomField" ? ProjectCustomField : CustomField
+
+ scope
+ .where(field_format: FIELD_FORMATS_FOR_FORMULA)
+ # Disallow the current custom field to avoid circular references
+ .where.not(id: id)
+ .visible
+ end
+
private
def perform_calculation