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

handle validating contract inside contract

ulferts304154552d24
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index 13c03d7d095..6314a653e8c 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -175,6 +175,7 @@ class BaseContract < Disposable::Twin
end
end
+ # TODO: check if this can be removed
# use activerecord as the base scope instead of 'activemodel' to be compatible
# to the messages we have already stored
def self.i18n_scope
diff --git a/app/contracts/projects/base_contract.rb b/app/contracts/projects/base_contract.rb
index 32bee318904..4a6b4550115 100644
--- a/app/contracts/projects/base_contract.rb
+++ b/app/contracts/projects/base_contract.rb
@@ -122,9 +122,11 @@ module Projects
contract_klass = model.being_archived? ? ArchiveContract : UnarchiveContract
contract = contract_klass.new(model, user)
+
+ former_errors = errors.dup
contract.validate
- errors.merge!(contract.errors)
+ errors.merge!(former_errors)
end
end
end
diff --git a/app/contracts/views/base_contract.rb b/app/contracts/views/base_contract.rb
index dacc8e6cd5c..a6a2e0204f9 100644
--- a/app/contracts/views/base_contract.rb
+++ b/app/contracts/views/base_contract.rb
@@ -41,9 +41,11 @@ module Views
# needs to validate additionally. E.g. a contract can have additional permission checks.
if (strategy_class = Constants::Views.contract_strategy(model.type))
strategy = strategy_class.new(model, user)
+
+ former_errors = errors.dup
strategy.valid?
- errors.merge!(strategy.errors)
+ errors.merge!(former_errors)
end
errors.empty?