Skip to content

Commit

Permalink
FEATURE: Use the site's small logo as the system user's avatar. (#11661)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanrizzi committed Jan 8, 2021
1 parent e63a9fa commit caa1738
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/user.rb
Expand Up @@ -868,7 +868,11 @@ def self.color_index(username, length)
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.
Expand Down
23 changes: 23 additions & 0 deletions spec/models/user_spec.rb
Expand Up @@ -1337,6 +1337,29 @@ def test_user?(opts = {})

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) }
Expand Down

1 comment on commit caa1738

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/i-am-not-able-to-change-avatar-of-system-user/175552/2

Please sign in to comment.