mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 22:48:12 +08:00
Revert "Revert "Extract logic to save external avatar url""
This reverts commit 2d20e4c6923cef4b7a6eed717cd3db3fe75756a7.
This commit is contained in:
parent
2d20e4c692
commit
cb94a9000d
@ -127,28 +127,7 @@ class DiscourseSingleSignOn < SingleSignOn
|
|||||||
avatar_force_update ||
|
avatar_force_update ||
|
||||||
sso_record.external_avatar_url != avatar_url)
|
sso_record.external_avatar_url != avatar_url)
|
||||||
|
|
||||||
begin
|
UserAvatar.import_url_for_user(avatar_url, user)
|
||||||
tempfile = FileHelper.download(avatar_url, SiteSetting.max_image_size_kb.kilobytes, "sso-avatar", true)
|
|
||||||
|
|
||||||
ext = FastImage.type(tempfile).to_s
|
|
||||||
tempfile.rewind
|
|
||||||
|
|
||||||
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, tempfile.size, { origin: avatar_url })
|
|
||||||
user.uploaded_avatar_id = upload.id
|
|
||||||
|
|
||||||
unless user.user_avatar
|
|
||||||
user.build_user_avatar
|
|
||||||
end
|
|
||||||
|
|
||||||
if !user.user_avatar.contains_upload?(upload.id)
|
|
||||||
user.user_avatar.custom_upload_id = upload.id
|
|
||||||
end
|
|
||||||
rescue => e
|
|
||||||
# skip saving, we are not connected to the net
|
|
||||||
Rails.logger.warn "#{e}: Failed to download external avatar: #{avatar_url}, user id #{ user.id }"
|
|
||||||
ensure
|
|
||||||
tempfile.close! if tempfile && tempfile.respond_to?(:close!)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# change external attributes for sso record
|
# change external attributes for sso record
|
||||||
|
@ -62,6 +62,29 @@ class UserAvatar < ActiveRecord::Base
|
|||||||
"#{upload_id}_#{OptimizedImage::VERSION}"
|
"#{upload_id}_#{OptimizedImage::VERSION}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.import_url_for_user(avatar_url, user)
|
||||||
|
tempfile = FileHelper.download(avatar_url, SiteSetting.max_image_size_kb.kilobytes, "sso-avatar", true)
|
||||||
|
|
||||||
|
ext = FastImage.type(tempfile).to_s
|
||||||
|
tempfile.rewind
|
||||||
|
|
||||||
|
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, tempfile.size, { origin: avatar_url })
|
||||||
|
user.uploaded_avatar_id = upload.id
|
||||||
|
|
||||||
|
unless user.user_avatar
|
||||||
|
user.build_user_avatar
|
||||||
|
end
|
||||||
|
|
||||||
|
if !user.user_avatar.contains_upload?(upload.id)
|
||||||
|
user.user_avatar.custom_upload_id = upload.id
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
# skip saving, we are not connected to the net
|
||||||
|
Rails.logger.warn "#{e}: Failed to download external avatar: #{avatar_url}, user id #{ user.id }"
|
||||||
|
ensure
|
||||||
|
tempfile.close! if tempfile && tempfile.respond_to?(:close!)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
Loading…
x
Reference in New Issue
Block a user