summaryrefslogtreecommitdiffstats
path: root/app/models/issue_relation.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-01-10 15:12:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-01-10 15:12:28 +0000
commit3a48f09d4f11b0da737007900c16d7fd95eee767 (patch)
tree07dda0716f05895bf863b305ad8b139da4407922 /app/models/issue_relation.rb
parent5e6cf80401cd2a97b6aec4732ce3ec3e276cb1be (diff)
downloadredmine-3a48f09d4f11b0da737007900c16d7fd95eee767.tar.gz
redmine-3a48f09d4f11b0da737007900c16d7fd95eee767.zip
Can't set parent issue when issue relations among child issues are present (#13654).
git-svn-id: http://svn.redmine.org/redmine/trunk@15056 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_relation.rb')
-rw-r--r--app/models/issue_relation.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
index 9df4e2b71..3e7e4235c 100644
--- a/app/models/issue_relation.rb
+++ b/app/models/issue_relation.rb
@@ -101,11 +101,8 @@ class IssueRelation < ActiveRecord::Base
Setting.cross_project_issue_relations?
errors.add :issue_to_id, :not_same_project
end
- # detect circular dependencies depending wether the relation should be reversed
- if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
- errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to
- else
- errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from
+ if circular_dependency?
+ errors.add :base, :circular_dependency
end
if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
errors.add :base, :cant_link_an_issue_with_a_descendant
@@ -197,6 +194,22 @@ class IssueRelation < ActiveRecord::Base
end
end
+ # Returns true if the relation would create a circular dependency
+ def circular_dependency?
+ case relation_type
+ when 'follows'
+ issue_from.would_reschedule? issue_to
+ when 'precedes'
+ issue_to.would_reschedule? issue_from
+ when 'blocked'
+ issue_from.blocks? issue_to
+ when 'blocks'
+ issue_to.blocks? issue_from
+ else
+ false
+ end
+ end
+
def call_issues_relation_added_callback
call_issues_callback :relation_added
end