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

Adjust error messages

Dombi Attilad4636bc2d72c
diff --git a/app/contracts/relations/base_contract.rb b/app/contracts/relations/base_contract.rb
index eaf0ebbe408..82c4d5edc2e 100644
--- a/app/contracts/relations/base_contract.rb
+++ b/app/contracts/relations/base_contract.rb
@@ -39,7 +39,6 @@ module Relations
validate :validate_to_exists
validate :validate_nodes_relatable
validate :validate_accepted_type
- validate :validate_lag_numericality
def self.model
Relation
@@ -74,16 +73,6 @@ module Relations
end
end
- def validate_lag_numericality
- if model.lag.present?
- if model.lag < 0
- errors.add :lag, I18n.t(:"activerecord.errors.messages.circular_dependency")
- elsif model.lag > 2_147_483_647
- errors.add :lag, I18n.t(:"activerecord.errors.models.relation.attributes.lag.high_value")
- end
- end
- end
-
def visible_work_packages
::WorkPackage.visible(user)
end
diff --git a/app/models/relation.rb b/app/models/relation.rb
index eb56291542f..fd56d0af358 100644
--- a/app/models/relation.rb
+++ b/app/models/relation.rb
@@ -106,14 +106,7 @@ class Relation < ApplicationRecord
validates :lag, numericality: {
allow_nil: true,
less_than_or_equal_to: 2_147_483_647,
- greater_than_or_equal_to: 0,
- message: ->(_, data) {
- if data[:value] < 0
- I18n.t("activerecord.errors.models.relation.attributes.lag.negative_value")
- else
- I18n.t("activerecord.errors.models.relation.attributes.lag.high_value")
- end
- }
+ greater_than_or_equal_to: 0
}
validates :to, uniqueness: { scope: :from }
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a99cb348827..e075a6954ea 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1308,8 +1308,9 @@ en:
error_not_found: "work package in `from` position not found or not visible"
error_readonly: "an existing relation's `from` link is immutable"
lag:
- high_value: "The value for lag is too high."
- negative_value: "Lag cannot be negative."
+ greater_than_or_equal_to:
+ zero: "cannot be negative."
+ less_than_or_equal_to: "is too high."
repository:
not_available: "SCM vendor is not available"
not_whitelisted: "is not allowed by the configuration."
diff --git a/spec/models/relation_spec.rb b/spec/models/relation_spec.rb
index 32252836b1e..d76a0a311ef 100644
--- a/spec/models/relation_spec.rb
+++ b/spec/models/relation_spec.rb
@@ -38,11 +38,12 @@ RSpec.describe Relation do
it "validates lag numericality" do
relation.lag = -1
expect(relation).not_to be_valid
- expect(relation.errors[:lag]).to include(I18n.t(:"activerecord.errors.models.relation.attributes.lag.negative_value"))
+ expect(relation.errors[:lag])
+ .to include(I18n.t(:"activerecord.errors.models.relation.attributes.lag.greater_than_or_equal_to.zero"))
relation.lag = 2_147_483_648
expect(relation).not_to be_valid
- expect(relation.errors[:lag]).to include(I18n.t(:"activerecord.errors.models.relation.attributes.lag.high_value"))
+ expect(relation.errors[:lag]).to include(I18n.t(:"activerecord.errors.models.relation.attributes.lag.less_than_or_equal_to"))
relation.lag = 1_000
expect(relation).to be_valid