Commit d8a0df36 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '12905-b-support-design-tab-link-references' into 'master'

12905b - Support design tab link references

Closes #12905

See merge request gitlab-org/gitlab!22330
parents d611e6d1 4e6482b2
---
title: Support design tab link references for issues
merge_request: 22330
author:
type: added
# 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.named_captures['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
let_it_be(:issue) { create(:issue) }
let_it_be(:project) { issue.project }
let_it_be(:current_user) { project.owner }
let_it_be(:designs_tab_url) { url_for_designs(issue) }
context 'when processing a link to the designs tab' do
before do
enable_design_management
end
let(:input_text) { "See #{designs_tab_url}" }
subject(:link) { reference_filter(input_text).css('a').first }
it 'includes the word "designs" after the reference in the text content', :aggregate_failures do
expect(link.attr('title')).to eq(issue.title)
expect(link.attr('href')).to eq(designs_tab_url)
expect(link.text).to eq("#{issue.to_reference} (designs)")
end
end
describe '#object_link_text_extras' do
before do
enable_design_management(enabled)
end
let(:enabled) { true }
let(:matches) { ::Issue.link_reference_pattern.match(input_text) }
let(:extras) { subject.object_link_text_extras(issue, matches) }
subject { filter_instance }
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) { designs_tab_url }
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 ...@@ -29,6 +29,10 @@ module DesignManagementTestHelpers
Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options) Gitlab::Routing.url_helpers.designs_project_issue_url(design.project, design.issue, path_options)
end end
def url_for_designs(issue)
Gitlab::Routing.url_helpers.designs_project_issue_url(issue.project, issue)
end
private private
def act_on_designs(designs, &block) def act_on_designs(designs, &block)
......
...@@ -31,3 +31,5 @@ module Banzai ...@@ -31,3 +31,5 @@ module Banzai
end end
end end
end end
Banzai::Filter::IssueReferenceFilter.prepend_if_ee('EE::Banzai::Filter::IssueReferenceFilter')
...@@ -55,6 +55,7 @@ module FilterSpecHelper ...@@ -55,6 +55,7 @@ module FilterSpecHelper
def reference_pipeline(context = {}) def reference_pipeline(context = {})
context.reverse_merge!(project: project) if defined?(project) context.reverse_merge!(project: project) if defined?(project)
context.reverse_merge!(current_user: current_user) if defined?(current_user)
filters = [ filters = [
Banzai::Filter::AutolinkFilter, Banzai::Filter::AutolinkFilter,
......
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