Merge branch 'jprovazn-issueref' into 'master'
Fix issuable state indicator Closes gitlab-ee#4683 See merge request gitlab-org/gitlab-ce!17878
This commit is contained in:
commit
f56ef20657
3 changed files with 23 additions and 1 deletions
6
changelogs/unreleased/jprovazn-issueref.yml
Normal file
6
changelogs/unreleased/jprovazn-issueref.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Display state indicator for issuable references in non-project scope (e.g.
|
||||
when referencing issuables from group scope).
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -17,7 +17,7 @@ module Banzai
|
|||
issuables.each do |node, issuable|
|
||||
next if !can_read_cross_project? && issuable.project != project
|
||||
|
||||
if VISIBLE_STATES.include?(issuable.state) && node.inner_html == issuable.reference_link_text(project)
|
||||
if VISIBLE_STATES.include?(issuable.state) && issuable_reference?(node.inner_html, issuable)
|
||||
node.content += " (#{issuable.state})"
|
||||
end
|
||||
end
|
||||
|
@ -27,6 +27,10 @@ module Banzai
|
|||
|
||||
private
|
||||
|
||||
def issuable_reference?(text, issuable)
|
||||
text == issuable.reference_link_text(project || group)
|
||||
end
|
||||
|
||||
def can_read_cross_project?
|
||||
Ability.allowed?(current_user, :read_cross_project)
|
||||
end
|
||||
|
@ -38,6 +42,10 @@ module Banzai
|
|||
def project
|
||||
context[:project]
|
||||
end
|
||||
|
||||
def group
|
||||
context[:group]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ describe Banzai::Filter::IssuableStateFilter do
|
|||
let(:context) { { current_user: user, issuable_state_filter_enabled: true } }
|
||||
let(:closed_issue) { create_issue(:closed) }
|
||||
let(:project) { create(:project, :public) }
|
||||
let(:group) { create(:group) }
|
||||
let(:other_project) { create(:project, :public) }
|
||||
|
||||
def create_link(text, data)
|
||||
|
@ -77,6 +78,13 @@ describe Banzai::Filter::IssuableStateFilter do
|
|||
expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)")
|
||||
end
|
||||
|
||||
it 'handles references from group scopes' do
|
||||
link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: 'issue')
|
||||
doc = filter(link, context.merge(project: nil, group: group))
|
||||
|
||||
expect(doc.css('a').last.text).to eq("#{closed_issue.to_reference(other_project)} (closed)")
|
||||
end
|
||||
|
||||
it 'skips cross project references if the user cannot read cross project' do
|
||||
expect(Ability).to receive(:allowed?).with(user, :read_cross_project) { false }
|
||||
link = create_link(closed_issue.to_reference(other_project), issue: closed_issue.id, reference_type: 'issue')
|
||||
|
|
Loading…
Reference in a new issue