A platform for community discussion. Free, open, simple.
FIX: Use CDN URL for internal onebox avatars (#15077)
David Taylor03998e0a299b
diff --git a/app/services/username_changer.rb b/app/services/username_changer.rbindex 7c6cec61cc3..0c8c472805f 100644--- a/app/services/username_changer.rb+++ b/app/services/username_changer.rb@@ -24,7 +24,7 @@ class UsernameChangerUsernameChanger.update_username(user_id: @user.id,old_username: @old_username,new_username: @new_username,- avatar_template: @user.avatar_template,+ avatar_template: @user.avatar_template_url,asynchronous: asynchronous) if run_update_jobreturn trueenddiff --git a/db/post_migrate/20211124161346_queue_internal_onebox_rebake.rb b/db/post_migrate/20211124161346_queue_internal_onebox_rebake.rbnew file mode 100644index 00000000000..85af7f1ceea--- /dev/null+++ b/db/post_migrate/20211124161346_queue_internal_onebox_rebake.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true++class QueueInternalOneboxRebake < ActiveRecord::Migration[6.1]+ def up+ # Prior to this fix, internal oneboxes were bypassing the CDN for avatar URLs.+ # If a site has a CDN, queue up a rebake in the background+ if GlobalSetting.cdn_url+ execute <<~SQL+ UPDATE posts SET baked_version = 0+ WHERE cooked LIKE '%src="/user_avatar/%'+ SQL+ end+ end++ def down+ # Do nothing+ end+enddiff --git a/lib/oneboxer.rb b/lib/oneboxer.rbindex 6c194fb0418..61393627af6 100644--- a/lib/oneboxer.rb+++ b/lib/oneboxer.rb@@ -321,7 +321,7 @@ module Oneboxerargs = {topic_id: topic.id,post_number: post.post_number,- avatar: PrettyText.avatar_img(post.user.avatar_template, "tiny"),+ avatar: PrettyText.avatar_img(post.user.avatar_template_url, "tiny"),original_url: url,title: PrettyText.unescape_emoji(CGI::escapeHTML(topic.title)),category_html: CategoryBadge.html_for(topic.category),diff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rbindex 21afb3abc99..8e68bf7ae84 100644--- a/spec/components/oneboxer_spec.rb+++ b/spec/components/oneboxer_spec.rb@@ -72,7 +72,7 @@ describe Oneboxer doonebox = preview(public_reply.url, user, public_category)expect(onebox).to include(public_reply.excerpt)expect(onebox).to include(%{data-post="2"})- expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny"))+ expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template_url, "tiny"))short_url = "#{Discourse.base_path}/t/#{public_topic.id}"expect(preview(short_url, user, public_category)).to include(public_topic.title)@@ -80,11 +80,11 @@ describe Oneboxer doonebox = preview(public_moderator_action.url, user, public_category)expect(onebox).to include(public_moderator_action.excerpt)expect(onebox).to include(%{data-post="4"})- expect(onebox).to include(PrettyText.avatar_img(staff.avatar_template, "tiny"))+ expect(onebox).to include(PrettyText.avatar_img(staff.avatar_template_url, "tiny"))onebox = preview(public_reply.url, user, public_category, public_topic)expect(onebox).not_to include(public_topic.title)- expect(onebox).to include(replier.avatar_template.sub("{size}", "40"))+ expect(onebox).to include(replier.avatar_template_url.sub("{size}", "40"))expect(preview(public_hidden.url, user, public_category)).to match_html(link(public_hidden.url))expect(preview(secured_topic.relative_url, user, public_category)).to match_html(link(secured_topic.relative_url))diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rbindex 3b56863f532..c0d935e9c88 100644--- a/spec/services/username_changer_spec.rb+++ b/spec/services/username_changer_spec.rb@@ -323,7 +323,7 @@ describe UsernameChanger docontext 'quotes' dolet(:quoted_post) { create_post(user: user, topic: topic, post_number: 1, raw: "quoted post") }- let(:avatar_url) { user.avatar_template.gsub("{size}", "40") }+ let(:avatar_url) { user.avatar_template_url.gsub("{size}", "40") }it 'replaces the username in quote tags and updates avatar' dopost = create_post_and_change_username(raw: <<~RAW)@@ -448,7 +448,7 @@ describe UsernameChanger doenddef user_avatar_url(u)- u.avatar_template.gsub("{size}", "40")+ u.avatar_template_url.gsub("{size}", "40")endit 'updates avatar for linked topics and posts' do