Commit 99205515 authored by Nick Thomas's avatar Nick Thomas

Enable CacheMarkdownField for the remaining models

This commit alters views for the following models to use the markdown cache if
present:

* AbuseReport
* Appearance
* ApplicationSetting
* BroadcastMessage
* Group
* Issue
* Label
* MergeRequest
* Milestone
* Project

At the same time, calls to `escape_once` have been moved into the `single_line`
Banzai pipeline, so they can't be missed out by accident and the work is done
at save, rather than render, time.
parent dd159a75
...@@ -37,7 +37,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController ...@@ -37,7 +37,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
end end
def preview def preview
@message = broadcast_message_params[:message] @broadcast_message = BroadcastMessage.new(broadcast_message_params)
end end
protected protected
......
...@@ -16,7 +16,7 @@ module AppearancesHelper ...@@ -16,7 +16,7 @@ module AppearancesHelper
end end
def brand_text def brand_text
markdown(brand_item.description) markdown_field(brand_item, :description)
end end
def brand_item def brand_item
......
...@@ -11,18 +11,6 @@ module ApplicationSettingsHelper ...@@ -11,18 +11,6 @@ module ApplicationSettingsHelper
current_application_settings.signin_enabled? current_application_settings.signin_enabled?
end end
def extra_sign_in_text
current_application_settings.sign_in_text
end
def after_sign_up_text
current_application_settings.after_sign_up_text
end
def shared_runners_text
current_application_settings.shared_runners_text
end
def user_oauth_applications? def user_oauth_applications?
current_application_settings.user_oauth_applications current_application_settings.user_oauth_applications
end end
......
...@@ -3,7 +3,7 @@ module BroadcastMessagesHelper ...@@ -3,7 +3,7 @@ module BroadcastMessagesHelper
return unless message.present? return unless message.present?
content_tag :div, class: 'broadcast-message', style: broadcast_message_style(message) do content_tag :div, class: 'broadcast-message', style: broadcast_message_style(message) do
icon('bullhorn') << ' ' << render_broadcast_message(message.message) icon('bullhorn') << ' ' << render_broadcast_message(message)
end end
end end
...@@ -32,7 +32,7 @@ module BroadcastMessagesHelper ...@@ -32,7 +32,7 @@ module BroadcastMessagesHelper
end end
end end
def render_broadcast_message(message) def render_broadcast_message(broadcast_message)
Banzai.render(message, pipeline: :broadcast_message).html_safe Banzai.render_field(broadcast_message, :message).html_safe
end end
end end
...@@ -13,14 +13,12 @@ module GitlabMarkdownHelper ...@@ -13,14 +13,12 @@ module GitlabMarkdownHelper
def link_to_gfm(body, url, html_options = {}) def link_to_gfm(body, url, html_options = {})
return "" if body.blank? return "" if body.blank?
escaped_body = if body.start_with?('<img') context = {
body project: @project,
else current_user: (current_user if defined?(current_user)),
escape_once(body) pipeline: :single_line,
end }
gfm_body = Banzai.render(body, context)
user = current_user if defined?(current_user)
gfm_body = Banzai.render(escaped_body, project: @project, current_user: user, pipeline: :single_line)
fragment = Nokogiri::HTML::DocumentFragment.parse(gfm_body) fragment = Nokogiri::HTML::DocumentFragment.parse(gfm_body)
if fragment.children.size == 1 && fragment.children[0].name == 'a' if fragment.children.size == 1 && fragment.children[0].name == 'a'
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
%td %td
%strong.subheading.visible-xs-block.visible-sm-block Message %strong.subheading.visible-xs-block.visible-sm-block Message
.message .message
= markdown(abuse_report.message.squish!, pipeline: :single_line, author: reporter) = markdown_field(abuse_report, :message)
%td %td
- if user - if user
= link_to 'Remove user & report', admin_abuse_report_path(abuse_report, remove_user: true), = link_to 'Remove user & report', admin_abuse_report_path(abuse_report, remove_user: true),
......
.broadcast-message-preview{ style: broadcast_message_style(@broadcast_message) } .broadcast-message-preview{ style: broadcast_message_style(@broadcast_message) }
= icon('bullhorn') = icon('bullhorn')
.js-broadcast-message-preview .js-broadcast-message-preview
= render_broadcast_message(@broadcast_message.message.presence || "Your message here") - if @broadcast_message.message.present?
= render_broadcast_message(@broadcast_message)
- else
= "Your message here"
= form_for [:admin, @broadcast_message], html: { class: 'broadcast-message-form form-horizontal js-quick-submit js-requires-input'} do |f| = form_for [:admin, @broadcast_message], html: { class: 'broadcast-message-form form-horizontal js-quick-submit js-requires-input'} do |f|
= form_errors(@broadcast_message) = form_errors(@broadcast_message)
......
$('.js-broadcast-message-preview').html("#{j(render_broadcast_message(@message))}"); $('.js-broadcast-message-preview').html("#{j(render_broadcast_message(@broadcast_message))}");
...@@ -23,4 +23,4 @@ ...@@ -23,4 +23,4 @@
- if group.description.present? - if group.description.present?
.description .description
= markdown(group.description, pipeline: :description) = markdown_field(group, :description)
%li{id: dom_id(label)} %li{id: dom_id(label)}
.label-row .label-row
= render_colored_label(label, tooltip: false) = render_colored_label(label, tooltip: false)
= markdown(label.description, pipeline: :single_line) = markdown_field(label, :description)
.pull-right .pull-right
= link_to 'Edit', edit_admin_label_path(label), class: 'btn btn-sm' = link_to 'Edit', edit_admin_label_path(label), class: 'btn btn-sm'
= link_to 'Delete', admin_label_path(label), class: 'btn btn-sm btn-remove remove-row', method: :delete, remote: true, data: {confirm: "Delete this label? Are you sure?"} = link_to 'Delete', admin_label_path(label), class: 'btn btn-sm btn-remove remove-row', method: :delete, remote: true, data: {confirm: "Delete this label? Are you sure?"}
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
- if project.description.present? - if project.description.present?
.description .description
= markdown(project.description, pipeline: :description) = markdown_field(project, :description)
= paginate @projects, theme: 'gitlab' = paginate @projects, theme: 'gitlab'
- else - else
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
Almost there... Almost there...
%p.lead %p.lead
Please check your email to confirm your account Please check your email to confirm your account
- if after_sign_up_text.present? - if current_application_settings.after_sign_up_text.present?
.well-confirmation.text-center .well-confirmation.text-center
= markdown(after_sign_up_text) = markdown_field(current_application_settings, :after_sign_up_text)
%p.confirmation-content.text-center %p.confirmation-content.text-center
No confirmation email received? Please check your spam folder or No confirmation email received? Please check your spam folder or
.append-bottom-20.prepend-top-20.text-center .append-bottom-20.prepend-top-20.text-center
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
- if @group.description.present? - if @group.description.present?
.cover-desc.description .cover-desc.description
= markdown(@group.description, pipeline: :description) = markdown_field(@group, :description)
%div.groups-header{ class: container_class } %div.groups-header{ class: container_class }
.top-area .top-area
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
Read more about GitLab at #{link_to promo_host, promo_url, target: '_blank'}. Read more about GitLab at #{link_to promo_host, promo_url, target: '_blank'}.
- if current_application_settings.help_page_text.present? - if current_application_settings.help_page_text.present?
%hr %hr
= markdown(current_application_settings.help_page_text) = markdown_field(current_application_settings, :help_page_text)
%hr %hr
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
Perform code reviews and enhance collaboration with merge requests. Perform code reviews and enhance collaboration with merge requests.
Each project can also have an issue tracker and a wiki. Each project can also have an issue tracker and a wiki.
- if extra_sign_in_text.present? - if current_application_settings.sign_in_text.present?
= markdown(extra_sign_in_text) = markdown_field(current_application_settings, :sign_in_text)
%hr %hr
.container .container
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
.project-home-desc .project-home-desc
- if @project.description.present? - if @project.description.present?
= markdown(@project.description, pipeline: :description) = markdown_field(@project, :description)
- if forked_from_project = @project.forked_from_project - if forked_from_project = @project.forked_from_project
%p %p
......
...@@ -65,10 +65,10 @@ ...@@ -65,10 +65,10 @@
.commit-box.content-block .commit-box.content-block
%h3.commit-title %h3.commit-title
= markdown escape_once(@commit.title), pipeline: :single_line, author: @commit.author = markdown(@commit.title, pipeline: :single_line, author: @commit.author)
- if @commit.description.present? - if @commit.description.present?
%pre.commit-description %pre.commit-description
= preserve(markdown(escape_once(@commit.description), pipeline: :single_line, author: @commit.author)) = preserve(markdown(@commit.description, pipeline: :single_line, author: @commit.author))
:javascript :javascript
$(".commit-info.branches").load("#{branches_namespace_project_commit_path(@project.namespace, @project, @commit.id)}"); $(".commit-info.branches").load("#{branches_namespace_project_commit_path(@project.namespace, @project, @commit.id)}");
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
- if commit.description? - if commit.description?
%pre.commit-row-description.js-toggle-content %pre.commit-row-description.js-toggle-content
= preserve(markdown(escape_once(commit.description), pipeline: :single_line, author: commit.author)) = preserve(markdown(commit.description, pipeline: :single_line, author: commit.author))
.commit-row-info .commit-row-info
= commit_author_link(commit, avatar: false, size: 24) = commit_author_link(commit, avatar: false, size: 24)
......
...@@ -55,12 +55,12 @@ ...@@ -55,12 +55,12 @@
.issue-details.issuable-details .issue-details.issuable-details
.detail-page-description.content-block .detail-page-description.content-block
%h2.title %h2.title
= markdown escape_once(@issue.title), pipeline: :single_line, author: @issue.author = markdown_field(@issue, :title)
- if @issue.description.present? - if @issue.description.present?
.description{ class: can?(current_user, :update_issue, @issue) ? 'js-task-list-container' : '' } .description{ class: can?(current_user, :update_issue, @issue) ? 'js-task-list-container' : '' }
.wiki .wiki
= preserve do = preserve do
= markdown(@issue.description, cache_key: [@issue, "description"], author: @issue.author) = markdown_field(@issue, :description)
%textarea.hidden.js-task-list-field %textarea.hidden.js-task-list-field
= @issue.description = @issue.description
= edited_time_ago_with_tooltip(@issue, placement: 'bottom', html_class: 'issue_edited_ago') = edited_time_ago_with_tooltip(@issue, placement: 'bottom', html_class: 'issue_edited_ago')
......
.detail-page-description.content-block .detail-page-description.content-block
%h2.title %h2.title
= markdown escape_once(@merge_request.title), pipeline: :single_line, author: @merge_request.author = markdown_field(@merge_request, :title)
%div %div
- if @merge_request.description.present? - if @merge_request.description.present?
.description{class: can?(current_user, :update_merge_request, @merge_request) ? 'js-task-list-container' : ''} .description{class: can?(current_user, :update_merge_request, @merge_request) ? 'js-task-list-container' : ''}
.wiki .wiki
= preserve do = preserve do
= markdown(@merge_request.description, cache_key: [@merge_request, "description"], author: @merge_request.author) = markdown_field(@merge_request, :description)
%textarea.hidden.js-task-list-field %textarea.hidden.js-task-list-field
= @merge_request.description = @merge_request.description
......
...@@ -30,13 +30,13 @@ ...@@ -30,13 +30,13 @@
.detail-page-description.milestone-detail .detail-page-description.milestone-detail
%h2.title %h2.title
= markdown escape_once(@milestone.title), pipeline: :single_line = markdown_field(@milestone, :title)
%div %div
- if @milestone.description.present? - if @milestone.description.present?
.description .description
.wiki .wiki
= preserve do = preserve do
= markdown @milestone.description = markdown_field(@milestone, :description)
- if @milestone.total_items_count(current_user).zero? - if @milestone.total_items_count(current_user).zero?
.alert.alert-success.prepend-top-default .alert.alert-success.prepend-top-default
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
- if @commit - if @commit
.commit-box.content-block .commit-box.content-block
%h3.commit-title %h3.commit-title
= markdown escape_once(@commit.title), pipeline: :single_line = markdown(@commit.title, pipeline: :single_line)
- if @commit.description.present? - if @commit.description.present?
%pre.commit-description %pre.commit-description
= preserve(markdown(escape_once(@commit.description), pipeline: :single_line)) = preserve(markdown(@commit.description, pipeline: :single_line))
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
= link_to namespace_project_commits_path(@project.namespace, @project, commit.id) do = link_to namespace_project_commits_path(@project.namespace, @project, commit.id) do
%code= commit.short_id %code= commit.short_id
= image_tag avatar_icon(commit.author_email), class: "", width: 16, alt: '' = image_tag avatar_icon(commit.author_email), class: "", width: 16, alt: ''
= markdown escape_once(truncate(commit.title, length: 40)), pipeline: :single_line, author: commit.author = markdown(truncate(commit.title, length: 40), pipeline: :single_line, author: commit.author)
%td %td
%span.pull-right.cgray %span.pull-right.cgray
= time_ago_with_tooltip(commit.committed_date) = time_ago_with_tooltip(commit.committed_date)
%h3 Shared Runners %h3 Shared Runners
.bs-callout.bs-callout-warning.shared-runners-description .bs-callout.bs-callout-warning.shared-runners-description
- if shared_runners_text.present? - if current_application_settings.shared_runners_text.present?
= markdown(shared_runners_text, pipeline: 'plain_markdown') = markdown_field(current_application_settings, :shared_runners_text)
- else - else
GitLab Shared Runners execute code of different projects on the same Runner GitLab Shared Runners execute code of different projects on the same Runner
unless you configure GitLab Runner Autoscale with MaxBuilds 1 (which it is unless you configure GitLab Runner Autoscale with MaxBuilds 1 (which it is
......
...@@ -30,4 +30,4 @@ ...@@ -30,4 +30,4 @@
.description.prepend-top-default .description.prepend-top-default
.wiki .wiki
= preserve do = preserve do
= markdown release.description = markdown_field(release, :description)
...@@ -33,6 +33,6 @@ ...@@ -33,6 +33,6 @@
.description .description
.wiki .wiki
= preserve do = preserve do
= markdown @release.description = markdown_field(@release, :description)
- else - else
This tag has no release notes. This tag has no release notes.
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
= link_to_label(label, tooltip: false) = link_to_label(label, tooltip: false)
- if label.description - if label.description
%span.label-description %span.label-description
= markdown(label.description, pipeline: :single_line) = markdown_field(label, :description)
...@@ -35,4 +35,4 @@ ...@@ -35,4 +35,4 @@
- if group.description.present? - if group.description.present?
.description .description
= markdown(group.description, pipeline: :description) = markdown_field(group, :description)
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
= link_to milestones_label_path(options) do = link_to milestones_label_path(options) do
- render_colored_label(label, tooltip: false) - render_colored_label(label, tooltip: false)
%span.prepend-description-left %span.prepend-description-left
= markdown(label.description, pipeline: :single_line) = markdown_field(label, :description)
.pull-info-right .pull-info-right
%span.append-right-20 %span.append-right-20
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
.detail-page-description.milestone-detail .detail-page-description.milestone-detail
%h2.title %h2.title
= markdown escape_once(milestone.title), pipeline: :single_line = markdown_field(milestone, :title)
- if milestone.complete?(current_user) && milestone.active? - if milestone.complete?(current_user) && milestone.active?
.alert.alert-success.prepend-top-default .alert.alert-success.prepend-top-default
...@@ -55,4 +55,3 @@ ...@@ -55,4 +55,3 @@
Open Open
%td %td
= ms.expires_at = ms.expires_at
...@@ -50,4 +50,4 @@ ...@@ -50,4 +50,4 @@
class: "commit-row-message" class: "commit-row-message"
- elsif project.description.present? - elsif project.description.present?
.description .description
= markdown(project.description, pipeline: :description) = markdown_field(project, :description)
- unless @snippet.content.empty? - unless @snippet.content.empty?
- if markup?(@snippet.file_name) - if markup?(@snippet.file_name)
%textarea.markdown-snippet-copy.blob-content{data: {blob_id: @snippet.id}} %textarea.markdown-snippet-copy.blob-content{data: {blob_id: @snippet.id}}
= @snippet.data = @snippet.content
.file-content.wiki .file-content.wiki
= render_markup(@snippet.file_name, @snippet.data) - if gitlab_markdown?(@snippet.file_name)
= preserve(markdown_field(@snippet, :content))
- else
= render_markup(@snippet.file_name, @snippet.content)
- else - else
= render 'shared/file_highlight', blob: @snippet = render 'shared/file_highlight', blob: @snippet
- else - else
......
...@@ -21,4 +21,4 @@ ...@@ -21,4 +21,4 @@
= render "snippets/actions" = render "snippets/actions"
%h2.snippet-title.prepend-top-0.append-bottom-0 %h2.snippet-title.prepend-top-0.append-bottom-0
= markdown escape_once(@snippet.title), pipeline: :single_line, author: @snippet.author = markdown_field(@snippet, :title)
require 'erb'
module Banzai
module Filter
# Text filter that escapes these HTML entities: & " < >
class HTMLEntityFilter < HTML::Pipeline::TextFilter
def call
ERB::Util.html_escape(text)
end
end
end
end
...@@ -3,6 +3,7 @@ module Banzai ...@@ -3,6 +3,7 @@ module Banzai
class SingleLinePipeline < GfmPipeline class SingleLinePipeline < GfmPipeline
def self.filters def self.filters
@filters ||= FilterArray[ @filters ||= FilterArray[
Filter::HTMLEntityFilter,
Filter::SanitizationFilter, Filter::SanitizationFilter,
Filter::EmojiFilter, Filter::EmojiFilter,
......
...@@ -7,7 +7,7 @@ describe BroadcastMessagesHelper do ...@@ -7,7 +7,7 @@ describe BroadcastMessagesHelper do
end end
it 'includes the current message' do it 'includes the current message' do
current = double(message: 'Current Message') current = BroadcastMessage.new(message: 'Current Message')
allow(helper).to receive(:broadcast_message_style).and_return(nil) allow(helper).to receive(:broadcast_message_style).and_return(nil)
...@@ -15,7 +15,7 @@ describe BroadcastMessagesHelper do ...@@ -15,7 +15,7 @@ describe BroadcastMessagesHelper do
end end
it 'includes custom style' do it 'includes custom style' do
current = double(message: 'Current Message') current = BroadcastMessage.new(message: 'Current Message')
allow(helper).to receive(:broadcast_message_style).and_return('foo') allow(helper).to receive(:broadcast_message_style).and_return('foo')
......
require 'spec_helper'
describe Banzai::Filter::HTMLEntityFilter, lib: true do
include FilterSpecHelper
let(:unescaped) { 'foo <strike attr="foo">&&&</strike>' }
let(:escaped) { 'foo &lt;strike attr=&quot;foo&quot;&gt;&amp;&amp;&amp;&lt;/strike&gt;' }
it 'converts common entities to their HTML-escaped equivalents' do
output = filter(unescaped)
expect(output).to eq(escaped)
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