diff options
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/issue_reference_filter.rb | 20 | ||||
-rw-r--r-- | lib/banzai/filter/upload_link_filter.rb | 4 | ||||
-rw-r--r-- | lib/banzai/filter/user_reference_filter.rb | 2 | ||||
-rw-r--r-- | lib/banzai/pipeline.rb | 2 | ||||
-rw-r--r-- | lib/banzai/reference_parser/design_parser.rb | 31 | ||||
-rw-r--r-- | lib/banzai/renderer.rb | 7 |
6 files changed, 60 insertions, 6 deletions
diff --git a/lib/banzai/filter/issue_reference_filter.rb b/lib/banzai/filter/issue_reference_filter.rb index 09a4d71b5f6..37e66387f2e 100644 --- a/lib/banzai/filter/issue_reference_filter.rb +++ b/lib/banzai/filter/issue_reference_filter.rb @@ -28,8 +28,24 @@ module Banzai def parent_records(parent, ids) parent.issues.where(iid: ids.to_a) end + + 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 - -Banzai::Filter::IssueReferenceFilter.prepend_if_ee('EE::Banzai::Filter::IssueReferenceFilter') diff --git a/lib/banzai/filter/upload_link_filter.rb b/lib/banzai/filter/upload_link_filter.rb index 023c1288367..762371e1418 100644 --- a/lib/banzai/filter/upload_link_filter.rb +++ b/lib/banzai/filter/upload_link_filter.rb @@ -50,6 +50,10 @@ module Banzai Addressable::URI.join(Gitlab.config.gitlab.base_url, path).to_s end + if html_attr.name == 'href' + html_attr.parent.set_attribute('data-link', 'true') + end + html_attr.parent.add_class('gfm') end diff --git a/lib/banzai/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb index 8cda67867a8..9268ff1a827 100644 --- a/lib/banzai/filter/user_reference_filter.rb +++ b/lib/banzai/filter/user_reference_filter.rb @@ -106,7 +106,7 @@ module Banzai end def link_class - reference_class(:project_member, tooltip: false) + [reference_class(:project_member, tooltip: false), "js-user-link"].join(" ") end def link_to_all(link_content: nil) diff --git a/lib/banzai/pipeline.rb b/lib/banzai/pipeline.rb index 8fdbc044861..01cadb11e83 100644 --- a/lib/banzai/pipeline.rb +++ b/lib/banzai/pipeline.rb @@ -9,7 +9,7 @@ module Banzai # Examples: # Pipeline[nil] # => Banzai::Pipeline::FullPipeline # Pipeline[:label] # => Banzai::Pipeline::LabelPipeline - # Pipeline[StatusPage::PostProcessPipeline] # => StatusPage::PostProcessPipeline + # Pipeline[StatusPage::Pipeline::PostProcessPipeline] # => StatusPage::Pipeline::PostProcessPipeline # # Pipeline['label'] # => raises ArgumentError - unsupport type # Pipeline[Project] # => raises ArgumentError - not a subclass of BasePipeline diff --git a/lib/banzai/reference_parser/design_parser.rb b/lib/banzai/reference_parser/design_parser.rb new file mode 100644 index 00000000000..04e878756d8 --- /dev/null +++ b/lib/banzai/reference_parser/design_parser.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Banzai + module ReferenceParser + class DesignParser < BaseParser + self.reference_type = :design + + def references_relation + DesignManagement::Design + end + + def nodes_visible_to_user(user, nodes) + issues = issues_for_nodes(nodes) + issue_attr = 'data-issue' + + nodes.select do |node| + if node.has_attribute?(issue_attr) + can?(user, :read_design, issues[node]) + else + true + end + end + end + + def issues_for_nodes(nodes) + relation = Issue.includes(project: [:project_feature]) + grouped_objects_for_nodes(nodes, relation, 'data-issue') + end + end + end +end diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index 3cb9ec21e8f..fbbd6135959 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -138,15 +138,18 @@ module Banzai # # html - String to process # context - Hash of options to customize output - # :pipeline - Symbol pipeline type + # :pipeline - Symbol pipeline type - for context transform only, defaults to :full # :project - Project # :user - User object + # :post_process_pipeline - pipeline to use for post_processing - defaults to PostProcessPipeline # # Returns an HTML-safe String def self.post_process(html, context) context = Pipeline[context[:pipeline]].transform_context(context) - pipeline = Pipeline[:post_process] + # Use a passed class for the pipeline or default to PostProcessPipeline + pipeline = context.delete(:post_process_pipeline) || ::Banzai::Pipeline::PostProcessPipeline + if context[:xhtml] pipeline.to_document(html, context).to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML) else |