From caa17386eed26c6434b6a2e00953cc19db3a3e44 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Fri, 8 Jan 2021 10:40:00 -0300 Subject: [PATCH] FEATURE: Use the site's small logo as the system user's avatar. (#11661) --- app/models/user.rb | 6 +++++- spec/models/user_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6b26110a32b..305b7b549cf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -868,7 +868,11 @@ class User < ActiveRecord::Base end def avatar_template - self.class.avatar_template(username, uploaded_avatar_id) + if id == Discourse::SYSTEM_USER_ID && SiteSetting.logo_small + UrlHelper.absolute(SiteSetting.logo_small.url) + else + self.class.avatar_template(username, uploaded_avatar_id) + end end # The following count methods are somewhat slow - definitely don't use them in a loop. diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3a7a609765f..33bd7b57737 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1337,6 +1337,29 @@ describe User do end + describe '#avatar_template' do + it 'uses the small logo if the user is the system user' do + logo_small_url = UrlHelper.absolute(SiteSetting.logo_small.url) + + expect(Discourse.system_user.avatar_template).to eq(logo_small_url) + end + + it 'uses the system user avatar if the logo is nil' do + SiteSetting.logo_small = nil + system_user = Discourse.system_user + expected = User.avatar_template(system_user.username, system_user.uploaded_avatar_id) + + expect(Discourse.system_user.avatar_template).to eq(expected) + end + + it 'uses the regular avatar for other users' do + user = Fabricate(:user) + expected = User.avatar_template(user.username, user.uploaded_avatar_id) + + expect(user.avatar_template).to eq(expected) + end + end + describe "update_posts_read!" do context "with a UserVisit record" do let!(:user) { Fabricate(:user) }