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

[#64530] API renders formula for calculated values

Tobias Dillmannceee1e83823b
diff --git a/docs/api/apiv3/tags/schemas.yml b/docs/api/apiv3/tags/schemas.yml
index b42c134a3e9..ef1de2cb830 100644
--- a/docs/api/apiv3/tags/schemas.yml
+++ b/docs/api/apiv3/tags/schemas.yml
@@ -51,6 +51,7 @@ description: |-
| minLength | The value of the property must at least contain the specified amount of characters | Integer | 0 |
| maxLength | The value of the property must at most contain the specified amount of characters | Integer | ∞ |
| regularExpression | The value of the property must match the given regular expression (if not null) | String | null |
+ | formula | If present, contains a formula that is used to calculate the value of the property | String | null |
| location | If present, contains a reference to the location of the property in the JSON | String | null |
| description | If present, contains a formattable, human readable description | Formattable | null |
| deprecated | If present, the client should consider the existence of the property deprecated | Boolean | false |
diff --git a/lib/api/decorators/property_schema_representer.rb b/lib/api/decorators/property_schema_representer.rb
index 22bdd291b78..e6928f2106a 100644
--- a/lib/api/decorators/property_schema_representer.rb
+++ b/lib/api/decorators/property_schema_representer.rb
@@ -69,6 +69,7 @@ module API
:max_length,
:regular_expression,
:options,
+ :formula,
:location,
:description,
:deprecated
@@ -84,6 +85,7 @@ module API
property :regular_expression, exec_context: :decorator
property :deprecated, exec_context: :decorator
property :options, exec_context: :decorator
+ property :formula, exec_context: :decorator, render_nil: false
property :location, exec_context: :decorator
diff --git a/lib/api/decorators/schema_representer.rb b/lib/api/decorators/schema_representer.rb
index 3ab74e36bbd..f1b116cb902 100644
--- a/lib/api/decorators/schema_representer.rb
+++ b/lib/api/decorators/schema_representer.rb
@@ -63,6 +63,7 @@ module API
max_length: nil,
regular_expression: nil,
options: {},
+ formula: nil,
show_if: true,
description: nil,
deprecated: nil)
@@ -77,6 +78,7 @@ module API
max_length,
regular_expression,
options,
+ formula,
location,
description,
deprecated)
@@ -299,6 +301,7 @@ module API
max_length,
regular_expression,
options,
+ formula,
location,
description,
deprecated)
@@ -317,6 +320,7 @@ module API
schema.max_length = max_length
schema.regular_expression = regular_expression
schema.options = options
+ schema.formula = formula
schema
end
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index a44c9942073..8a0d2fcce96 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -45,7 +45,8 @@ module API
"version" => "Version",
"list" => "CustomOption",
"hierarchy" => "CustomField::Hierarchy::Item",
- "scored_list" => "CustomField::Hierarchy::Item"
+ "scored_list" => "CustomField::Hierarchy::Item",
+ "calculated_value" => "CalculatedValue"
}.freeze
LINK_FORMATS = %w(list user version hierarchy scored_list).freeze
@@ -199,7 +200,8 @@ module API
min_length: cf_min_length(custom_field),
max_length: cf_max_length(custom_field),
regular_expression: cf_regexp(custom_field),
- options: cf_options(custom_field)
+ options: cf_options(custom_field),
+ formula: cf_formula(custom_field)
end
def inject_link_value(custom_field, config)
@@ -326,6 +328,12 @@ module API
custom_field.regexp.presence
end
+ def cf_formula(custom_field)
+ if custom_field.field_format_calculated_value?
+ custom_field.formula_string
+ end
+ end
+
def cf_options(custom_field)
{
rtl: ("true" if custom_field.content_right_to_left)