A platform for community discussion. Free, open, simple.
DEV: Deprecate external_system_avatars_enabled (#33436)
Ted Johansson4c7089f817c3
diff --git a/app/models/user.rb b/app/models/user.rbindex b6bf954ed2f..3717f84e645 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -1192,7 +1192,7 @@ class User < ActiveRecord::Basenormalized_username = normalize_username(username)# TODO it may be worth caching this in a distributed cache, should be benched- if SiteSetting.external_system_avatars_enabled+ if SiteSetting.external_system_avatars_url.present?url = SiteSetting.external_system_avatars_url.dupurl = +"#{Discourse.base_path}#{url}" unless url =~ %r{\Ahttps?://}url.gsub! "{color}", letter_avatar_color(normalized_username)diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 1a6ec2ec58c..c7dc4559e85 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2096,7 +2096,7 @@ en:avatar_sizes: "List of automatically generated avatar sizes."external_system_avatars_enabled: "Enables the use of an external service for generating system avatars. When this setting is enabled, user avatars, instead of being produced within the Discourse system, are generated and provided by an external service defined by the `external_system_avatars_url` setting."- external_system_avatars_url: "URL of the external system avatars service. Allowed substitutions are {username} {first_letter} {color} {size}"+ external_system_avatars_url: "URL of the external system avatars service. Allowed substitutions are {username} {first_letter} {color} {size}. Leave blank to disable."external_emoji_url: "URL of the external service for emoji images. Leave blank to disable."use_site_small_logo_as_system_avatar: "Use the site's small logo instead of the system user's avatar. Requires the logo to be present."restrict_letter_avatar_colors: "A list of 6-digit hexadecimal color values to be used for letter avatar background."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 9dea3d1fdc3..46866cc71a8 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -2142,6 +2142,7 @@ files:external_system_avatars_enabled:default: trueclient: true+ hidden: truevalidator: "ExternalSystemAvatarsValidator"external_system_avatars_url:default: "/letter_avatar_proxy/v4/letter/{first_letter}/{color}/{size}.png"diff --git a/db/post_migrate/20250702082232_deprecate_external_system_avatars_enabled.rb b/db/post_migrate/20250702082232_deprecate_external_system_avatars_enabled.rbnew file mode 100644index 00000000000..531dc18a581--- /dev/null+++ b/db/post_migrate/20250702082232_deprecate_external_system_avatars_enabled.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true+class DeprecateExternalSystemAvatarsEnabled < ActiveRecord::Migration[7.2]+ def up+ execute <<~SQL+ INSERT INTO site_settings(name, data_type, value, created_at, updated_at)+ SELECT 'external_system_avatars_url', 1, '', 'NOW()', 'NOW()'+ WHERE EXISTS (+ SELECT 1+ FROM site_settings+ WHERE name = 'external_system_avatars_enabled'+ AND value = 'f'+ )+ ON CONFLICT(name) DO UPDATE+ SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at;+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/lib/site_settings/deprecated_settings.rb b/lib/site_settings/deprecated_settings.rbindex ca9ea175e78..1ad5b6bc0e6 100644--- a/lib/site_settings/deprecated_settings.rb+++ b/lib/site_settings/deprecated_settings.rb@@ -47,6 +47,7 @@ module SiteSettings::DeprecatedSettings],["min_first_post_typing_time", "fast_typing_threshold", false, "3.4"],["twitter_summary_large_image", "x_summary_large_image", false, "3.4"],+ ["external_system_avatars_enabled", "external_system_avatars_url", false, "3.5"],]OVERRIDE_TL_GROUP_SETTINGS = %w[diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rakeindex b72ae0cb2b2..5c8df012813 100644--- a/lib/tasks/posts.rake+++ b/lib/tasks/posts.rake@@ -57,7 +57,7 @@ enddesc "Rebake all posts with a quote using a letter_avatar"task "posts:fix_letter_avatars" => :environment do- next unless SiteSetting.external_system_avatars_enabled+ next if SiteSetting.external_system_avatars_url.blank?search =Post.where("user_id <> -1").where(diff --git a/lib/validators/unicode_username_validator.rb b/lib/validators/unicode_username_validator.rbindex a2d26b791eb..53692714106 100644--- a/lib/validators/unicode_username_validator.rb+++ b/lib/validators/unicode_username_validator.rb@@ -6,7 +6,7 @@ class UnicodeUsernameValidatorenddef valid_value?(value)- @valid = SiteSetting.external_system_avatars_enabled || value == "f"+ @valid = SiteSetting.external_system_avatars_url.present? || value == "f"enddef error_messagediff --git a/plugins/chat/spec/integration/post_chat_transcript_spec.rb b/plugins/chat/spec/integration/post_chat_transcript_spec.rbindex 7dc63f5b2f1..afc3719bd2d 100644--- a/plugins/chat/spec/integration/post_chat_transcript_spec.rb+++ b/plugins/chat/spec/integration/post_chat_transcript_spec.rb@@ -194,7 +194,7 @@ martin</div>endit "handles nested chat transcripts in posts" do- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""freeze_timechannel = Fabricate(:chat_channel)diff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rbindex 319e7c5972d..d8c0905ec99 100644--- a/plugins/chat/spec/models/chat/message_spec.rb+++ b/plugins/chat/spec/models/chat/message_spec.rb@@ -358,7 +358,7 @@ describe Chat::Message doit "supports quote bbcode" dotopic = Fabricate(:topic, title: "Some quotable topic")post = Fabricate(:post, topic: topic)- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""avatar_src ="//test.localhost#{User.system_avatar_template(post.user.username).gsub("{size}", "48")}"diff --git a/spec/lib/validators/unicode_username_validator_spec.rb b/spec/lib/validators/unicode_username_validator_spec.rbindex 649fca8632e..fbf8eb111e0 100644--- a/spec/lib/validators/unicode_username_validator_spec.rb+++ b/spec/lib/validators/unicode_username_validator_spec.rb@@ -4,7 +4,7 @@ RSpec.describe UnicodeUsernameValidator dosubject(:validator) { described_class.new }it "disallows Unicode usernames when external system avatars are disabled" do- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""expect(validator.valid_value?("t")).to eq(false)expect(validator.error_message).to eq(I18n.t("site_settings.errors.unicode_usernames_avatars"))@@ -14,7 +14,8 @@ RSpec.describe UnicodeUsernameValidator doendit "allows Unicode usernames when external system avatars are enabled" do- SiteSetting.external_system_avatars_enabled = true+ SiteSetting.external_system_avatars_url =+ "/letter_avatar_proxy/v4/letter/{first_letter}/{color}/{size}.png"expect(validator.valid_value?("t")).to eq(true)expect(validator.error_message).to be_blankdiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 16172dea344..4d9bb03b230 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -1662,12 +1662,13 @@ RSpec.describe User dolet(:user) { build(:user, username: "Sam") }it "returns a 45-pixel-wide avatar" do- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""expect(user.small_avatar_url).to eq("//test.localhost/letter_avatar/sam/45/#{LetterAvatar.version}.png",)- SiteSetting.external_system_avatars_enabled = true+ SiteSetting.external_system_avatars_url =+ "/letter_avatar_proxy/v4/letter/{first_letter}/{color}/{size}.png"expect(user.small_avatar_url).to eq("//test.localhost/letter_avatar_proxy/v4/letter/s/5f9b8f/45.png",)@@ -1769,7 +1770,7 @@ RSpec.describe User dodescribe "automatic avatar creation" doit "sets a system avatar for new users" do- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""u = User.create!(username: "bob", email: "[email protected]")u.reload@@ -2974,7 +2975,10 @@ RSpec.describe User dodescribe ".system_avatar_template" docontext "with external system avatars enabled" do- before { SiteSetting.external_system_avatars_enabled = true }+ before do+ SiteSetting.external_system_avatars_url =+ "/letter_avatar_proxy/v4/letter/{first_letter}/{color}/{size}.png"+ endit "uses the normalized username" doexpect(User.system_avatar_template("Lo\u0308we")).to match(diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 716f869ac67..9245d162fdc 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -44,7 +44,7 @@ RSpec.describe TopicsController dofab!(:p2) { Fabricate(:post, topic: p1.topic, user: moderator) }it "returns the JSON in the format our wordpress plugin needs" do- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""get "/t/#{p1.topic.id}/wordpress.json", params: { best: 3 }diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rbindex ed3229826e1..e0d84e396f8 100644--- a/spec/support/system_helpers.rb+++ b/spec/support/system_helpers.rb@@ -65,7 +65,7 @@ module SystemHelpersSiteSetting.has_login_hint = falseSiteSetting.force_hostname = Capybara.server_hostSiteSetting.port = Capybara.server_port- SiteSetting.external_system_avatars_enabled = false+ SiteSetting.external_system_avatars_url = ""SiteSetting.enable_user_tips = falseSiteSetting.splash_screen = falseSiteSetting.allowed_internal_hosts =