mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Merge pull request #2171 from aignatov-bio/ai-sci-3995-fix-avatar-comments-and-activties
Fix avatars in comments and activities [SCI-3995]
This commit is contained in:
commit
717b70f75b
3 changed files with 10 additions and 18 deletions
|
@ -182,7 +182,7 @@ module ApplicationHelper
|
|||
else
|
||||
raw("<span class=\"global-avatar-container smart-annotation\"><img src='#{user_avatar_absolute_url(user, :icon_small)}'" \
|
||||
"alt='avatar' class='atwho-user-img-popover'" \
|
||||
" ref='#{'missing-img' if missing_avatar(user, :icon_small)}'></span>")
|
||||
" ref='#{'missing-img' unless user.avatar.attached?}'></span>")
|
||||
end
|
||||
|
||||
html =
|
||||
|
@ -200,23 +200,15 @@ module ApplicationHelper
|
|||
|
||||
# No more dirty hack
|
||||
def user_avatar_absolute_url(user, style)
|
||||
begin
|
||||
unless missing_avatar(user, style)
|
||||
image = File.open(user.avatar_variant(style))
|
||||
encoded_data = Base64.strict_encode64(image)
|
||||
avatar_base64 = "data:#{user.avatar_content_type};base64,#{encoded_data}"
|
||||
return avatar_base64
|
||||
avatar_link = user.avatar_variant(style)
|
||||
if user.avatar.attached?
|
||||
avatar_link.processed.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME)
|
||||
else
|
||||
avatar_link
|
||||
end
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e.message
|
||||
end
|
||||
url_for("/images/#{style}/missing.png")
|
||||
end
|
||||
|
||||
def missing_avatar(user, style)
|
||||
user.avatar == '/images/icon_small/missing.png' ||
|
||||
user.avatar == '/images/thumb/missing.png'
|
||||
end
|
||||
|
||||
def wopi_enabled?
|
||||
ENV['WOPI_ENABLED'] == 'true'
|
||||
|
|
|
@ -249,7 +249,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def avatar_variant(style)
|
||||
return Constants::DEFAULT_AVATAR_URL.gsub(':style', style) unless avatar.attached?
|
||||
return Constants::DEFAULT_AVATAR_URL.gsub(':style', style.to_s) unless avatar.attached?
|
||||
|
||||
format = case style.to_sym
|
||||
when :medium
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div class="avatar-placehodler">
|
||||
<span class='global-avatar-container'>
|
||||
<% if report %>
|
||||
<%= image_tag comment.user.avatar_base64(:icon_small), class: 'avatar' %>
|
||||
<%= image_tag user_avatar_absolute_url(comment.user, :icon_small), class: 'avatar' %>
|
||||
<% else %>
|
||||
<%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue