Skip to content

Commit

Permalink
allow html to be rendered completely in some MOTD formats
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Sep 5, 2023
1 parent dbc3373 commit 4a4c12c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions apps/dashboard/app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ def default_dashboard_layout
{ rows: [{ columns: [left_column, right_column].compact }] }
end

def render_motd_rss_item(item)
return '' unless item.description

content = if Configuration.motd_render_html?
item.description.html_safe
else
sanitize(item.description)
end

content_tag(:div, content)
end
end
13 changes: 12 additions & 1 deletion apps/dashboard/app/models/motd_formatter/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ module MotdFormatter
# Utility class for rendering Markdown MOTD files.
class Markdown

include ActionView::Helpers::SanitizeHelper

attr_reader :content, :title

# @param [MotdFile] motd_file an MotdFile object that contains a URI path to a message of the day in OSC format
def initialize(motd_file)
motd_file = MotdFile.new unless motd_file
@title = motd_file.title
@content = OodAppkit.markdown.render(motd_file.content)
content = OodAppkit.markdown.render(motd_file.content)
@content = safe_content(content)
end

def to_partial_path
"dashboard/motd_markdown"
end

def safe_content(content)
if Configuration.motd_render_html?
content.html_safe
else
sanitize(content)
end
end
end
end
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/dashboard/_motd_markdown.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h3><%= @motd.title %></h3>
<hr />
<div><%= sanitize(@motd.content) %></div>
<div><%= @motd.content %></div>
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/dashboard/_motd_rss.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div>
<%= content_tag(:strong, item.pubDate.strftime("%m-%d-%Y")) if item.pubDate %>
<h4><a href="<%= item.link %>"><%= item.title %></a></h4>
<%= content_tag(:p, item.description) if item.description %>
<%= render_motd_rss_item(item) %>
<hr />
</div>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def boolean_configs
:disable_bc_shell => false,
:cancel_session_enabled => false,
:hide_app_version => false,
:motd_render_html => false,
}.freeze
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ disable_bc_shell: true
cancel_session_enabled: true
bc_clean_old_dirs: true
hide_app_version: true
motd_render_html: true

0 comments on commit 4a4c12c

Please sign in to comment.