Commit 204ab7c9 authored by Jan Provaznik's avatar Jan Provaznik

Fix issuable state indicator

Now the issuable reference check works only in project scope, if we
reference an issuable from a non-project resource (e.g. epics), then
project is not set, and there is mismatch in generated issue references.

This patch enables issuable reference state check also from group scope.

Closes gitlab-ee#4683
Related to #30916
parent 453b5c1c
Pipeline #19368408 passed with stages
in 22 minutes and 32 seconds
---
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')
......
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