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:
aignatov-bio 2019-10-29 14:11:39 +01:00 committed by GitHub
commit 717b70f75b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 18 deletions

View file

@ -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'

View file

@ -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

View file

@ -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 %>