diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/models/issue_link.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/models/issue_link.rb')
-rw-r--r-- | app/models/issue_link.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/issue_link.rb b/app/models/issue_link.rb index 9740b009396..5448ebdf50b 100644 --- a/app/models/issue_link.rb +++ b/app/models/issue_link.rb @@ -10,6 +10,7 @@ class IssueLink < ApplicationRecord validates :target, presence: true validates :source, uniqueness: { scope: :target_id, message: 'is already related' } validate :check_self_relation + validate :check_opposite_relation scope :for_source_issue, ->(issue) { where(source_id: issue.id) } scope :for_target_issue, ->(issue) { where(target_id: issue.id) } @@ -33,6 +34,14 @@ class IssueLink < ApplicationRecord errors.add(:source, 'cannot be related to itself') end end + + def check_opposite_relation + return unless source && target + + if IssueLink.find_by(source: target, target: source) + errors.add(:source, 'is already related to this issue') + end + end end IssueLink.prepend_if_ee('EE::IssueLink') |