mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: don't overwrite custom uploaded avatar when selecting gravatar
FIX: remove unecessary serialized fields
This commit is contained in:
parent
569f2815d1
commit
93f9dcfcec
10 changed files with 20 additions and 35 deletions
|
@ -256,10 +256,10 @@ const User = RestModel.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
pickAvatar(upload_id, avatar_template) {
|
pickAvatar(upload_id, type, avatar_template) {
|
||||||
return Discourse.ajax(`/users/${this.get("username_lower")}/preferences/avatar/pick`, {
|
return Discourse.ajax(`/users/${this.get("username_lower")}/preferences/avatar/pick`, {
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: { upload_id }
|
data: { upload_id, type }
|
||||||
}).then(() => this.setProperties({
|
}).then(() => this.setProperties({
|
||||||
avatar_template,
|
avatar_template,
|
||||||
uploaded_avatar_id: upload_id
|
uploaded_avatar_id: upload_id
|
||||||
|
|
|
@ -49,9 +49,12 @@ export default RestrictedUserRoute.extend({
|
||||||
const user = this.modelFor('user'),
|
const user = this.modelFor('user'),
|
||||||
controller = this.controllerFor('avatar-selector'),
|
controller = this.controllerFor('avatar-selector'),
|
||||||
selectedUploadId = controller.get("selectedUploadId"),
|
selectedUploadId = controller.get("selectedUploadId"),
|
||||||
selectedAvatarTemplate = controller.get("selectedAvatarTemplate");
|
selectedAvatarTemplate = controller.get("selectedAvatarTemplate"),
|
||||||
|
type = controller.get("selected");
|
||||||
|
|
||||||
user.pickAvatar(selectedUploadId, selectedAvatarTemplate)
|
if (type === "uploaded") { type = "custom" }
|
||||||
|
|
||||||
|
user.pickAvatar(selectedUploadId, type, selectedAvatarTemplate)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
user.setProperties(controller.getProperties(
|
user.setProperties(controller.getProperties(
|
||||||
'system_avatar_template',
|
'system_avatar_template',
|
||||||
|
|
|
@ -515,13 +515,13 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
results = UserSearch.new(term, topic_id: topic_id, topic_allowed_users: topic_allowed_users, searching_user: current_user).search
|
results = UserSearch.new(term, topic_id: topic_id, topic_allowed_users: topic_allowed_users, searching_user: current_user).search
|
||||||
|
|
||||||
user_fields = [:username, :upload_avatar_template, :uploaded_avatar_id]
|
user_fields = [:username, :upload_avatar_template]
|
||||||
user_fields << :name if SiteSetting.enable_names?
|
user_fields << :name if SiteSetting.enable_names?
|
||||||
|
|
||||||
to_render = { users: results.as_json(only: user_fields, methods: [:avatar_template]) }
|
to_render = { users: results.as_json(only: user_fields, methods: [:avatar_template]) }
|
||||||
|
|
||||||
if params[:include_groups] == "true"
|
if params[:include_groups] == "true"
|
||||||
to_render[:groups] = Group.search_group(term, current_user).map {|m| {:name=>m.name, :usernames=> m.usernames.split(",")} }
|
to_render[:groups] = Group.search_group(term, current_user).map { |m| { name: m.name, usernames: m.usernames.split(",") } }
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: to_render
|
render json: to_render
|
||||||
|
@ -533,12 +533,11 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
upload_id = params[:upload_id]
|
upload_id = params[:upload_id]
|
||||||
|
|
||||||
user.uploaded_avatar_id = upload_id
|
type = params[:type]
|
||||||
|
type = "custom" if type == "uploaded"
|
||||||
|
|
||||||
# ensure we associate the custom avatar properly
|
user.uploaded_avatar_id = upload_id
|
||||||
if upload_id && user.user_avatar.custom_upload_id != upload_id
|
user.user_avatar.send("#{type}_upload_id=", upload_id)
|
||||||
user.user_avatar.custom_upload_id = upload_id
|
|
||||||
end
|
|
||||||
|
|
||||||
user.save!
|
user.save!
|
||||||
user.user_avatar.save!
|
user.user_avatar.save!
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Upload < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# list of image types that will be cropped
|
# list of image types that will be cropped
|
||||||
CROPPED_IMAGE_TYPES ||= ["avatar", "profile_background", "card_background"]
|
CROPPED_IMAGE_TYPES ||= %w{avatar profile_background card_background}
|
||||||
|
|
||||||
# options
|
# options
|
||||||
# - content_type
|
# - content_type
|
||||||
|
|
|
@ -462,8 +462,8 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.avatar_template(username, uploaded_avatar_id)
|
def self.avatar_template(username, uploaded_avatar_id)
|
||||||
return default_template(username) if !uploaded_avatar_id
|
|
||||||
username ||= ""
|
username ||= ""
|
||||||
|
return default_template(username) if !uploaded_avatar_id
|
||||||
hostname = RailsMultisite::ConnectionManagement.current_hostname
|
hostname = RailsMultisite::ConnectionManagement.current_hostname
|
||||||
UserAvatar.local_avatar_template(hostname, username.downcase, uploaded_avatar_id)
|
UserAvatar.local_avatar_template(hostname, username.downcase, uploaded_avatar_id)
|
||||||
end
|
end
|
||||||
|
@ -482,7 +482,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.letter_avatar_color(username)
|
def self.letter_avatar_color(username)
|
||||||
username = username || ""
|
username ||= ""
|
||||||
color = LetterAvatar::COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length]
|
color = LetterAvatar::COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length]
|
||||||
color.map { |c| c.to_s(16).rjust(2, '0') }.join
|
color.map { |c| c.to_s(16).rjust(2, '0') }.join
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,8 +39,7 @@ class UserAvatar < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.local_avatar_url(hostname, username, upload_id, size)
|
def self.local_avatar_url(hostname, username, upload_id, size)
|
||||||
version = self.version(upload_id)
|
self.local_avatar_template(hostname, username, upload_id).gsub("{size}", size)
|
||||||
"#{Discourse.base_uri}/user_avatar/#{hostname}/#{username}/#{size}/#{version}.png"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.local_avatar_template(hostname, username, upload_id)
|
def self.local_avatar_template(hostname, username, upload_id)
|
||||||
|
@ -49,8 +48,7 @@ class UserAvatar < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.external_avatar_url(user_id, upload_id, size)
|
def self.external_avatar_url(user_id, upload_id, size)
|
||||||
version = self.version(upload_id)
|
self.external_avatar_template(user_id, upload_id).gsub("{size}", size)
|
||||||
"#{Discourse.store.absolute_base_url}/avatars/#{user_id}/#{size}/#{version}.png"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.external_avatar_template(user_id, upload_id)
|
def self.external_avatar_template(user_id, upload_id)
|
||||||
|
|
|
@ -3,7 +3,7 @@ class AdminPostSerializer < ApplicationSerializer
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:created_at,
|
:created_at,
|
||||||
:post_number,
|
:post_number,
|
||||||
:name, :username, :avatar_template, :uploaded_avatar_id,
|
:name, :username, :avatar_template,
|
||||||
:topic_id, :topic_slug, :topic_title,
|
:topic_id, :topic_slug, :topic_title,
|
||||||
:category_id,
|
:category_id,
|
||||||
:excerpt,
|
:excerpt,
|
||||||
|
@ -29,10 +29,6 @@ class AdminPostSerializer < ApplicationSerializer
|
||||||
object.user.avatar_template
|
object.user.avatar_template
|
||||||
end
|
end
|
||||||
|
|
||||||
def uploaded_avatar_id
|
|
||||||
object.user.uploaded_avatar_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def topic_slug
|
def topic_slug
|
||||||
topic.slug
|
topic.slug
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,10 +9,6 @@ class PostActionUserSerializer < BasicUserSerializer
|
||||||
object.user.username
|
object.user.username
|
||||||
end
|
end
|
||||||
|
|
||||||
def uploaded_avatar_id
|
|
||||||
object.user.uploaded_avatar_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def avatar_template
|
def avatar_template
|
||||||
object.user.avatar_template
|
object.user.avatar_template
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,4 @@ class TopicPostCountSerializer < BasicUserSerializer
|
||||||
object[:post_count]
|
object[:post_count]
|
||||||
end
|
end
|
||||||
|
|
||||||
def uploaded_avatar_id
|
|
||||||
object[:user].uploaded_avatar_id
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,10 +12,7 @@ class AvatarLookup
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.lookup_columns
|
def self.lookup_columns
|
||||||
@lookup_columns ||= [:id,
|
@lookup_columns ||= %i{id email username uploaded_avatar_id}
|
||||||
:email,
|
|
||||||
:username,
|
|
||||||
:uploaded_avatar_id]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def users
|
def users
|
||||||
|
|
Loading…
Reference in a new issue