From aaf76c05260abf380f9406dafd1d37101ece0b1e Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 22 Oct 2019 09:54:36 +0200 Subject: [PATCH 1/3] Fix avatars in comments and activities --- app/helpers/application_helper.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 24186adef..d031ca8a9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -200,17 +200,9 @@ 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 - end - rescue StandardError => e - Rails.logger.error e.message - end - url_for("/images/#{style}/missing.png") + user.avatar_base64(style) + rescue StandardError => e + Rails.logger.error e.message end def missing_avatar(user, style) From 9950a231887a5317cff0ff14e8979a1e1c81ecac Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 22 Oct 2019 12:27:13 +0200 Subject: [PATCH 2/3] Replace base64 avatars with url --- app/helpers/application_helper.rb | 14 +++++++------- app/models/user.rb | 2 +- app/views/shared/comments/_item.html.erb | 2 +- db/structure.sql | 7 ++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d031ca8a9..a9b7cce84 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -182,7 +182,7 @@ module ApplicationHelper else raw("") + " ref='#{'missing-img' unless user.avatar.attached?}'>") end html = @@ -200,16 +200,16 @@ module ApplicationHelper # No more dirty hack def user_avatar_absolute_url(user, style) - user.avatar_base64(style) + 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 - 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' end diff --git a/app/models/user.rb b/app/models/user.rb index 8087b5c84..0ca3b4687 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/shared/comments/_item.html.erb b/app/views/shared/comments/_item.html.erb index 2b7b49edc..305645882 100644 --- a/app/views/shared/comments/_item.html.erb +++ b/app/views/shared/comments/_item.html.erb @@ -14,7 +14,7 @@
<% 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 %> diff --git a/db/structure.sql b/db/structure.sql index 7c5435c87..bdc6b98bb 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -168,8 +168,8 @@ ALTER SEQUENCE public.activities_id_seq OWNED BY public.activities.id; CREATE TABLE public.ar_internal_metadata ( key character varying NOT NULL, value character varying, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL ); @@ -6520,6 +6520,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20190812072649'), ('20190830141257'), ('20190910125740'), -('20191001133557'); +('20191001133557'), +('20191009146101'); From 0ad824c28f6c7c71ec5ed275761111c0dfe43d1b Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 22 Oct 2019 12:30:18 +0200 Subject: [PATCH 3/3] Fix structure sql --- db/structure.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index bdc6b98bb..7c5435c87 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -168,8 +168,8 @@ ALTER SEQUENCE public.activities_id_seq OWNED BY public.activities.id; CREATE TABLE public.ar_internal_metadata ( key character varying NOT NULL, value character varying, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL ); @@ -6520,7 +6520,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20190812072649'), ('20190830141257'), ('20190910125740'), -('20191001133557'), -('20191009146101'); +('20191001133557');