Class: Banzai::Filter::DesignReferenceFilter

Inherits:
AbstractReferenceFilter show all
Defined in:
lib/banzai/filter/design_reference_filter.rb

Defined Under Namespace

Classes: Identifier

Constant Summary collapse

FEATURE_FLAG =
:design_management_reference_filter_gfm_pipeline

Constants inherited from AbstractReferenceFilter

AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#current_parent_path, #current_project_namespace_path, #find_for_paths, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, identifier, #object_class, #object_link_filter, #object_link_text, #object_link_text_extras, #object_link_title, object_name, #object_sym, #parent_per_reference, #records_per_parent, #references_in, references_in, #references_per_parent, symbol_from_match, #url_for_object_cached, #wrap_link

Methods inherited from ReferenceFilter

call, #call_and_update_nodes, #data_attribute, #each_node, #element_node?, #group, #ignore_ancestor_query, #initialize, #nodes, #project, #reference_class, #replace_link_node_with_href, #replace_link_node_with_text, #replace_text_when_pattern_matches, #skip_project_check?, #text_node?, #user, #validate, #yield_valid_link

Methods included from OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

This class inherits a constructor from Banzai::Filter::ReferenceFilter

Class Method Details

.object_classObject


88
89
90
# File 'lib/banzai/filter/design_reference_filter.rb', line 88

def self.object_class
  ::DesignManagement::Design
end

.object_symObject


92
93
94
# File 'lib/banzai/filter/design_reference_filter.rb', line 92

def self.object_sym
  :design
end

.parse_symbol(raw, match_data) ⇒ Object


96
97
98
99
100
# File 'lib/banzai/filter/design_reference_filter.rb', line 96

def self.parse_symbol(raw, match_data)
  filename = match_data[:url_filename]
  iid = match_data[:issue].to_i
  Identifier.new(filename: CGI.unescape(filename), issue_iid: iid)
end

Instance Method Details

#callObject

This filter must be enabled by setting the design_management_reference_filter_gfm_pipeline flag


40
41
42
43
44
# File 'lib/banzai/filter/design_reference_filter.rb', line 40

def call
  return doc unless enabled?

  super
end

#data_attributes_for(_text, _project, design, **_kwargs) ⇒ Object


84
85
86
# File 'lib/banzai/filter/design_reference_filter.rb', line 84

def data_attributes_for(_text, _project, design, **_kwargs)
  super.merge(issue: design.issue_id)
end

#find_object(project, identifier) ⇒ Object


46
47
48
# File 'lib/banzai/filter/design_reference_filter.rb', line 46

def find_object(project, identifier)
  records_per_parent[project][identifier]
end

#parent_from_ref(ref) ⇒ Object

optimisation to reuse the parent_per_reference query information


75
76
77
# File 'lib/banzai/filter/design_reference_filter.rb', line 75

def parent_from_ref(ref)
  parent_per_reference[ref || current_parent_path]
end

#parent_records(project, identifiers) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/banzai/filter/design_reference_filter.rb', line 50

def parent_records(project, identifiers)
  return [] unless project.design_management_enabled?

  iids        = identifiers.map(&:issue_iid).to_set
  issues      = project.issues.where(iid: iids)
  id_for_iid  = issues.index_by(&:iid).transform_values(&:id)
  issue_by_id = issues.index_by(&:id)

  designs(identifiers, id_for_iid).each do |d|
    issue = issue_by_id[d.issue_id]
    # optimisation: assign values we have already fetched
    d.project = project
    d.issue = issue
  end
end

#parent_typeObject


70
71
72
# File 'lib/banzai/filter/design_reference_filter.rb', line 70

def parent_type
  :project
end

#record_identifier(design) ⇒ Object


102
103
104
# File 'lib/banzai/filter/design_reference_filter.rb', line 102

def record_identifier(design)
  Identifier.new(filename: design.filename, issue_iid: design.issue.iid)
end

#relation_for_paths(paths) ⇒ Object


66
67
68
# File 'lib/banzai/filter/design_reference_filter.rb', line 66

def relation_for_paths(paths)
  super.includes(:route, :namespace, :group)
end

#url_for_object(design, project) ⇒ Object


79
80
81
82
# File 'lib/banzai/filter/design_reference_filter.rb', line 79

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