mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
fixes smart annotations bug in reports [fixes SCI-1328]
This commit is contained in:
parent
d726c121bc
commit
7b9410f02f
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
|
user_name << ' ' + I18n.t('atwho.res.removed') if !user_still_in_team
|
||||||
|
|
||||||
raw("<img src='#{user_avatar_absolute_url(user, :icon_small)}'" \
|
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\')" ' \
|
raw('<a onClick="$(this).popover(\'show\')" ' \
|
||||||
'class="atwho-user-popover" data-container="body" ' \
|
'class="atwho-user-popover" data-container="body" ' \
|
||||||
'data-html="true" tabindex="0" data-trigger="focus" ' \
|
'data-html="true" tabindex="0" data-trigger="focus" ' \
|
||||||
|
@ -253,9 +254,14 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
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)
|
return user.avatar(style, timeout: Constants::URL_LONG_EXPIRE_TIME)
|
||||||
end
|
end
|
||||||
url_for(prefix + "/images/#{style}/missing.png")
|
url_for(prefix + "/images/#{style}/missing.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def missing_avatar(user, style)
|
||||||
|
user.avatar(style) == '/images/icon_small/missing.png' ||
|
||||||
|
user.avatar(style) == '/images/thumb/missing.png'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,11 +100,17 @@ module ReportsHelper
|
||||||
"<span class=\"label label-#{style}\">#{text}</span>".html_safe
|
"<span class=\"label label-#{style}\">#{text}</span>".html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_report_pdf(text, tags = [], attributes = [])
|
# Fixes issues with avatar images in reports
|
||||||
ActionController::Base.helpers.sanitize(
|
def fix_smart_annotation_image(html)
|
||||||
text,
|
html_doc = Nokogiri::HTML(html)
|
||||||
tags: Constants::WHITELISTED_TAGS + tags,
|
html_doc.search('.atwho-user-popover').each do |el|
|
||||||
attributes: Constants::WHITELISTED_ATTRIBUTES + attributes
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
<body class="print-report-body">
|
<body class="print-report-body">
|
||||||
<div class="print-report">
|
<div class="print-report">
|
||||||
<% # Also whitelist <img> and <input type="checkbox"> tags %>
|
<% # 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>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue