Commit 9b2450ca authored by Jan Provaznik's avatar Jan Provaznik

Use specific has_many relation

Adds has_many relation to get blocking issues.
parent 45762399
......@@ -7,7 +7,7 @@ module EE
override :associations_to_preload
def associations_to_preload
super << { target_issue_links: { source: { project: :project_feature } } }
super << { blocked_by_issues: { project: :project_feature } }
end
end
end
......
......@@ -42,7 +42,8 @@ module EE
has_many :vulnerability_links, class_name: 'Vulnerabilities::IssueLink', inverse_of: :issue
has_many :related_vulnerabilities, through: :vulnerability_links, source: :vulnerability
has_many :target_issue_links, class_name: 'IssueLink', foreign_key: :target_id
has_many :blocked_by_issue_links, -> { where(link_type: IssueLink::TYPE_BLOCKS) }, class_name: 'IssueLink', foreign_key: :target_id
has_many :blocked_by_issues, through: :blocked_by_issue_links, source: :source
validates :weight, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
......
......@@ -7,7 +7,7 @@ module EE
prepended do
expose :weight, if: ->(issue, _) { issue.supports_weight? }
expose :blocked do |issue|
issue.target_issue_links.any? { |link| link.link_type == IssueLink::TYPE_BLOCKS && can?(request.current_user, :read_issue, link.source) }
issue.blocked_by_issues.any? { |blocked_by_issue| can?(request.current_user, :read_issue, blocked_by_issue) }
end
end
end
......
......@@ -127,6 +127,8 @@ describe Issue do
it { is_expected.to have_many(:related_vulnerabilities).through(:vulnerability_links).source(:vulnerability) }
it { is_expected.to belong_to(:promoted_to_epic).class_name('Epic') }
it { is_expected.to have_many(:resource_weight_events) }
it { is_expected.to have_many(:blocked_by_issue_links) }
it { is_expected.to have_many(:blocked_by_issues).through(:blocked_by_issue_links).source(:source) }
describe 'versions.most_recent' do
it 'returns the most recent version' do
......
......@@ -38,7 +38,8 @@ issues:
- vulnerability_links
- related_vulnerabilities
- user_mentions
- target_issue_links
- blocked_by_issue_links
- blocked_by_issues
events:
- author
- project
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment