mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 13:28:53 +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
|
else
|
||||||
raw("<span class=\"global-avatar-container smart-annotation\"><img src='#{user_avatar_absolute_url(user, :icon_small)}'" \
|
raw("<span class=\"global-avatar-container smart-annotation\"><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)}'></span>")
|
" ref='#{'missing-img' unless user.avatar.attached?}'></span>")
|
||||||
end
|
end
|
||||||
|
|
||||||
html =
|
html =
|
||||||
|
@ -200,23 +200,15 @@ module ApplicationHelper
|
||||||
|
|
||||||
# No more dirty hack
|
# No more dirty hack
|
||||||
def user_avatar_absolute_url(user, style)
|
def user_avatar_absolute_url(user, style)
|
||||||
begin
|
avatar_link = user.avatar_variant(style)
|
||||||
unless missing_avatar(user, style)
|
if user.avatar.attached?
|
||||||
image = File.open(user.avatar_variant(style))
|
avatar_link.processed.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME)
|
||||||
encoded_data = Base64.strict_encode64(image)
|
else
|
||||||
avatar_base64 = "data:#{user.avatar_content_type};base64,#{encoded_data}"
|
avatar_link
|
||||||
return avatar_base64
|
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error e.message
|
Rails.logger.error e.message
|
||||||
end
|
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?
|
def wopi_enabled?
|
||||||
ENV['WOPI_ENABLED'] == 'true'
|
ENV['WOPI_ENABLED'] == 'true'
|
||||||
|
|
|
@ -249,7 +249,7 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def avatar_variant(style)
|
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
|
format = case style.to_sym
|
||||||
when :medium
|
when :medium
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="avatar-placehodler">
|
<div class="avatar-placehodler">
|
||||||
<span class='global-avatar-container'>
|
<span class='global-avatar-container'>
|
||||||
<% if report %>
|
<% 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 %>
|
<% else %>
|
||||||
<%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %>
|
<%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue