Commit 8c4718dc authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ajk-remove-design-reference-filter' into 'master'

Remove design reference filter

See merge request gitlab-org/gitlab!27112
parents 3c1e19ba 3f6ed2f6
# frozen_string_literal: true
module Banzai
module Filter
class DesignReferenceFilter < AbstractReferenceFilter
include Gitlab::Allowable
Identifier = Struct.new(:issue_iid, :filename, keyword_init: true)
self.reference_type = :design
# This filter must be enabled by setting the following flags:
# - design_management
# - design_management_reference_filter_gfm_pipeline
def call
return doc unless enabled?
super
end
def find_object(project, identifier)
records_per_parent[project][identifier]
end
def parent_records(project, identifiers)
return [] unless can_read_designs?(project)
iids = identifiers.map(&:issue_iid).to_set
filenames = identifiers.map(&:filename).to_set
issues = project.issues.where(iid: iids)
issue_map = issues.index_by(&:id)
designs(issues.to_a, filenames).select do |d|
issue = issue_map[d.issue_id]
# assign values we have already fetched
d.project = project
d.issue = issue
identifiers.include?(Identifier.new(filename: d.filename, issue_iid: issue.iid))
end
end
def relation_for_paths(paths)
super.includes(:route, :namespace, :group)
end
def parent_type
:project
end
# optimisation to reuse the parent_per_reference query information
def parent_from_ref(ref)
parent_per_reference[ref || current_parent_path]
end
def url_for_object(design, project)
path_options = { vueroute: design.filename }
Gitlab::Routing.url_helpers.designs_project_issue_path(project, design.issue, path_options)
end
def data_attributes_for(_text, _project, design, **_kwargs)
super.merge(issue: design.issue_id)
end
def self.object_class
::DesignManagement::Design
end
def self.object_sym
:design
end
def self.parse_symbol(raw, match_data)
filename = parse_filename(raw, match_data)
iid = match_data[:issue].to_i
Identifier.new(filename: filename, issue_iid: iid)
end
def self.parse_filename(raw, match_data)
if name = match_data[:simple_file_name]
name
elsif efn = match_data[:escaped_filename]
efn.gsub(/(\\ \\ | \\ ")/x) { |x| x[1] }
elsif b64_name = match_data[:base_64_encoded_name]
Base64.decode64(b64_name)
else
raise "Unexpected name format: #{raw}"
end
end
def record_identifier(design)
Identifier.new(filename: design.filename, issue_iid: design.issue.iid)
end
private
def can_read_designs?(project)
DeclarativePolicy.user_scope { can?(current_user, :read_design, project) }
end
def designs(issues, filenames)
DesignManagement::Design.on_issue(issues).with_filename(filenames)
end
def enabled?
Feature.enabled?(:design_management_reference_filter_gfm_pipeline)
end
end
end
end
......@@ -18,7 +18,6 @@ module EE
def reference_filters
[
::Banzai::Filter::EpicReferenceFilter,
::Banzai::Filter::DesignReferenceFilter,
*super
]
end
......
# frozen_string_literal: true
require 'spec_helper'
describe 'viewing issues with design references' do
include DesignManagementTestHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project_empty_repo, :public) }
let_it_be(:design_issue) { create(:issue, project: project) }
let_it_be(:design_a) { create(:design, :with_file, issue: design_issue) }
let_it_be(:design_b) { create(:design, :with_file, issue: design_issue) }
let(:issue) { create(:issue, project: project, description: description) }
let(:description) do
<<~MD
Designs:
* #{design_a.to_reference(project)}
* #{design_b.to_reference(project)}
MD
end
before do
project.add_developer(user)
sign_in(user)
end
context 'design management is enabled' do
before do
enable_design_management
end
it 'shows the issue description' do
visit project_issue_path(project, issue)
expect(page).to have_link(design_a.to_reference)
expect(page).to have_link(design_b.to_reference)
end
end
context 'design management is disabled' do
before do
enable_design_management(false, false)
end
it 'shows the issue description' do
visit project_issue_path(project, issue)
expect(page).to have_link(issue.to_reference)
expect(page).not_to have_link(design_a.to_reference)
expect(page).not_to have_link(design_b.to_reference)
end
end
end
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