mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 06:04:35 +08:00
Merge pull request #715 from ZmagoD/zd_SCI_1328_v2
fixes smart annotations bug in reports [fixes SCI-1328]
This commit is contained in:
commit
6c541602e7
3 changed files with 23 additions and 9 deletions
|
@ -225,7 +225,8 @@ module ApplicationHelper
|
|||
user_name << ' ' + I18n.t('atwho.res.removed') if !user_still_in_team
|
||||
|
||||
raw("<img src='#{user_avatar_absolute_url(user, :icon_small)}'" \
|
||||
"alt='avatar' class='atwho-user-img-popover'>") +
|
||||
"alt='avatar' class='atwho-user-img-popover'" \
|
||||
" ref='#{'missing-img' if missing_avatar(user, :icon_small)}'>") +
|
||||
raw('<a onClick="$(this).popover(\'show\')" ' \
|
||||
'class="atwho-user-popover" data-container="body" ' \
|
||||
'data-html="true" tabindex="0" data-trigger="focus" ' \
|
||||
|
@ -253,9 +254,14 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
unless user.avatar(style) == '/images/icon_small/missing.png'
|
||||
unless missing_avatar(user, style)
|
||||
return user.avatar(style, timeout: Constants::URL_LONG_EXPIRE_TIME)
|
||||
end
|
||||
url_for(prefix + "/images/#{style}/missing.png")
|
||||
end
|
||||
|
||||
def missing_avatar(user, style)
|
||||
user.avatar(style) == '/images/icon_small/missing.png' ||
|
||||
user.avatar(style) == '/images/thumb/missing.png'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,11 +100,17 @@ module ReportsHelper
|
|||
"<span class=\"label label-#{style}\">#{text}</span>".html_safe
|
||||
end
|
||||
|
||||
def sanitize_report_pdf(text, tags = [], attributes = [])
|
||||
ActionController::Base.helpers.sanitize(
|
||||
text,
|
||||
tags: Constants::WHITELISTED_TAGS + tags,
|
||||
attributes: Constants::WHITELISTED_ATTRIBUTES + attributes
|
||||
)
|
||||
# Fixes issues with avatar images in reports
|
||||
def fix_smart_annotation_image(html)
|
||||
html_doc = Nokogiri::HTML(html)
|
||||
html_doc.search('.atwho-user-popover').each do |el|
|
||||
text = el.content
|
||||
el.replace("<a href='#' style='margin-left: 5px'>#{text}</a>")
|
||||
end
|
||||
html_doc.search('[ref="missing-img"]').each do |el|
|
||||
tag = wicked_pdf_image_tag('icon_small/missing.png')
|
||||
el.replace(tag)
|
||||
end
|
||||
html_doc.to_s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
<body class="print-report-body">
|
||||
<div class="print-report">
|
||||
<% # Also whitelist <img> and <input type="checkbox"> tags %>
|
||||
<%= sanitize_report_pdf(@html, ['img', 'input'], ['type', 'disabled', 'checked']) %>
|
||||
<%= sanitize_input(fix_smart_annotation_image(@html),
|
||||
['img', 'input'],
|
||||
['type', 'disabled', 'checked']) %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue