From fb3d40cb61eaff46bc10d3d49d499bd5d34a6be1 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 3 Jun 2019 14:52:58 -0700 Subject: Extend #parse to accept a suggestions_filter_enabled param This will allow the front end to specify the behavior as needed. --- app/services/preview_markdown_service.rb | 4 +++- lib/gitlab/diff/suggestions_parser.rb | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/services/preview_markdown_service.rb b/app/services/preview_markdown_service.rb index 7386530f45f..2b4c4ae68e2 100644 --- a/app/services/preview_markdown_service.rb +++ b/app/services/preview_markdown_service.rb @@ -38,7 +38,9 @@ class PreviewMarkdownService < BaseService head_sha: params[:head_sha], start_sha: params[:start_sha]) - Gitlab::Diff::SuggestionsParser.parse(text, position: position, project: project) + Gitlab::Diff::SuggestionsParser.parse(text, position: position, + project: project, + supports_suggestion: params[:preview_suggestions]) end def preview_sugestions? diff --git a/lib/gitlab/diff/suggestions_parser.rb b/lib/gitlab/diff/suggestions_parser.rb index c8c03d5d001..6e17ffaf6ff 100644 --- a/lib/gitlab/diff/suggestions_parser.rb +++ b/lib/gitlab/diff/suggestions_parser.rb @@ -10,10 +10,12 @@ module Gitlab # Returns an array of Gitlab::Diff::Suggestion which represents each # suggestion in the given text. # - def parse(text, position:, project:) + def parse(text, position:, project:, supports_suggestion: true) return [] unless position.complete? - html = Banzai.render(text, project: nil, no_original_data: true) + html = Banzai.render(text, project: nil, + no_original_data: true, + suggestions_filter_enabled: supports_suggestion) doc = Nokogiri::HTML(html) suggestion_nodes = doc.search('pre.suggestion') -- cgit v1.2.1