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
[#66093] API returns calculated value errors
Tobias Dillmann9ee1a6eb4ef5
diff --git a/docs/api/apiv3/example/README.md b/docs/api/apiv3/example/README.mdindex 7aab5e7fe4e..0d689b5af92 100644--- a/docs/api/apiv3/example/README.md+++ b/docs/api/apiv3/example/README.md@@ -229,6 +229,24 @@ The schema can instruct the client where to set them properly. All properties wi}```+#### Custom field errors++Custom fields with a field format of `calculated_value` may produce errors during calculation. In such a case, their scalar value is set to `null` and an additional property is returned.+Note that multiple errors may be present in the array. Each error consists of a machine-readable error code and a localized error string intended for humans.++If there are no errors, this field is missing.++```json5+{+ "customFieldXerrors": [+ {+ "error_code": "ERROR_MATHEMATICAL",+ "error_message": "A mathematical error occurred during calculation. Please review the formula and try again."+ }+ ]+}+```+## Filtering work packagesOnce a work package is created, it can also be retrieved again.diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rbindex cd6cb8a85a0..38e350db3c2 100644--- a/lib/api/v3/utilities/custom_field_injector.rb+++ b/lib/api/v3/utilities/custom_field_injector.rb@@ -269,15 +269,19 @@ module APIenddef inject_property_value(custom_field, config)- # TODO: inject calculated value error message somewhere around here as a sibling of this property.- # customField20Errors: [{ error_code: "MISSING_VALUE", error_message: "message"}, {...}]-@class.property custom_field.attribute_name.to_sym,as: property_name(custom_field),getter: property_value_getter_for(custom_field),setter: property_value_setter_for(custom_field),cache_if: config[:cache_if],render_nil: true++ if custom_field.calculated_value?+ @class.property :"#{custom_field.attribute_name}errors",+ getter: calculated_value_error_getter(custom_field),+ cache_if: config[:cache_if],+ render_nil: false+ endenddef property_value_getter_for(custom_field)@@ -305,6 +309,18 @@ module API}end+ def calculated_value_error_getter(custom_field)+ ->(*) {+ next unless custom_field.calculated_value?+ next unless available_custom_fields.include?(custom_field)++ errors = custom_field.calculated_value_errors.where(project_id: id)+ errors.map do |err|+ { error_code: err.error_code, error_message: err.error_message }+ end+ }+ end+def allowed_users_href_callbackstatic_filters = allowed_users_static_filtersinstance_filters = method(:allowed_users_instance_filter)