mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FIX: default_avatars
wasn't being used for some server side templates
This commit is contained in:
parent
9408d5891d
commit
b52e5d1536
@ -4,21 +4,13 @@ var safe = Handlebars.SafeString;
|
||||
var registerUnbound = require('discourse/helpers/register-unbound', null, null, true).default;
|
||||
var avatarTemplate = require('discourse/lib/avatar-template', null, null, true).default;
|
||||
|
||||
/**
|
||||
Bound avatar helper.
|
||||
|
||||
@method bound-avatar
|
||||
@for Handlebars
|
||||
**/
|
||||
Em.Handlebars.helper('bound-avatar', function(user, size, uploadId) {
|
||||
if (Em.isEmpty(user)) {
|
||||
return new safe("<div class='avatar-placeholder'></div>");
|
||||
}
|
||||
|
||||
var username = Em.get(user, 'username');
|
||||
|
||||
if (arguments.length < 4) { uploadId = Em.get(user, 'uploaded_avatar_id'); }
|
||||
|
||||
var avatar = Em.get(user, 'avatar_template') || avatarTemplate(username, uploadId);
|
||||
|
||||
return new safe(Discourse.Utilities.avatarImg({ size: size, avatarTemplate: avatar }));
|
||||
|
@ -429,8 +429,23 @@ class User < ActiveRecord::Base
|
||||
UrlHelper.schemaless UrlHelper.absolute avatar_template
|
||||
end
|
||||
|
||||
def self.default_template(username)
|
||||
if SiteSetting.default_avatars.present?
|
||||
split_avatars = SiteSetting.default_avatars.split("\n")
|
||||
if split_avatars.present?
|
||||
hash = username.each_char.reduce(0) do |result, char|
|
||||
[((result << 5) - result) + char.ord].pack('L').unpack('l').first
|
||||
end
|
||||
|
||||
avatar_template = split_avatars[hash.abs % split_avatars.size]
|
||||
end
|
||||
else
|
||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||
end
|
||||
end
|
||||
|
||||
def self.avatar_template(username,uploaded_avatar_id)
|
||||
return letter_avatar_template(username) if !uploaded_avatar_id
|
||||
return default_template(username) if !uploaded_avatar_id
|
||||
username ||= ""
|
||||
hostname = RailsMultisite::ConnectionManagement.current_hostname
|
||||
UserAvatar.local_avatar_template(hostname, username.downcase, uploaded_avatar_id)
|
||||
|
@ -25,15 +25,8 @@ module PrettyText
|
||||
return "" unless user.present?
|
||||
|
||||
# TODO: Add support for ES6 and call `avatar-template` directly
|
||||
if !user.uploaded_avatar_id && SiteSetting.default_avatars.present?
|
||||
split_avatars = SiteSetting.default_avatars.split("\n")
|
||||
if split_avatars.present?
|
||||
hash = username.each_char.reduce(0) do |result, char|
|
||||
[((result << 5) - result) + char.ord].pack('L').unpack('l').first
|
||||
end
|
||||
|
||||
avatar_template = split_avatars[hash.abs % split_avatars.size]
|
||||
end
|
||||
if !user.uploaded_avatar_id
|
||||
avatar_template = User.default_template(username)
|
||||
else
|
||||
avatar_template = user.avatar_template
|
||||
end
|
||||
|
@ -9,10 +9,11 @@ describe PrettyText do
|
||||
describe "Cooking" do
|
||||
|
||||
describe "with avatar" do
|
||||
let(:default_avatar) { "//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png" }
|
||||
|
||||
before(:each) do
|
||||
eviltrout = User.new
|
||||
eviltrout.stubs(:avatar_template).returns("//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png")
|
||||
User.stubs(:default_template).returns(default_avatar)
|
||||
User.expects(:find_by).with(username_lower: "eviltrout").returns(eviltrout)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user