From 204ab7c9f88e19eea96ff64e39ae81cdcb83bada Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 20 Mar 2018 09:29:15 +0100 Subject: [PATCH] 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 --- changelogs/unreleased/jprovazn-issueref.yml | 6 ++++++ lib/banzai/filter/issuable_state_filter.rb | 10 +++++++++- spec/lib/banzai/filter/issuable_state_filter_spec.rb | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/jprovazn-issueref.yml diff --git a/changelogs/unreleased/jprovazn-issueref.yml b/changelogs/unreleased/jprovazn-issueref.yml new file mode 100644 index 00000000000..ee19cac7b19 --- /dev/null +++ b/changelogs/unreleased/jprovazn-issueref.yml @@ -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 diff --git a/lib/banzai/filter/issuable_state_filter.rb b/lib/banzai/filter/issuable_state_filter.rb index 77299abe324..8f541dcfdb2 100644 --- a/lib/banzai/filter/issuable_state_filter.rb +++ b/lib/banzai/filter/issuable_state_filter.rb @@ -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 diff --git a/spec/lib/banzai/filter/issuable_state_filter_spec.rb b/spec/lib/banzai/filter/issuable_state_filter_spec.rb index 17347768a49..a5373517ac8 100644 --- a/spec/lib/banzai/filter/issuable_state_filter_spec.rb +++ b/spec/lib/banzai/filter/issuable_state_filter_spec.rb @@ -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')