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] Avoid error duplication via model
Tobias Dillmann7e348621136b
diff --git a/app/models/acts_as_customizable/calculated_value.rb b/app/models/acts_as_customizable/calculated_value.rbindex fc6617e9ff8..2ce6e858eff 100644--- a/app/models/acts_as_customizable/calculated_value.rb+++ b/app/models/acts_as_customizable/calculated_value.rb@@ -102,9 +102,7 @@ module ActsAsCustomizable::CalculatedValueenddef create_calculated_value_error(custom_field_id, error_code)- unless CalculatedValueError.exists?(project: self, custom_field_id:, error_code:)- CalculatedValueError.create!(project: self, custom_field_id:, error_code:)- end+ CalculatedValueError.create(project: self, custom_field_id:, error_code:)enddef remove_calculated_value_errors(custom_field_ids = [])diff --git a/app/models/calculated_value_error.rb b/app/models/calculated_value_error.rbindex 4c0515c246d..493ba9041c9 100644--- a/app/models/calculated_value_error.rb+++ b/app/models/calculated_value_error.rb@@ -43,6 +43,9 @@ class CalculatedValueError < ApplicationRecordvalidates :error_code, inclusion: { in: VALID_ERROR_CODES }+ # It makes no sense to have the exact same error multiple times.+ validates :project_id, uniqueness: { scope: %i[custom_field_id error_code] }+def error_messagetranslation_key = ERROR_TRANSLATIONS.fetch(error_code, "calculated_values.errors.unknown")