Commit 94d9e719 authored by Alex Kalderimis's avatar Alex Kalderimis

Allow issue reference filter to recognize design tab links

This inspects the path group (if available) to see if it matches
the known `/designs` subpath.
parent ade11b30
# frozen_string_literal: true
module EE
module Banzai
module Filter
module IssueReferenceFilter
extend ActiveSupport::Concern
prepended do
extend ::Gitlab::Utils::Override
override :object_link_text_extras
def object_link_text_extras(issue, matches)
super + design_link_extras(issue, matches.names.include?('path') && matches[:path])
end
private
def design_link_extras(issue, path)
if path == '/designs' && read_designs?(issue)
['designs']
else
[]
end
end
def read_designs?(issue)
Ability.allowed?(current_user, :read_design, issue)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Banzai::Filter::IssueReferenceFilter do
include FilterSpecHelper
include DesignManagementTestHelpers
describe '#object_link_text_extras' do
before do
enable_design_management(enabled)
end
let(:enabled) { true }
let_it_be(:issue) { create(:issue) }
let(:project) { issue.project }
let(:matches) { ::Issue.link_reference_pattern.match(input_text) }
let(:current_user) { project.owner }
let(:extras) { subject.object_link_text_extras(issue, matches) }
subject do
render_context = Banzai::RenderContext.new(project, current_user)
context = { project: project, current_user: current_user, render_context: render_context }
described_class.new(input_text, context)
end
context 'the link does not go to the designs tab' do
let(:input_text) { Gitlab::Routing.url_helpers.project_issue_url(issue.project, issue) }
it 'does not include designs' do
expect(extras).not_to include('designs')
end
end
context 'the link goes to the designs tab' do
let(:input_text) { url_for_designs(issue) }
it 'includes designs' do
expect(extras).to include('designs')
end
context 'design management is disabled' do
let(:enabled) { false }
it 'does not include designs in the extras' do
expect(extras).not_to include('designs')
end
end
end
end
end
......@@ -29,6 +29,10 @@ module DesignManagementTestHelpers
Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options)
end
def url_for_designs(issue)
Gitlab::Routing.url_helpers.designs_project_issue_url(issue.project, issue)
end
private
def act_on_designs(designs, &block)
......
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